diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index b510a80..59ce3f4 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -292,17 +292,10 @@ jobs: publish: needs: [version, aarch64, x86_64] - # Always run after version so a failed build still hits the fail-closed - # delete step (a skipped publish left act without a job result). - # Pi runner, not docker-amd64: the amd64 dind runner is capacity=1 and - # android-release sat in front of run 116's publish for ~1h; the Pi - # already created the tag over the public API (version job), so publish - # uses that same path. This job only curls the Forgejo API — no docker CLI. - # Fail-closed tag delete lives as a step here: a sibling cleanup job ran - # after a successful publish (act treats needs.publish.result as unset, so - # != success) and Early-terminated on run 135. Do not restore that job. + # Always run after version so cleanup can need this job without Forgejo + # act dying on "'runs-on' key not defined" for a skipped publish. if: always() && needs.version.result == 'success' - runs-on: docker + runs-on: docker-amd64 timeout-minutes: 20 steps: - name: Skip publish on dry_run @@ -375,8 +368,13 @@ jobs: dist/onionwire-x86_64-unknown-linux-gnu \ dist/onionwire-x86_64-unknown-linux-gnu.sha256 - - name: Delete tag we created if this job failed - if: failure() && needs.version.outputs.created_tag == 'true' && needs.version.outputs.dry_run != 'true' + cleanup: + needs: [version, aarch64, x86_64, publish] + if: ${{ always() && needs.version.result == 'success' && needs.version.outputs.created_tag == 'true' && needs.publish.result != 'success' }} + runs-on: docker + timeout-minutes: 10 + steps: + - name: Delete tag and incomplete release we created env: FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} REPO_API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} @@ -386,19 +384,19 @@ jobs: FORGEJO_TOKEN=$(printf '%s' "$FORGEJO_TOKEN" | tr -d '\r\n') echo "fail-closed: removing tag $TAG created by this run" code=$(curl -sS --http1.1 -o /tmp/rel.json -w '%{http_code}' \ - -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer $FORGEJO_TOKEN" \ "$REPO_API/releases/tags/$TAG") if [ "$code" = "200" ]; then rid=$(python3 -c "import json; print(json.load(open('/tmp/rel.json'))['id'])") echo "deleting incomplete release id $rid" curl -sS --http1.1 -X DELETE \ - -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer $FORGEJO_TOKEN" \ "$REPO_API/releases/$rid" -o /dev/null -w "DELETE release HTTP %{http_code}\n" else echo "no release for $TAG (HTTP $code)" fi del=$(curl -sS --http1.1 -o /tmp/tag-del.json -w '%{http_code}' -X DELETE \ - -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ + -H "Authorization: Bearer $FORGEJO_TOKEN" \ "$REPO_API/tags/$TAG") echo "DELETE tag HTTP $del" if [ "$del" != "204" ] && [ "$del" != "404" ]; then diff --git a/README.md b/README.md index fc2f559..fa13334 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,13 @@ Arti onion services are still **experimental**. If the hidden service cannot com ### Option A — download a release binary -CI (`.forgejo/workflows/release.yml`) tags and publishes both Linux binaries on every `main` push that touches the core (`src/`, `crates/`, `Cargo.toml`, `Cargo.lock`, or `scripts/release-body.md`). Workflow-only edits do not mint a release — validate those with Actions → release → `dry_run=true`. aarch64 builds on the Pi runner; x86_64 builds on the amd64 runner. Both attach to the same [Forgejo release](https://forgejo.siriusdevops.com/sirius/onionwire/releases). `scripts/build-release-local.sh` remains the offline x86_64 fallback. This Forgejo does not serve `/releases/latest/download/…` (404); pin the tag. +CI (`.forgejo/workflows/release.yml`) tags and publishes both Linux binaries on every `main` push that touches the core (`src/`, `crates/`, `Cargo.toml`, `Cargo.lock`, or the release workflow/scripts). aarch64 builds on the Pi runner; x86_64 builds on the amd64 runner. Both attach to the same [Forgejo release](https://forgejo.siriusdevops.com/sirius/onionwire/releases). `scripts/build-release-local.sh` remains the offline x86_64 fallback. **x86_64 (most PCs / VMs):** ```bash -curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.1.0/onionwire-x86_64-unknown-linux-gnu -curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.1.0/onionwire-x86_64-unknown-linux-gnu.sha256 +curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/latest/download/onionwire-x86_64-unknown-linux-gnu +curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/latest/download/onionwire-x86_64-unknown-linux-gnu.sha256 sha256sum -c onionwire-x86_64-unknown-linux-gnu.sha256 chmod +x onionwire-x86_64-unknown-linux-gnu ./onionwire-x86_64-unknown-linux-gnu --version @@ -40,8 +40,8 @@ chmod +x onionwire-x86_64-unknown-linux-gnu **aarch64 (Raspberry Pi, ARM servers):** ```bash -curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.1.0/onionwire-aarch64-unknown-linux-gnu -curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.1.0/onionwire-aarch64-unknown-linux-gnu.sha256 +curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/latest/download/onionwire-aarch64-unknown-linux-gnu +curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/latest/download/onionwire-aarch64-unknown-linux-gnu.sha256 sha256sum -c onionwire-aarch64-unknown-linux-gnu.sha256 chmod +x onionwire-aarch64-unknown-linux-gnu ./onionwire-aarch64-unknown-linux-gnu --version @@ -274,7 +274,6 @@ Do not push tags by hand — a tag-push trigger would start a second run. # rebuild / re-publish an existing tag, or dry-run a build with no tag: # Actions → release → Run workflow → tag=vX.Y.Z and/or dry_run=true -# (dry_run is how you test release.yml without cutting a user-facing release) # offline x86_64 fallback (idempotent — safe to re-run) FORGEJO_TOKEN= scripts/build-release-local.sh vX.Y.Z @@ -283,7 +282,7 @@ FORGEJO_TOKEN= scripts/build-release-local.sh vX.Y.Z Workflows (Forgejo Actions, `.forgejo/workflows/`): - [`.forgejo/workflows/ci.yml`](.forgejo/workflows/ci.yml) — `cargo test --locked` + `cargo clippy --all-targets -- -D warnings` on `main` and PRs when `src/`, `crates/`, `tests/`, `Cargo.toml`, `Cargo.lock`, or this workflow change (ignored Tor-live tests are not run). `workflow_dispatch` always runs the suite. Pi runner, `docker` label. -- [`.forgejo/workflows/release.yml`](.forgejo/workflows/release.yml) — on core paths to `main` (`src/`, `crates/`, `Cargo.toml`, `Cargo.lock`, `scripts/release-body.md`): next tag, aarch64 (`docker`) + x86_64 (`docker-amd64`), one release. `workflow_dispatch` rebuilds a tag or `dry_run`s. Concurrency group `onionwire-ci-pi` (same as `ci.yml`, `cancel-in-progress: false`) so cargo jobs do not overlap on the Pi. Amd64 dind is serialized by runner `capacity=1`. +- [`.forgejo/workflows/release.yml`](.forgejo/workflows/release.yml) — on core paths to `main`: next tag, aarch64 (`docker`) + x86_64 (`docker-amd64`), one release. `workflow_dispatch` rebuilds a tag or `dry_run`s. Concurrency group `onionwire-release` (separate from CI). Scripts: diff --git a/scripts/publish-release.sh b/scripts/publish-release.sh index ae0e784..cdfd65b 100755 --- a/scripts/publish-release.sh +++ b/scripts/publish-release.sh @@ -12,38 +12,26 @@ # same-named assets instead of failing with 409. set -euo pipefail -# HTTP/1.1: Cloudflare resets HTTP/2 mid-POST (curl 92). Do NOT use -# --retry-all-errors: that retries 422 Unprocessable Entity five times -# and hides the response body (run 116). Connection failures still retry. +# Every API call goes through here. Publishing runs from CI containers that +# reach Forgejo through Cloudflare, where a bare HTTP/2 request intermittently +# dies with curl exit 92 (stream error) — retries plus forcing HTTP/1.1 make +# that a non-event. api_curl() { - curl -sS --http1.1 --retry 5 --retry-connrefused --retry-delay 3 \ + curl -sS --http1.1 --retry 5 --retry-all-errors --retry-delay 3 \ --connect-timeout 20 --max-time 300 "$@" } -auth_json() { - api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" -H "Content-Type: application/json" "$@" -} - tag="${1:?usage: publish-release.sh ...}" name="${2:?missing release name}" body_file="${3:?missing body file}" shift 3 : "${FORGEJO_TOKEN:?FORGEJO_TOKEN is not set}" -FORGEJO_TOKEN=$(printf '%s' "$FORGEJO_TOKEN" | tr -d '\r\n') api="${REPO_API:-https://forgejo.siriusdevops.com/api/v1/repos/sirius/onionwire}" target="${TARGET_COMMITISH:-}" jqp() { python3 -c "import json,sys; d=json.load(sys.stdin); print($1)"; } -die_http() { - local what="$1" code="$2" file="$3" - echo "publish: $what HTTP $code" >&2 - cat "$file" >&2 || true - echo >&2 - exit 1 -} - # Body with @TAG@ substituted, JSON-encoded by python (handles newlines/quotes). python3 - "$body_file" "$tag" "$target" "$name" > /tmp/release-body.json <<'PY' import json, sys @@ -62,37 +50,24 @@ if sys.argv[3]: print(json.dumps(payload)) PY -code=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \ - "$api/releases/tags/$tag") +code=$(api_curl -o /tmp/release-rel.json -w '%{http_code}' \ + -H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/tags/$tag") if [ "$code" = "404" ]; then echo "publish: creating release $tag" - create=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \ - -X POST --data-binary @/tmp/release-body.json "$api/releases") - if [ "$create" = "201" ]; then - : - elif [ "$create" = "409" ] || [ "$create" = "422" ]; then - echo "publish: POST releases HTTP $create — joining if the release exists" - cat /tmp/release-rel.json >&2 || true - echo >&2 - code=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \ - "$api/releases/tags/$tag") - if [ "$code" != "200" ]; then - die_http "create release $tag (then GET)" "$code" /tmp/release-rel.json - fi - echo "publish: release $tag exists, joining" - else - die_http "create release $tag" "$create" /tmp/release-rel.json - fi + api_curl -sf -X POST "$api/releases" \ + -H "Authorization: Bearer $FORGEJO_TOKEN" \ + -H 'Content-Type: application/json' \ + --data @/tmp/release-body.json -o /tmp/release-rel.json elif [ "$code" = "200" ]; then echo "publish: release $tag exists, updating" rid=$(jqp "d['id']" < /tmp/release-rel.json) - patch=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \ - -X PATCH --data-binary @/tmp/release-body.json "$api/releases/$rid") - if [ "$patch" != "200" ]; then - die_http "PATCH release $rid" "$patch" /tmp/release-rel.json - fi + api_curl -sf -X PATCH "$api/releases/$rid" \ + -H "Authorization: Bearer $FORGEJO_TOKEN" \ + -H 'Content-Type: application/json' \ + --data @/tmp/release-body.json -o /tmp/release-rel.json else - die_http "GET releases/tags/$tag" "$code" /tmp/release-rel.json + echo "publish: unexpected status $code from GET releases/tags/$tag" >&2 + cat /tmp/release-rel.json >&2; exit 1 fi rid=$(jqp "d['id']" < /tmp/release-rel.json) echo "publish: release id $rid ($tag)" @@ -109,7 +84,7 @@ for f in "$@"; do fi asset=$(basename "$f") echo "publish: asset $asset is $bytes bytes on disk" - api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \ + api_curl -s -H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/$rid/assets" \ | python3 -c " import json,sys for a in json.load(sys.stdin): @@ -117,21 +92,13 @@ for a in json.load(sys.stdin): " | while read -r aid aname; do if [ "$aname" = "$asset" ]; then echo "publish: deleting stale asset $aname ($aid)" - del=$(api_curl -o /tmp/release-adel.json -w '%{http_code}' \ - -X DELETE -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ - "$api/releases/$rid/assets/$aid") - if [ "$del" != "204" ] && [ "$del" != "404" ]; then - die_http "DELETE asset $aid" "$del" /tmp/release-adel.json - fi + api_curl -sf -X DELETE -H "Authorization: Bearer $FORGEJO_TOKEN" \ + "$api/releases/$rid/assets/$aid" > /dev/null fi done - up=$(api_curl -o /tmp/release-asset.json -w '%{http_code}' \ - -X POST "$api/releases/$rid/assets?name=$asset" \ - -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ - -F "attachment=@$f") - if [ "$up" != "201" ]; then - die_http "upload $asset" "$up" /tmp/release-asset.json - fi + api_curl -sf -X POST "$api/releases/$rid/assets?name=$asset" \ + -H "Authorization: Bearer $FORGEJO_TOKEN" \ + -F "attachment=@$f" -o /tmp/release-asset.json python3 -c " import json,sys d=json.load(open('/tmp/release-asset.json')) @@ -142,7 +109,7 @@ if not size: " done -api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \ +api_curl -s -H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/$rid/assets" \ | python3 -c " import json,sys for a in json.load(sys.stdin):