Skip to content

Commit 4aca268

Browse files
ci: make release workflow idempotent for existing releases
`gh release create` fails with HTTP 422 when a Release already exists for the tag (e.g. when the tag+release were created from the GitHub UI, which triggers this workflow). Detect an existing release and update its notes instead of failing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 85c3d8a commit 4aca268

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,19 @@ jobs:
7272
echo "No CHANGELOG section found for $version; GitHub will auto-generate notes."
7373
fi
7474
75-
- name: Create GitHub Release
75+
- name: Create or update GitHub Release
7676
env:
7777
GH_TOKEN: ${{ github.token }}
7878
run: |
79-
if [ -s release-notes.md ]; then
79+
# Idempotent: the tag may already have a Release (e.g. created from
80+
# the GitHub UI, which both tags and releases in one step). In that
81+
# case update its notes instead of failing on a duplicate create.
82+
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
83+
echo "Release $GITHUB_REF_NAME already exists; updating notes."
84+
if [ -s release-notes.md ]; then
85+
gh release edit "$GITHUB_REF_NAME" --notes-file release-notes.md
86+
fi
87+
elif [ -s release-notes.md ]; then
8088
gh release create "$GITHUB_REF_NAME" \
8189
--title "$GITHUB_REF_NAME" \
8290
--notes-file release-notes.md

0 commit comments

Comments
 (0)