Skip to content

Commit 32eadf5

Browse files
committed
release workflow skips existing releases instead of failing
1 parent 4d4e7f3 commit 32eadf5

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,40 @@ jobs:
2121
name: Create Release
2222
runs-on: ubuntu-latest
2323
outputs:
24-
upload_url: ${{ steps.create_release.outputs.upload_url }}
24+
upload_url: ${{ steps.finalize.outputs.upload_url }}
25+
release_exists: ${{ steps.release_info.outputs.exists }}
2526
steps:
27+
- name: Check if release exists
28+
id: release_info
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
TAG_NAME: ${{ github.event.inputs.tag || github.ref_name }}
32+
shell: bash
33+
run: |
34+
api_url="https://api.github.com/repos/${{ github.repository }}/releases/tags/${TAG_NAME}"
35+
response_path="${RUNNER_TEMP}/release_info.json"
36+
status_code=$(curl -sS -o "${response_path}" -w "%{http_code}" \
37+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
38+
-H "Accept: application/vnd.github+json" \
39+
"${api_url}")
40+
if [[ "${status_code}" == "200" ]]; then
41+
upload_url=$(python3 - <<'PY'
42+
import json
43+
import sys
44+
with open(sys.argv[1], "r", encoding="utf-8") as handle:
45+
data = json.load(handle)
46+
print(data.get("upload_url", ""))
47+
PY
48+
"${response_path}")
49+
echo "exists=true" >> "$GITHUB_OUTPUT"
50+
echo "upload_url=${upload_url}" >> "$GITHUB_OUTPUT"
51+
else
52+
echo "exists=false" >> "$GITHUB_OUTPUT"
53+
fi
54+
2655
- name: Create Release
2756
id: create_release
57+
if: steps.release_info.outputs.exists != 'true'
2858
uses: actions/create-release@v1
2959
env:
3060
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -34,9 +64,19 @@ jobs:
3464
draft: false
3565
prerelease: false
3666

67+
- name: Finalize release metadata
68+
id: finalize
69+
run: |
70+
upload_url="${{ steps.create_release.outputs.upload_url }}"
71+
if [ "${{ steps.release_info.outputs.exists }}" = "true" ]; then
72+
upload_url="${{ steps.release_info.outputs.upload_url }}"
73+
fi
74+
echo "upload_url=${upload_url}" >> "$GITHUB_OUTPUT"
75+
3776
build-release:
3877
name: Build Release Binaries
3978
needs: create-release
79+
if: needs.create-release.outputs.release_exists != 'true'
4080
runs-on: ${{ matrix.os }}
4181
strategy:
4282
matrix:

0 commit comments

Comments
 (0)