2121 steps :
2222 - name : Determine PR source
2323 id : source
24+ env :
25+ HEAD_REPO : ${{ github.event.pull_request.head.repo.full_name }}
26+ THIS_REPO : ${{ github.repository }}
2427 run : |
25- if [ "${{ github.event.pull_request.head.repo.full_name }} " = "${{ github.repository }} " ]; then
28+ if [ "$HEAD_REPO " = "$THIS_REPO " ]; then
2629 echo "same_repo=true" >> "$GITHUB_OUTPUT"
2730 else
2831 echo "same_repo=false" >> "$GITHUB_OUTPUT"
@@ -42,18 +45,21 @@ jobs:
4245 fi
4346 echo "ref=$REF" >> "$GITHUB_OUTPUT"
4447
45- - uses : actions/checkout@v6
48+ - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4649 if : steps.source.outputs.same_repo == 'true'
4750 with :
4851 repository : ${{ github.event.pull_request.head.repo.full_name }}
4952 ref : ${{ github.event.pull_request.head.sha }}
5053 fetch-depth : 0
5154 token : ${{ secrets.GH_PAT }}
55+ persist-credentials : false
5256
5357 - name : Fetch base branch for diff comparison
5458 if : steps.source.outputs.same_repo == 'true'
59+ env :
60+ BASE_REF : ${{ github.base_ref }}
5561 run : |
56- git fetch origin "${{ github.base_ref }} "
62+ git fetch origin "$BASE_REF "
5763
5864 - name : Configure git credentials for private dependencies
5965 if : steps.source.outputs.same_repo == 'true'
@@ -62,20 +68,31 @@ jobs:
6268 - name : Check for existing changelog
6369 if : steps.source.outputs.same_repo == 'true'
6470 id : existing
71+ env :
72+ BASE_REF : ${{ github.base_ref }}
6573 run : |
66- if git diff "origin/${{ github.base_ref } }...HEAD" --name-only | grep -q '^\.changelog/.*\.md$'; then
74+ if git diff "origin/${BASE_REF }...HEAD" --name-only | grep -q '^\.changelog/.*\.md$'; then
6775 echo "found=true" >> "$GITHUB_OUTPUT"
6876 else
6977 echo "found=false" >> "$GITHUB_OUTPUT"
7078 fi
7179
7280 - name : Install changelogs
7381 if : steps.source.outputs.same_repo == 'true' && steps.existing.outputs.found == 'false'
74- run : curl -sSL https://changelogs.sh | sh -s -- changelogs@0.6.2
82+ run : |
83+ EXPECTED_SHA256="34bca37144e400d167f936d83c092da4b032591a74ae8c0175c3a42d716cc54c"
84+ CHANGELOGS_BIN="$RUNNER_TEMP/changelogs"
85+ curl -fsSL "https://github.com/tempoxyz/changelogs/releases/download/changelogs%400.6.2/changelogs-linux-amd64" -o "$CHANGELOGS_BIN"
86+ ACTUAL_SHA256=$(sha256sum "$CHANGELOGS_BIN" | cut -d' ' -f1)
87+ if [ "$ACTUAL_SHA256" != "$EXPECTED_SHA256" ]; then
88+ echo "::error::changelogs checksum mismatch: expected $EXPECTED_SHA256, got $ACTUAL_SHA256"
89+ exit 1
90+ fi
91+ chmod +x "$CHANGELOGS_BIN"
7592
7693 - name : Install claude
7794 if : steps.source.outputs.same_repo == 'true' && steps.existing.outputs.found == 'false'
78- run : npm install -g @anthropic-ai/claude-code
95+ run : npm install -g @anthropic-ai/claude-code@1.0.3
7996
8097 - name : Extract bump level from label
8198 if : steps.source.outputs.same_repo == 'true' && steps.existing.outputs.found == 'false'
89106 env :
90107 ANTHROPIC_API_KEY : ${{ secrets.ANTHROPIC_API_KEY }}
91108 BUMP_LEVEL : ${{ steps.bump.outputs.level }}
109+ BASE_REF : ${{ github.base_ref }}
92110 run : |
111+ CHANGELOGS_BIN="$RUNNER_TEMP/changelogs"
93112 cat > /tmp/changelog-instructions.md << 'PROMPT'
94113 Generate a changelog entry for this git diff.
95114
@@ -114,28 +133,35 @@ jobs:
114133 {diff}
115134 PROMPT
116135 sed -i "s/BUMP_LEVEL/$BUMP_LEVEL/g" /tmp/changelog-instructions.md
117- changelogs add --ai "claude -p" --ref "origin/${{ github.base_ref } }" \
136+ "$CHANGELOGS_BIN" add --ai "claude -p" --ref "origin/${BASE_REF }" \
118137 --instructions "$(cat /tmp/changelog-instructions.md)"
119138
120139 - name : Commit and push changelog
121140 if : steps.source.outputs.same_repo == 'true' && steps.existing.outputs.found == 'false'
141+ env :
142+ VALIDATED_REF : ${{ steps.ref.outputs.ref }}
122143 run : |
123144 set -euo pipefail
124145 git config user.name "github-actions[bot]"
125146 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
126147 git add .changelog/
127148 git commit -m "chore: add changelog"
128- git push origin "HEAD:${{ steps.ref.outputs.ref } }"
149+ git push origin "HEAD:${VALIDATED_REF }"
129150
130151 - name : Comment for fork PRs
131152 if : steps.source.outputs.same_repo != 'true'
132153 env :
133154 GH_TOKEN : ${{ github.token }}
155+ PR_NUMBER : ${{ github.event.number }}
156+ REPO : ${{ github.repository }}
134157 run : |
135- gh pr comment "${{ github.event.number }} " --repo "${{ github.repository }} " --body "Changelog auto-generation is only supported for same-repo branches. For fork PRs, please add a changelog file manually under .changelog/."
158+ gh pr comment "$PR_NUMBER " --repo "$REPO " --body "Changelog auto-generation is only supported for same-repo branches. For fork PRs, please add a changelog file manually under .changelog/."
136159
137160 - name : Remove label
138161 if : always()
139162 env :
140163 GH_TOKEN : ${{ github.token }}
141- run : gh pr edit ${{ github.event.number }} --repo "${{ github.repository }}" --remove-label "${{ github.event.label.name }}"
164+ PR_NUMBER : ${{ github.event.number }}
165+ REPO : ${{ github.repository }}
166+ LABEL : ${{ github.event.label.name }}
167+ run : gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$LABEL"
0 commit comments