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:
|
on:
|
||||||
push:
|
push:
|
||||||
tags: ['v*']
|
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:
|
jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ env.TAG }}
|
||||||
|
|
||||||
- name: Install Zig
|
- name: Install Zig
|
||||||
run: echo "$(.github/ci/install-zig.sh)" >> "$GITHUB_PATH"
|
run: echo "$(.github/ci/install-zig.sh)" >> "$GITHUB_PATH"
|
||||||
@@ -18,7 +28,7 @@ jobs:
|
|||||||
- name: Check the tag matches build.zig.zon
|
- name: Check the tag matches build.zig.zon
|
||||||
run: |
|
run: |
|
||||||
version=$(sed -n 's/^[[:space:]]*\.version = "\(.*\)",$/\1/p' build.zig.zon)
|
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
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
@@ -41,18 +51,25 @@ jobs:
|
|||||||
|
|
||||||
- name: Publish the release
|
- name: Publish the release
|
||||||
env:
|
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: |
|
run: |
|
||||||
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
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 '""')
|
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" \
|
resp=$(mktemp)
|
||||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
code=$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$api/releases" \
|
||||||
-d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"${GITHUB_REF_NAME}\",\"body\":${body}}" \
|
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||||
| sed -n 's/.*"id":\([0-9]*\).*/\1/p' | head -1)
|
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":${body}}")
|
||||||
[ -n "$id" ] || { echo "could not create the release"; exit 1; }
|
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
|
for f in dist/*; do
|
||||||
echo "uploading $f"
|
echo "uploading $f"
|
||||||
curl -fsS -X POST "$api/releases/$id/assets?name=$(basename "$f")" \
|
code=$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$api/releases/$id/assets?name=$(basename "$f")" \
|
||||||
-H "Authorization: token $TOKEN" -F "attachment=@$f" >/dev/null
|
-H "Authorization: token $TOKEN" -F "attachment=@$f")
|
||||||
|
[ "$code" = "201" ] || { echo "upload of $f failed: HTTP $code"; cat "$resp"; echo; exit 1; }
|
||||||
done
|
done
|
||||||
Reference in new issue
Block a user