@@ -2,10 +2,8 @@ name: Release Drafter
22
33on :
44 push :
5- # branches to consider in the event; optional, defaults to all
65 branches :
76 - master
8-
97 pull_request :
108 types : [opened, reopened, synchronize]
119
@@ -15,61 +13,86 @@ permissions:
1513jobs :
1614 update_release_draft :
1715 permissions :
18- # write permission is required to create a github release
1916 contents : write
20- # write permission is required for autolabeler
2117 pull-requests : write
2218 runs-on : ubuntu-latest
2319 steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+ with :
23+ fetch-depth : 0
2424
25- # Drafts your next Release notes as Pull Requests are merged into "master"
2625 - name : Draft Release
2726 id : release_drafter
2827 uses : release-drafter/release-drafter@v6
2928 with :
3029 config-name : release-drafter.yml
3130 publish : false
3231 env :
33- GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
34-
35- - name : Checkout code
36- uses : actions/checkout@v4
37- with :
38- fetch-depth : 0
32+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3933
40- - name : Ensure correct branch is checked out (only on PR)
41- if : github.event_name == 'pull_request'
34+ - name : Debug release-drafter outputs (safe)
4235 run : |
43- echo "Checking out PR source branch: ${{ github.head_ref }}"
44- git fetch origin ${{ github.head_ref }}
45- git checkout ${{ github.head_ref }}
46-
47- - name : Setup Node.js
48- uses : actions/setup-node@v4
49- with :
50- node-version : ' 20'
36+ printf 'release-drafter.tag_name=%s\n' "${{ steps.release_drafter.outputs.tag_name }}"
37+ echo 'release-drafter.body:'
38+ printf '%s\n' "${{ steps.release_drafter.outputs.body }}" > /tmp/release_drafter_body.txt
39+ echo "Wrote release body to /tmp/release_drafter_body.txt"
5140
52- - name : Update Changelog
41+ - name : Create / prepend CHANGELOG entry
42+ if : steps.release_drafter.outputs.tag_name != ''
5343 run : |
54- VERSION="${{ steps.release_drafter.outputs.tag_name }}"
55- BODY="${{ steps.release_drafter.outputs.body }}"
56-
57- # Create a new changelog entry file
58- echo -e "## ${VERSION} ($(date +'%Y-%m-%d'))\n\n${BODY}\n\n" > new_changelog_entry.md
59-
60- # Prepend the new entry to the existing CHANGELOG.md
44+ TAG="${{ steps.release_drafter.outputs.tag_name }}"
45+ BODY_FILE="/tmp/release_drafter_body.txt"
46+ DATE="$(date +%F)"
47+ if [ -f "$BODY_FILE" ]; then
48+ BODY="$(cat "$BODY_FILE")"
49+ else
50+ BODY="${{ steps.release_drafter.outputs.body }}"
51+ fi
52+ printf "## %s - %s\n\n%s\n\n---\n\n" "$TAG" "$DATE" "$BODY" > /tmp/new_changelog.md
6153 if [ -f CHANGELOG.md ]; then
62- cat CHANGELOG.md >> new_changelog_entry .md
54+ cat CHANGELOG.md >> /tmp/new_changelog .md
6355 fi
64- mv new_changelog_entry.md CHANGELOG.md
56+ mv /tmp/new_changelog.md CHANGELOG.md
57+ git status --porcelain || true
6558
66- # Commits the updated CHANGELOG.md and creates a tag for the new version
67- - name : Commit and Push Changelog
68- uses : stefanzweifel/git-auto-commit-action@v5
69- with :
70- commit_message : ' docs: Update CHANGELOG.md for ${{ steps.release_drafter.outputs.tag_name }}'
71- file_pattern : ' CHANGELOG.md'
72- tagging_message : ${{ steps.release_drafter.outputs.tag_name }}
59+ - name : Commit & push CHANGELOG and tag via GITHUB_TOKEN
60+ if : steps.release_drafter.outputs.tag_name != ''
61+ env :
62+ TAG : ${{ steps.release_drafter.outputs.tag_name }}
63+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
64+ run : |
65+ set -e
66+ git config user.name "github-actions[bot]"
67+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
68+
69+ git add CHANGELOG.md || true
70+
71+ if git diff --cached --quiet; then
72+ echo "No CHANGELOG.md changes to commit"
73+ else
74+ git commit -m "docs(changelog): update for ${TAG}"
75+ fi
76+
77+ REPO="${{ github.repository }}"
78+
79+ # Push commit (use token to authenticate)
80+ git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${REPO}.git" HEAD:refs/heads/master
7381
82+ # Create annotated tag if missing and push it
83+ if git rev-parse "${TAG}" >/dev/null 2>&1; then
84+ echo "Tag ${TAG} already exists locally"
85+ else
86+ git tag -a "${TAG}" -m "Release ${TAG}" || true
87+ fi
88+ git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${REPO}.git" "refs/tags/${TAG}" || echo "Tag push failed or tag exists"
7489
75-
90+ - name : Setup Node.js
91+ uses : actions/setup-node@v4
92+ with :
93+ node-version : ' 20'
94+
95+ - name : (Optional) Update Changelog formatting / run scripts
96+ run : |
97+ # placeholder for any project-specific changelog formatting commands
98+ echo "Changelog updated; no additional formatting configured"
0 commit comments