build: update pr changelog workflow

This commit is contained in:
2026-04-12 22:38:22 +03:00
parent 32326beb8d
commit c72a655f6a
2 changed files with 55 additions and 93 deletions

View File

@@ -1,93 +0,0 @@
name: Update Fastlane Changelog
# Runs when the release-please branch is pushed (either by the release-please
# action creating/updating the PR, or by manual pushes to the branch).
on:
push:
branches:
- 'release-please--**'
permissions:
contents: write
jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract version from pubspec.yaml
id: version
run: |
VERSION_LINE=$(grep '^version:' pubspec.yaml)
VERSION_NAME=$(echo "$VERSION_LINE" | sed 's/version: *//;s/+.*//')
VERSION_CODE=$(echo "$VERSION_LINE" | sed 's/.*+//')
echo "name=$VERSION_NAME" >> "$GITHUB_OUTPUT"
echo "code=$VERSION_CODE" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION_NAME+$VERSION_CODE"
- name: Generate fastlane changelog
run: |
VERSION="${{ steps.version.outputs.name }}"
CODE="${{ steps.version.outputs.code }}"
CHANGELOG="CHANGELOG.md"
OUT_DIR="fastlane/metadata/android/en-US/changelogs"
OUT_FILE="$OUT_DIR/$CODE.txt"
mkdir -p "$OUT_DIR"
if [ ! -f "$CHANGELOG" ]; then
echo "Release $VERSION" > "$OUT_FILE"
echo "No CHANGELOG.md, wrote fallback."
exit 0
fi
# Extract the section for this version
NOTES=$(awk "
/^## \\[${VERSION//./\\.}\\]/ { found=1; next }
/^## / { if (found) exit }
found { print }
" "$CHANGELOG")
# Strip commit links, reformat bullets, strip markdown headers
NOTES=$(echo "$NOTES" \
| sed -E 's/ *\(\[[0-9a-f]+\]\([^)]+\)\)//g' \
| sed -E 's/^\* \*\*[^*]+:\*\* */- /; s/^\* /- /' \
| sed 's/^### //' \
| sed '/^[[:space:]]*$/d')
# Trim leading/trailing blank lines
NOTES=$(echo "$NOTES" | sed -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba;}')
if [ -z "$NOTES" ]; then
NOTES="Release $VERSION"
fi
# Truncate to 500 chars (Play Store limit)
MAX=500
TRAILER=$'\n\n… see full notes on GitHub.'
if [ ${#NOTES} -gt $MAX ]; then
BUDGET=$((MAX - ${#TRAILER}))
NOTES="${NOTES:0:$BUDGET}"
# Cut at last newline
NOTES=$(echo "$NOTES" | sed '$d')
NOTES="${NOTES}${TRAILER}"
fi
echo "$NOTES" > "$OUT_FILE"
echo "Wrote $OUT_FILE ($(wc -c < "$OUT_FILE") bytes)"
cat "$OUT_FILE"
- name: Commit and push if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add fastlane/metadata/android/en-US/changelogs/
if git diff --cached --quiet; then
echo "No changes to commit."
else
git commit -m "chore: update fastlane changelog for ${{ steps.version.outputs.name }}"
git push
fi

View File

@@ -96,6 +96,61 @@ jobs:
with:
release-type: dart
- name: Update fastlane changelog on release PR
if: ${{ steps.release.outputs.pr && !steps.release.outputs.release_created }}
env:
PR_JSON: ${{ steps.release.outputs.pr }}
run: |
PR_BRANCH=$(echo "$PR_JSON" | jq -r .headBranchName)
git clone --depth=5 --branch "$PR_BRANCH" \
https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git _pr
cd _pr
VERSION_LINE=$(grep '^version:' pubspec.yaml)
VERSION=$(echo "$VERSION_LINE" | sed 's/version: *//;s/+.*//')
CODE=$(echo "$VERSION_LINE" | sed 's/.*+//')
OUT_DIR="fastlane/metadata/android/en-US/changelogs"
OUT_FILE="$OUT_DIR/$CODE.txt"
mkdir -p "$OUT_DIR"
NOTES=$(awk "
/^## \\[${VERSION//./\\.}\\]/ { found=1; next }
/^## / { if (found) exit }
found { print }
" CHANGELOG.md)
NOTES=$(echo "$NOTES" \
| sed -E 's/ *\(\[[0-9a-f]+\]\([^)]+\)\)//g' \
| sed -E 's/^\* \*\*[^*]+:\*\* */- /; s/^\* /- /' \
| sed 's/^### //' \
| sed '/^[[:space:]]*$/d')
NOTES=$(echo "$NOTES" | sed -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba;}')
[ -z "$NOTES" ] && NOTES="Release $VERSION"
MAX=500
TRAILER=$'\n\n… see full notes on GitHub.'
if [ ${#NOTES} -gt $MAX ]; then
BUDGET=$((MAX - ${#TRAILER}))
NOTES="${NOTES:0:$BUDGET}"
NOTES=$(echo "$NOTES" | sed '$d')
NOTES="${NOTES}${TRAILER}"
fi
echo "$NOTES" > "$OUT_FILE"
echo "Wrote $OUT_FILE ($(wc -c < "$OUT_FILE") bytes)"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$OUT_DIR/"
if git diff --cached --quiet; then
echo "No changelog changes."
else
git commit -m "chore: update fastlane changelog for $VERSION"
git push
fi
build-android:
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}