-
Notifications
You must be signed in to change notification settings - Fork 1
split create tag and update changelog workflows to fix race condition #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: Update Changelog | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| update-changelog: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Update CHANGELOG.md from releases | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| # Generate changelog header (no indentation to avoid leading spaces) | ||
| printf '%s\n' \ | ||
| "# Changelog" \ | ||
| "" \ | ||
| "All notable changes to this project will be documented in this file." \ | ||
| "The format is based on [Keep a Changelog](https://keepachangelog.com/)." \ | ||
| "" \ | ||
| "For releases prior to automated changelog generation, please see the" \ | ||
| "[GitHub Releases](https://github.com/${{ github.repository }}/releases) page." \ | ||
| "" > CHANGELOG.md | ||
|
|
||
| # Append all releases using JSON for reliable parsing (paginate to include all) | ||
| gh api --paginate repos/${{ github.repository }}/releases?per_page=100 \ | ||
| | jq -s -r 'add | map({tagName: .tag_name, publishedAt: .published_at}) | .[] | "\(.tagName) \(.publishedAt)"' \ | ||
| | while read -r tag published_at; do | ||
| formatted_date=$(date -d "$published_at" +%Y-%m-%d 2>/dev/null || echo "$published_at") | ||
| echo "## [$tag] - $formatted_date" | ||
| echo "" | ||
| # Transform top-level headings (## ) to subheadings (### ) for changelog nesting. | ||
| # Uses negative lookahead pattern to avoid double-transforming already-nested headings. | ||
| gh release view "$tag" --json body -q '.body' | sed 's/^##\([^#]\)/###\1/' | ||
| echo "" | ||
| done >> CHANGELOG.md | ||
|
|
||
| - name: Create PR for CHANGELOG.md update | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| git config user.name "github-actions" | ||
| git config user.email "github-actions@github.com" | ||
| git add CHANGELOG.md | ||
| if git diff --staged --quiet; then | ||
| echo "No changelog changes to commit" | ||
| exit 0 | ||
| fi | ||
|
|
||
| BRANCH_NAME="chore/update-changelog-${{ github.event.release.tag_name }}" | ||
| git checkout -B "$BRANCH_NAME" | ||
| git commit -m "chore: update changelog for ${{ github.event.release.tag_name }}" | ||
| git push --force-with-lease origin "$BRANCH_NAME" | ||
|
|
||
| # Create PR only if one doesn't already exist for this branch | ||
| if gh pr view "$BRANCH_NAME" --json state -q '.state' 2>/dev/null | grep -q "OPEN"; then | ||
| echo "PR already exists for $BRANCH_NAME; skipping creation." | ||
| else | ||
| gh pr create \ | ||
| --title "chore: update changelog for ${{ github.event.release.tag_name }}" \ | ||
| --body "Automated changelog update for release ${{ github.event.release.tag_name }}" \ | ||
| --base main \ | ||
| --head "$BRANCH_NAME" | ||
| fi | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
GitHub REST API List releases GET /repos/{owner}/{repo}/releases draft prerelease fields💡 Result:
GET /repos/{owner}/{repo}/releasesreturns an array of release objects, and each release object includes these boolean fields:draft:trueif the release is a draft (unpublished), elsefalse. [1]prerelease:trueif the release is marked as a prerelease, elsefalse. [1]Visibility note: only users with push access will have draft releases included in the list response; others only see published releases. [2]
Sources:
[1] GitHub REST API “List releases” example response schema (shows
draftandprerelease). (docs.github.com)[2] GitHub REST API “List releases” notes on draft visibility. (docs.github.com)
Citations:
Exclude draft releases from the changelog.
The releases API includes draft releases (for users with push access), which would surface unpublished notes in
CHANGELOG.md. Filter them out in the jq pipeline usingselect(.draft == false)to avoid leaking draft content. If prereleases should also be excluded, add aprerelease == falsepredicate as well.🔧 Proposed fix
🤖 Prompt for AI Agents