Flatten changelog format: replace category subsections with inline pr… #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Merge Changelog | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - CHANGELOG.md | |
| permissions: | |
| contents: write | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Find merged PR | |
| id: pr | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| COMMIT_SHA: ${{ github.sha }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| # Retry loop for GitHub API eventual consistency. | |
| for attempt in 1 2 3; do | |
| PR_JSON=$(gh api "repos/${REPO}/commits/${COMMIT_SHA}/pulls" \ | |
| --jq '.[0] // empty' 2>/dev/null || echo "") | |
| if [ -n "$PR_JSON" ]; then | |
| break | |
| fi | |
| echo "Attempt ${attempt}: no PR found, retrying in 10s..." | |
| sleep 10 | |
| done | |
| if [ -z "$PR_JSON" ]; then | |
| echo "No PR found for commit — skipping" | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| NUMBER=$(echo "$PR_JSON" | jq -r '.number') | |
| TITLE=$(echo "$PR_JSON" | jq -r '.title') | |
| URL=$(echo "$PR_JSON" | jq -r '.html_url') | |
| HAS_CHANGELOG=$(echo "$PR_JSON" | jq -r \ | |
| '[.labels[].name] | map(select(startswith("changelog - "))) | first // empty') | |
| BREAKING=$(echo "$PR_JSON" | jq -r \ | |
| '[.labels[].name] | map(select(. == "changelog - breaking")) | first // empty') | |
| echo "number=$NUMBER" >> "$GITHUB_OUTPUT" | |
| echo "title=$TITLE" >> "$GITHUB_OUTPUT" | |
| echo "url=$URL" >> "$GITHUB_OUTPUT" | |
| echo "has_changelog=$HAS_CHANGELOG" >> "$GITHUB_OUTPUT" | |
| echo "breaking=$BREAKING" >> "$GITHUB_OUTPUT" | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| - name: Check out main | |
| if: steps.pr.outputs.skip != 'true' && steps.pr.outputs.has_changelog != '' | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| if: steps.pr.outputs.skip != 'true' && steps.pr.outputs.has_changelog != '' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.x" | |
| - name: Add changelog entry | |
| if: steps.pr.outputs.has_changelog != '' | |
| env: | |
| TITLE: ${{ steps.pr.outputs.title }} | |
| NUMBER: ${{ steps.pr.outputs.number }} | |
| URL: ${{ steps.pr.outputs.url }} | |
| BREAKING: ${{ steps.pr.outputs.breaking }} | |
| run: | | |
| ENTRY="${TITLE} ([PR #${NUMBER}](${URL}))" | |
| ARGS="" | |
| if [ -n "$BREAKING" ]; then | |
| ARGS="--breaking" | |
| fi | |
| python3 .ci-scripts/changelog.py add-entry $ARGS "$ENTRY" | |
| - name: Commit and push | |
| if: steps.pr.outputs.skip != 'true' && steps.pr.outputs.has_changelog != '' | |
| env: | |
| NUMBER: ${{ steps.pr.outputs.number }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add CHANGELOG.md | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "Update changelog for PR #${NUMBER}" | |
| git pull --rebase origin main | |
| git push origin main |