Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Update Changelog

on:
release:
types: [published]
workflow_run:
workflows: ["Tag zxporter (manual)"]
types: [completed]

permissions:
contents: write
Expand All @@ -11,11 +12,14 @@ permissions:
jobs:
update-changelog:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main

- name: Update CHANGELOG.md from releases
env:
Expand All @@ -32,18 +36,21 @@ jobs:
"[GitHub Releases](https://github.com/${{ github.repository }}/releases) page." \
"" > CHANGELOG.md

# Append all releases using JSON for reliable parsing (paginate to include all)
# Append all (non-draft) 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)"' \
| jq -s -r 'add
| map(select(.draft == false) | {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
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:
Expand All @@ -52,23 +59,32 @@ jobs:
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 }}"
# Latest stable release tag (since you only do releases)
LATEST_TAG=$(gh api repos/${{ github.repository }}/releases/latest --jq '.tag_name')

if [[ -z "$LATEST_TAG" || "$LATEST_TAG" == "null" ]]; then
echo "Error: No latest release tag found"
exit 1
fi

BRANCH_NAME="chore/update-changelog-${LATEST_TAG}"
git checkout -B "$BRANCH_NAME"
git commit -m "chore: update changelog for ${{ github.event.release.tag_name }}"
git commit -m "chore: update changelog for ${LATEST_TAG}"
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 }}" \
--title "chore: update changelog for ${LATEST_TAG}" \
--body "Automated changelog update for release ${LATEST_TAG}" \
--base main \
--head "$BRANCH_NAME"
fi