ci: report release API errors, support re-running the release for an existing tag
CI / test (push) Successful in 3m20s
CI / test (push) Successful in 3m20s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
508f515f5b
commit
4b55f5a060
1 file changed
+27
-10
@@ -5,12 +5,22 @@ name: Release
|
||||
on:
|
||||
push:
|
||||
tags: ['v*']
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: 'Existing tag to build and publish (e.g. v0.1.0)'
|
||||
required: true
|
||||
|
||||
env:
|
||||
TAG: ${{ inputs.tag || github.ref_name }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ env.TAG }}
|
||||
|
||||
- name: Install Zig
|
||||
run: echo "$(.github/ci/install-zig.sh)" >> "$GITHUB_PATH"
|
||||
@@ -18,7 +28,7 @@ jobs:
|
||||
- name: Check the tag matches build.zig.zon
|
||||
run: |
|
||||
version=$(sed -n 's/^[[:space:]]*\.version = "\(.*\)",$/\1/p' build.zig.zon)
|
||||
[ "v$version" = "${GITHUB_REF_NAME}" ] || { echo "tag ${GITHUB_REF_NAME} != v$version"; exit 1; }
|
||||
[ "v$version" = "$TAG" ] || { echo "tag $TAG != v$version"; exit 1; }
|
||||
|
||||
- name: Test
|
||||
run: |
|
||||
@@ -41,18 +51,25 @@ jobs:
|
||||
|
||||
- name: Publish the release
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# RELEASE_TOKEN (a personal access token with write:repository) wins when the
|
||||
# built-in token is not allowed to create releases.
|
||||
TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
notes=$(awk -v v="${GITHUB_REF_NAME#v}" '$0 ~ "^## \\[?"v {f=1; next} /^## / {f=0} f' CHANGELOG.md)
|
||||
notes=$(awk -v v="${TAG#v}" '$0 ~ "^## \\[?"v {f=1; next} /^## / {f=0} f' CHANGELOG.md)
|
||||
body=$(printf '%s' "$notes" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))' 2>/dev/null || echo '""')
|
||||
id=$(curl -fsS -X POST "$api/releases" \
|
||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"${GITHUB_REF_NAME}\",\"body\":${body}}" \
|
||||
| sed -n 's/.*"id":\([0-9]*\).*/\1/p' | head -1)
|
||||
[ -n "$id" ] || { echo "could not create the release"; exit 1; }
|
||||
resp=$(mktemp)
|
||||
code=$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$api/releases" \
|
||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":${body}}")
|
||||
if [ "$code" != "201" ]; then
|
||||
echo "creating the release failed: HTTP $code"; cat "$resp"; echo
|
||||
exit 1
|
||||
fi
|
||||
id=$(sed -n 's/.*"id":\([0-9]*\).*/\1/p' "$resp" | head -1)
|
||||
for f in dist/*; do
|
||||
echo "uploading $f"
|
||||
curl -fsS -X POST "$api/releases/$id/assets?name=$(basename "$f")" \
|
||||
-H "Authorization: token $TOKEN" -F "attachment=@$f" >/dev/null
|
||||
code=$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$api/releases/$id/assets?name=$(basename "$f")" \
|
||||
-H "Authorization: token $TOKEN" -F "attachment=@$f")
|
||||
[ "$code" = "201" ] || { echo "upload of $f failed: HTTP $code"; cat "$resp"; echo; exit 1; }
|
||||
done
|
||||
Reference in new issue
Block a user