Skip to content

Commit b03b3c8

Browse files
committed
release action fixes: don't trample existing releases
1 parent 606a254 commit b03b3c8

1 file changed

Lines changed: 24 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ jobs:
185185
runs-on: ubuntu-22.04
186186
outputs:
187187
release_id: ${{ steps.create_release.outputs.id }}
188+
tag: ${{ steps.resolve.outputs.tag }}
188189
steps:
189190
- uses: actions/checkout@v4
190191

@@ -218,6 +219,24 @@ jobs:
218219
echo "tag=${resolved_tag}" >> "$GITHUB_OUTPUT"
219220
echo "name=Robrix ${resolved_tag}" >> "$GITHUB_OUTPUT"
220221
222+
# Safety: this workflow only ever creates a NEW release. If one already
223+
# exists for the tag, bail so we never adopt, overwrite, or unpublish it.
224+
- name: Refuse to reuse an existing release
225+
shell: bash
226+
env:
227+
GH_TOKEN: ${{ secrets.ROBRIX_RELEASE }}
228+
run: |
229+
TAG="${{ steps.resolve.outputs.tag }}"
230+
existing=$(gh api "repos/${{ github.repository }}/releases" --paginate \
231+
--jq ".[] | select(.tag_name == \"$TAG\") | \"id=\(.id) draft=\(.draft)\"")
232+
if [[ -n "$existing" ]]; then
233+
echo "::error::A release already exists for tag '$TAG' ($existing)."
234+
echo "::error::This workflow only creates new releases; it will not touch an existing one."
235+
echo "::error::For testing, dispatch a throwaway release_tag. For a real re-release, delete the old one first, deliberately."
236+
exit 1
237+
fi
238+
echo "No existing release for '$TAG'; safe to create a fresh one."
239+
221240
- name: Create Release
222241
id: create_release
223242
uses: softprops/action-gh-release@v2
@@ -314,16 +333,13 @@ jobs:
314333
./packaging/build-macos-dmg.sh
315334
316335
- name: Upload DMG to Release
336+
if: ${{ needs.create_release.outputs.release_id != '' }}
317337
env:
318338
GH_TOKEN: ${{ secrets.ROBRIX_RELEASE }}
319339
run: |
320340
DMG_FILE=$(find ./dist -name '*.dmg' -print -quit)
321-
RELEASE_ID="${{ needs.create_release.outputs.release_id }}"
322-
gh api "repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
323-
--method POST \
324-
-H "Content-Type: application/octet-stream" \
325-
--input "$DMG_FILE" \
326-
-f "name=$(basename "$DMG_FILE")"
341+
gh release upload "${{ needs.create_release.outputs.tag }}" "$DMG_FILE" \
342+
--repo ${{ github.repository }}
327343
328344
for_windows:
329345
name: Release Robrix for Windows (${{ matrix.os }}, ${{ matrix.arch }})
@@ -450,8 +466,5 @@ jobs:
450466
echo "Error: no .ipa found to upload"
451467
exit 1
452468
fi
453-
gh api "repos/${{ github.repository }}/releases/${{ needs.create_release.outputs.release_id }}/assets" \
454-
--method POST \
455-
-H "Content-Type: application/octet-stream" \
456-
--input "$IPA_FILE" \
457-
-f "name=$(basename "$IPA_FILE")"
469+
gh release upload "${{ needs.create_release.outputs.tag }}" "$IPA_FILE" \
470+
--repo ${{ github.repository }}

0 commit comments

Comments
 (0)