diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index e4690a9..4c7b8aa 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -2,10 +2,29 @@ name: ci # Tests and clippy run on the Pi runner (aarch64) inside a rust container, so # this CI proves the aarch64 build too. Jobs use the runner's `docker` label. +# +# Path allowlist: skip the cargo job when the change cannot affect the Rust +# build (docs, android, scripts, sibling workflows, markdown). No required +# status checks on main, so a missing run is not a merge trap. +# workflow_dispatch has no path filter — it always runs the suite. on: push: branches: [main] + paths: + - "src/**" + - "crates/**" + - "tests/**" + - "Cargo.toml" + - "Cargo.lock" + - ".forgejo/workflows/ci.yml" pull_request: + paths: + - "src/**" + - "crates/**" + - "tests/**" + - "Cargo.toml" + - "Cargo.lock" + - ".forgejo/workflows/ci.yml" workflow_dispatch: # One cargo job on the Pi at a time. Overlapping PR+main runs shared the diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index 3b9f22a..b510a80 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -13,8 +13,6 @@ on: - "crates/**" - "Cargo.toml" - "Cargo.lock" - - ".forgejo/workflows/release.yml" - - "scripts/build-release-local.sh" - "scripts/release-body.md" workflow_dispatch: inputs: @@ -28,13 +26,18 @@ on: type: string default: "false" +# Same group as ci.yml: both cargo builds share the Pi's 4 cores and the +# onionwire-cargo-registry volume. A separate group raced tests and produced +# Permission denied (os error 13) on /target/debug/deps/* binaries. concurrency: - group: onionwire-release + group: onionwire-ci-pi cancel-in-progress: false env: CARGO_TERM_COLOR: never RUST_IMAGE: rust:1.91-bookworm + # Not baking pkg-config/libssl-dev into a custom image on this card — + # dind PVC would make that the durable fix for the apt loop. Filed separately. CARGO_REGISTRY_VOLUME: onionwire-cargo-registry jobs: @@ -170,8 +173,8 @@ jobs: -w /src \ "$RUST_IMAGE" \ sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ - && apt-get update \ - && apt-get install -y --no-install-recommends pkg-config libssl-dev \ + && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \ + && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev \ && cargo build --release --locked \ && strip /target/release/onionwire \ && ls -l /target/release/onionwire' @@ -221,6 +224,21 @@ jobs: - name: Show runner arch run: uname -m && echo "target=$TARGET" + - name: Ensure docker CLI (amd64 dind job image has none) + run: | + set -euo pipefail + if ! command -v docker >/dev/null 2>&1; then + curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-27.3.1.tgz \ + | tar xz -C /tmp + install -m 755 /tmp/docker/docker /usr/local/bin/docker + fi + docker version + if [ ! -S /var/run/docker.sock ]; then + echo "docker.sock is not mounted into the job container" >&2 + ls -l /var/run || true + exit 1 + fi + - name: Build ${{ env.TARGET }} in a rust container run: | set -euo pipefail @@ -238,8 +256,8 @@ jobs: -w /src \ "$RUST_IMAGE" \ sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ - && apt-get update \ - && apt-get install -y --no-install-recommends pkg-config libssl-dev \ + && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true update \ + && apt-get -o Acquire::Retries=5 -o Acquire::http::Timeout=20 -o Acquire::https::Timeout=20 -o Acquire::ForceIPv4=true install -y --no-install-recommends pkg-config libssl-dev \ && cargo build --release --locked \ && strip /target/release/onionwire \ && ls -l /target/release/onionwire' @@ -274,21 +292,43 @@ jobs: publish: needs: [version, aarch64, x86_64] - if: needs.version.outputs.dry_run != 'true' - runs-on: docker-amd64 + # 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. + if: always() && needs.version.result == 'success' + runs-on: docker timeout-minutes: 20 steps: + - name: Skip publish on dry_run + if: needs.version.outputs.dry_run == 'true' + run: echo "dry_run not publishing" + + - name: Fail closed if a build failed + if: needs.version.outputs.dry_run != 'true' && (needs.aarch64.result != 'success' || needs.x86_64.result != 'success') + run: | + echo "aarch64=${{ needs.aarch64.result }} x86_64=${{ needs.x86_64.result }}" >&2 + exit 1 + - name: Checkout CI tooling + if: needs.version.outputs.dry_run != 'true' && needs.aarch64.result == 'success' && needs.x86_64.result == 'success' uses: https://code.forgejo.org/actions/checkout@v4 with: path: .ci-tools - name: Download both arch artifacts + if: needs.version.outputs.dry_run != 'true' && needs.aarch64.result == 'success' && needs.x86_64.result == 'success' uses: https://code.forgejo.org/actions/download-artifact@v3 with: path: artifacts - name: Publish both binaries to one release + if: needs.version.outputs.dry_run != 'true' && needs.aarch64.result == 'success' && needs.x86_64.result == 'success' env: FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} REPO_API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} @@ -335,30 +375,33 @@ jobs: dist/onionwire-x86_64-unknown-linux-gnu \ dist/onionwire-x86_64-unknown-linux-gnu.sha256 - cleanup: - needs: [version, aarch64, x86_64, publish] - if: ${{ always() && needs.version.outputs.created_tag == 'true' && (needs.aarch64.result != 'success' || needs.x86_64.result != 'success' || needs.publish.result != 'success') }} - runs-on: docker - timeout-minutes: 10 - steps: - - name: Delete tag and incomplete release we created + - name: Delete tag we created if this job failed + if: failure() && needs.version.outputs.created_tag == 'true' && needs.version.outputs.dry_run != 'true' env: FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} REPO_API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} TAG: ${{ needs.version.outputs.tag }} run: | set -euo pipefail + 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" \ + curl -sS --http1.1 -X DELETE \ + -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 - curl -sS --http1.1 -X DELETE -H "Authorization: Bearer $FORGEJO_TOKEN" \ - "$REPO_API/tags/$TAG" -o /dev/null -w "DELETE tag HTTP %{http_code}\n" + del=$(curl -sS --http1.1 -o /tmp/tag-del.json -w '%{http_code}' -X DELETE \ + -H "Authorization: Bearer ${FORGEJO_TOKEN}" \ + "$REPO_API/tags/$TAG") + echo "DELETE tag HTTP $del" + if [ "$del" != "204" ] && [ "$del" != "404" ]; then + cat /tmp/tag-del.json >&2 || true + exit 1 + fi diff --git a/README.md b/README.md index 562ec3e..fc2f559 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 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. +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. **x86_64 (most PCs / VMs):** ```bash -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 +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 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/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 +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 sha256sum -c onionwire-aarch64-unknown-linux-gnu.sha256 chmod +x onionwire-aarch64-unknown-linux-gnu ./onionwire-aarch64-unknown-linux-gnu --version @@ -274,6 +274,7 @@ 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 @@ -281,8 +282,8 @@ 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 (ignored Tor-live tests are not run). Pi runner, `docker` label. -- [`.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). +- [`.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`. Scripts: diff --git a/scripts/publish-release.sh b/scripts/publish-release.sh index cdfd65b..ae0e784 100755 --- a/scripts/publish-release.sh +++ b/scripts/publish-release.sh @@ -12,26 +12,38 @@ # same-named assets instead of failing with 409. set -euo pipefail -# 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. +# 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. api_curl() { - curl -sS --http1.1 --retry 5 --retry-all-errors --retry-delay 3 \ + curl -sS --http1.1 --retry 5 --retry-connrefused --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 @@ -50,24 +62,37 @@ if sys.argv[3]: print(json.dumps(payload)) PY -code=$(api_curl -o /tmp/release-rel.json -w '%{http_code}' \ - -H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/tags/$tag") +code=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \ + "$api/releases/tags/$tag") if [ "$code" = "404" ]; then echo "publish: creating release $tag" - 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 + 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 elif [ "$code" = "200" ]; then echo "publish: release $tag exists, updating" rid=$(jqp "d['id']" < /tmp/release-rel.json) - 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 + 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 else - echo "publish: unexpected status $code from GET releases/tags/$tag" >&2 - cat /tmp/release-rel.json >&2; exit 1 + die_http "GET releases/tags/$tag" "$code" /tmp/release-rel.json fi rid=$(jqp "d['id']" < /tmp/release-rel.json) echo "publish: release id $rid ($tag)" @@ -84,7 +109,7 @@ for f in "$@"; do fi asset=$(basename "$f") echo "publish: asset $asset is $bytes bytes on disk" - api_curl -s -H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/$rid/assets" \ + api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \ | python3 -c " import json,sys for a in json.load(sys.stdin): @@ -92,13 +117,21 @@ for a in json.load(sys.stdin): " | while read -r aid aname; do if [ "$aname" = "$asset" ]; then echo "publish: deleting stale asset $aname ($aid)" - api_curl -sf -X DELETE -H "Authorization: Bearer $FORGEJO_TOKEN" \ - "$api/releases/$rid/assets/$aid" > /dev/null + 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 fi done - api_curl -sf -X POST "$api/releases/$rid/assets?name=$asset" \ - -H "Authorization: Bearer $FORGEJO_TOKEN" \ - -F "attachment=@$f" -o /tmp/release-asset.json + 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 python3 -c " import json,sys d=json.load(open('/tmp/release-asset.json')) @@ -109,7 +142,7 @@ if not size: " done -api_curl -s -H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/$rid/assets" \ +api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \ | python3 -c " import json,sys for a in json.load(sys.stdin):