docs: Update changelog #5
Workflow file for this run
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: Changelog CI | |
| on: | |
| pull_request: | |
| types: | |
| - closed | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| actions: read | |
| jobs: | |
| update_changelog: | |
| name: Update Changelog | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Sparse checkout exclusion script | |
| uses: actions/checkout@v4 | |
| with: | |
| sparse-checkout: | | |
| .github/scripts/check-changelog-exclusions.mjs | |
| .github/scripts/update-changelog.mjs | |
| sparse-checkout-cone-mode: false | |
| - name: Check if PR should be excluded | |
| id: check-exclusions | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { default: checkExclusions } = await import('${{ github.workspace }}/.github/scripts/check-changelog-exclusions.mjs'); | |
| return await checkExclusions({ | |
| pr: context.payload.pull_request, | |
| core | |
| }); | |
| - name: Changelog update skipped | |
| if: steps.check-exclusions.outputs.should-skip == 'true' | |
| run: | | |
| echo "ℹ️ Changelog update skipped: ${{ steps.check-exclusions.outputs.skip-reason }}" | |
| - name: Checkout repository | |
| if: steps.check-exclusions.outputs.should-skip == 'false' | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Disable sparse checkout | |
| if: steps.check-exclusions.outputs.should-skip == 'false' | |
| run: | | |
| git sparse-checkout disable | |
| - name: Check for existing changelog PR | |
| if: steps.check-exclusions.outputs.should-skip == 'false' | |
| id: check-existing-changelog-pr | |
| run: | | |
| BASE_BRANCH="${{ github.event.pull_request.base.ref }}" | |
| # Find existing changelog PR | |
| CHANGELOG_PR=$(gh pr list --base "$BASE_BRANCH" --state open --json number,title,headRefName,body --jq '.[] | select(.title | test("^docs: Update changelog"; "i"))') | |
| if [ -n "$CHANGELOG_PR" ]; then | |
| PR_NUMBER=$(echo "$CHANGELOG_PR" | jq -r '.number') | |
| PR_BRANCH_NAME=$(echo "$CHANGELOG_PR" | jq -r '.headRefName') | |
| PR_BODY=$(echo "$CHANGELOG_PR" | jq -r '.body') | |
| echo "📝 Found existing changelog PR #$PR_NUMBER" | |
| echo "changelog-pr-exists=true" >> $GITHUB_OUTPUT | |
| echo "changelog-pr-branch-name=$PR_BRANCH_NAME" >> $GITHUB_OUTPUT | |
| echo "changelog-pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT | |
| echo "changelog-pr-body<<EOF" >> "$GITHUB_OUTPUT" | |
| echo "$PR_BODY" >> "$GITHUB_OUTPUT" | |
| echo "EOF" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "✨ No existing changelog PR found" | |
| echo "changelog-pr-exists=false" >> $GITHUB_OUTPUT | |
| echo "changelog-pr-branch-name=docs/update-changelog" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Configure Git | |
| if: steps.check-exclusions.outputs.should-skip == 'false' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Copy changelog script | |
| if: steps.check-exclusions.outputs.should-skip == 'false' | |
| run: cp "${{ github.workspace }}/.github/scripts/update-changelog.mjs" /tmp/update-changelog.mjs | |
| - name: Checkout changelog branch | |
| if: steps.check-exclusions.outputs.should-skip == 'false' | |
| run: | | |
| BRANCH_NAME="${{ steps.check-existing-changelog-pr.outputs.changelog-pr-branch-name }}" | |
| if [ "${{ steps.check-existing-changelog-pr.outputs.changelog-pr-exists }}" = "true" ]; then | |
| echo "🔄 Checking out existing branch: $BRANCH_NAME" | |
| git fetch origin $BRANCH_NAME | |
| git checkout $BRANCH_NAME | |
| git pull origin $BRANCH_NAME | |
| else | |
| echo "✨ Creating new branch: $BRANCH_NAME" | |
| git checkout -b $BRANCH_NAME | |
| fi | |
| - name: Update Changelog | |
| if: steps.check-exclusions.outputs.should-skip == 'false' | |
| id: update-changelog | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { default: updateChangelog } = await import('/tmp/update-changelog.mjs'); | |
| return await updateChangelog({ | |
| pr: context.payload.pull_request, | |
| core | |
| }); | |
| - name: Prettify Changelog | |
| id: prettify-changelog | |
| if: steps.check-exclusions.outputs.should-skip == 'false' && steps.update-changelog.outputs.changelog-updated == 'true' | |
| run: | | |
| npx prettier --write CHANGELOG.md | |
| echo "✅ Formatted CHANGELOG.md with Prettier" | |
| - name: Git Diff | |
| id: git-diff | |
| if: steps.check-exclusions.outputs.should-skip == 'false' && steps.update-changelog.outputs.changelog-updated == 'true' | |
| run: | | |
| git diff CHANGELOG.md | |
| - name: Commit and push changes | |
| if: steps.check-exclusions.outputs.should-skip == 'false' && steps.update-changelog.outputs.changelog-updated == 'true' | |
| run: | | |
| BRANCH_NAME="${{ steps.check-existing-changelog-pr.outputs.changelog-pr-branch-name }}" | |
| git add CHANGELOG.md | |
| git commit -m "docs: update changelog for PR #${{ steps.update-changelog.outputs.pr-number }}" | |
| if [ "${{ steps.check-existing-changelog-pr.outputs.changelog-pr-exists }}" = "true" ]; then | |
| git push origin $BRANCH_NAME | |
| else | |
| git push -u origin $BRANCH_NAME | |
| fi | |
| - name: Create or update changelog PR | |
| if: steps.check-exclusions.outputs.should-skip == 'false' && steps.update-changelog.outputs.changelog-updated == 'true' | |
| run: | | |
| BASE_BRANCH="${{ github.event.pull_request.base.ref }}" | |
| BRANCH_NAME="${{ steps.check-existing-changelog-pr.outputs.changelog-pr-branch-name }}" | |
| PR_NUMBER="${{ steps.update-changelog.outputs.pr-number }}" | |
| CHANGELOG_PR_EXISTS="${{ steps.check-existing-changelog-pr.outputs.changelog-pr-exists }}" | |
| if [ "$CHANGELOG_PR_EXISTS" = "true" ]; then | |
| # Update existing PR | |
| EXISTING_PR_NUMBER="${{ steps.check-existing-changelog-pr.outputs.changelog-pr-number }}" | |
| EXISTING_BODY="${{ steps.check-existing-changelog-pr.outputs.changelog-pr-body }}" | |
| UPDATED_BODY="$EXISTING_BODY | |
| - #$PR_NUMBER" | |
| gh pr edit "$EXISTING_PR_NUMBER" --body "$UPDATED_BODY" | |
| echo "✅ Updated changelog PR #$EXISTING_PR_NUMBER" | |
| else | |
| # Create new PR | |
| gh pr create \ | |
| --base "$BASE_BRANCH" \ | |
| --head "$BRANCH_NAME" \ | |
| --title "docs: Update changelog" \ | |
| --body "This PR updates the changelog with merged PRs. | |
| This is an automated PR created by the changelog workflow. | |
| ### Included PRs: | |
| - #$PR_NUMBER" | |
| NEW_PR_NUMBER=$(gh pr view "$BRANCH_NAME" --json number --jq '.number') | |
| echo "✅ Created changelog PR #$NEW_PR_NUMBER" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ github.token }} |