diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index de8ddf9..22c3b64 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -16,10 +16,12 @@ jobs: runs-on: ubuntu-latest # The built-in token every job is given carries whatever the instance's # default mode allows, and under the restricted default that is read-only - # on releases — so the build would succeed and the upload would 403. Asking - # for the one scope this needs works under either default. + # on releases — so the build would succeed and the publish would be + # refused. `contents` covers code and releases together, which is what + # creating a release needs: `releases: write` alone was refused, because + # creating one can create its tag. permissions: - releases: write + contents: write steps: - uses: actions/checkout@v4 with: @@ -113,10 +115,17 @@ jobs: | sed -n 's/.*"id":\([0-9]*\).*/\1/p' | head -1) if [ -z "$id" ]; then echo "creating release $tag" - id=$(curl -sS -X POST -H "Authorization: token $TOKEN" \ + body=$(curl -sS -w '\n%{http_code}' -X POST \ + -H "Authorization: token $TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"$tag\",\"name\":\"$tag\"}" \ - "$api/releases" | sed -n 's/.*"id":\([0-9]*\).*/\1/p' | head -1) + "$api/releases") + code=$(printf '%s' "$body" | tail -1) + echo "create returned $code" + id=$(printf '%s' "$body" | sed -n 's/.*"id":\([0-9]*\).*/\1/p' | head -1) + # Whatever went wrong, the server said so, and the previous version + # of this step threw that away and reported only that it had failed. + [ -n "$id" ] || printf '%s\n' "$body" | head -5 >&2 fi [ -n "$id" ] || { echo "could not find or create the release" >&2; exit 1; }