name: release # Manual, batched releases. There is deliberately NO push trigger: a merged # PR does not mint a release. A maintainer dispatches this at a stopping point # (a batch of work has landed and CI is green on main) — see docs/RELEASING.md. # Tag-push is intentionally NOT a trigger here: this workflow creates the tag # via the API, and a tag-push hook would start a second run of the same release. # (A tag this workflow creates does not wake android-release.yml either — see # docs/RELEASING.md: on this Forgejo, pushes made with the CI token are # Actions-user events and are not dispatched back into Actions.) # Version: explicit `version`, else `bump` off the newest v*.*.* tag # (default minor — a batched release is usually a feature set); zero tags → v0.1.0. on: workflow_dispatch: inputs: bump: description: Bump off the newest v*.*.* tag (ignored when version or tag is set) required: false type: choice options: - minor - patch - major default: minor version: description: Explicit version MAJOR.MINOR.PATCH (or vMAJOR.MINOR.PATCH); overrides bump required: false type: string tag: description: Existing tag to (re)build and publish (empty = create the next version) required: false type: string dry_run: description: Build and checksum without creating a tag or publishing (true/false) required: false 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-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: version: runs-on: docker timeout-minutes: 10 outputs: tag: ${{ steps.plan.outputs.tag }} sha: ${{ steps.plan.outputs.sha }} dry_run: ${{ steps.plan.outputs.dry_run }} created_tag: ${{ steps.plan.outputs.created_tag }} steps: - name: Plan version, create tag unless dry_run id: plan env: FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} REPO_API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} EVENT_NAME: ${{ github.event_name }} EVENT_SHA: ${{ github.sha }} INPUT_BUMP: ${{ github.event.inputs.bump }} INPUT_VERSION: ${{ github.event.inputs.version }} INPUT_TAG: ${{ github.event.inputs.tag }} INPUT_DRY_RUN: ${{ github.event.inputs.dry_run }} run: | set -euo pipefail : "${FORGEJO_TOKEN:?FORGEJO_TOKEN secret is not set}" FORGEJO_TOKEN=$(printf '%s' "$FORGEJO_TOKEN" | tr -d '\r\n') dry_run=false if [ "$EVENT_NAME" = "workflow_dispatch" ]; then case "${INPUT_DRY_RUN:-false}" in true|True|TRUE|1|yes|YES) dry_run=true ;; esac fi echo "event=$EVENT_NAME sha=$EVENT_SHA input_version=${INPUT_VERSION-} input_tag=${INPUT_TAG-} input_bump=${INPUT_BUMP-} input_dry_run=${INPUT_DRY_RUN-} dry_run=$dry_run" api_curl() { curl -sS --http1.1 --retry 5 --retry-all-errors --retry-delay 3 \ --connect-timeout 20 --max-time 60 \ -u "sirius:${FORGEJO_TOKEN}" "$@" | sed 's/\r$//' } input_tag="${INPUT_TAG:-}" version_input="${INPUT_VERSION:-}" bump="${INPUT_BUMP:-minor}" # Contradictory input is rejected, never guessed at. if [ -n "$input_tag" ] && [ -n "$version_input" ]; then echo "got both tag='$input_tag' and version='$version_input': tag rebuilds an existing tag, version mints a new one — pass one" >&2 exit 1 fi if [ -n "$input_tag" ]; then code=$(api_curl -o /tmp/tag.json -w '%{http_code}' \ "$REPO_API/tags/$input_tag") if [ "$code" != "200" ]; then echo "dispatch tag $input_tag not found (HTTP $code)" >&2 cat /tmp/tag.json >&2 || true exit 1 fi sha=$(python3 -c "import json; print(json.load(open('/tmp/tag.json'))['commit']['sha'])") tag="$input_tag" created=false echo "re-publish existing tag $tag at $sha (dry_run=$dry_run)" else if [ -n "$version_input" ]; then tag=$(python3 -c "import re,sys; m=re.fullmatch(r'v?([0-9]+)\.([0-9]+)\.([0-9]+)', sys.argv[1].strip()); print('v' + '.'.join(m.groups()) if m else '')" "$version_input") if [ -z "$tag" ]; then echo "version must be MAJOR.MINOR.PATCH or vMAJOR.MINOR.PATCH, got '$version_input'" >&2 exit 1 fi else case "$bump" in patch|minor|major) ;; *) echo "bump must be patch|minor|major, got '$bump'" >&2; exit 1 ;; esac api_curl "$REPO_API/tags?limit=50" -o /tmp/tags.json latest=$(python3 -c "import json,re; tags=json.load(open('/tmp/tags.json')); assert isinstance(tags, list), tags; s=[tuple(int(x) for x in m.groups()) for t in tags for m in [re.fullmatch(r'v([0-9]+)\.([0-9]+)\.([0-9]+)', t.get('name') or '')] if m]; print('%d.%d.%d' % max(s) if s else '')") if [ -z "$latest" ]; then tag="v0.1.0" else major="${latest%%.*}" rest="${latest#*.}" minor="${rest%%.*}" patch="${rest#*.}" case "$bump" in major) tag="v$((major + 1)).0.0" ;; minor) tag="v$major.$((minor + 1)).0" ;; patch) tag="v$major.$minor.$((patch + 1))" ;; esac fi fi sha="$EVENT_SHA" created=false if [ "$dry_run" = "true" ]; then echo "dry_run: would use $tag on $sha (no tag created)" else code=$(api_curl -o /tmp/tag.json -w '%{http_code}' \ "$REPO_API/tags/$tag") if [ "$code" = "200" ]; then existing=$(python3 -c "import json; print(json.load(open('/tmp/tag.json'))['commit']['sha'])") if [ "$existing" != "$sha" ]; then echo "tag $tag exists on $existing, not moving from $sha" >&2 exit 1 fi echo "tag $tag already exists on $sha — joining" elif [ "$code" = "404" ]; then python3 -c "import json,sys; json.dump({'tag_name':sys.argv[1],'target':sys.argv[2],'message':'OnionWire '+sys.argv[1]}, sys.stdout)" \ "$tag" "$sha" > /tmp/tag-create.json echo "tag-create payload $(wc -c < /tmp/tag-create.json) bytes" create_code=$(api_curl -o /tmp/tag-created.json -w '%{http_code}' \ -X POST -H "Content-Type: application/json" \ --data-binary @/tmp/tag-create.json \ "$REPO_API/tags") if [ "$create_code" = "201" ]; then created=true echo "created tag $tag on $sha" elif [ "$create_code" = "409" ]; then echo "tag $tag created concurrently — joining" else echo "creating tag $tag failed HTTP $create_code" >&2 cat /tmp/tag-created.json >&2 || true exit 1 fi else echo "GET tags/$tag failed HTTP $code" >&2 cat /tmp/tag.json >&2 || true exit 1 fi fi fi echo "tag=$tag" >> "$GITHUB_OUTPUT" echo "sha=$sha" >> "$GITHUB_OUTPUT" echo "dry_run=$dry_run" >> "$GITHUB_OUTPUT" echo "created_tag=$created" >> "$GITHUB_OUTPUT" echo "plan: tag=$tag sha=$sha dry_run=$dry_run created_tag=$created" aarch64: needs: version runs-on: docker timeout-minutes: 120 env: TARGET: aarch64-unknown-linux-gnu CARGO_TARGET_VOLUME: onionwire-target-aarch64 BUILD_CONTAINER: onionwire-release-${{ github.run_id }}-aarch64 steps: - name: Checkout source uses: https://code.forgejo.org/actions/checkout@v4 with: ref: ${{ needs.version.outputs.sha }} - name: Show runner arch run: uname -m && echo "target=$TARGET" - name: Build ${{ env.TARGET }} in a rust container run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" echo "workspace: $GITHUB_WORKSPACE" docker volume create "$CARGO_REGISTRY_VOLUME" > /dev/null docker volume create "$CARGO_TARGET_VOLUME" > /dev/null docker rm -f "$BUILD_CONTAINER" > /dev/null 2>&1 || true docker create --name "$BUILD_CONTAINER" -i \ -e CARGO_TARGET_DIR=/target \ -e CARGO_BUILD_JOBS=2 \ -e CARGO_TERM_COLOR=never \ -v "$CARGO_REGISTRY_VOLUME":/usr/local/cargo/registry \ -v "$CARGO_TARGET_VOLUME":/target \ -w /src \ "$RUST_IMAGE" \ sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ && 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' tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees \ --exclude=./.ci-tools . \ | docker start -a -i "$BUILD_CONTAINER" mkdir -p dist docker cp "$BUILD_CONTAINER:/target/release/onionwire" "dist/onionwire-$TARGET" docker rm -f "$BUILD_CONTAINER" > /dev/null - name: Pack and checksum run: | set -euo pipefail cd "${GITHUB_WORKSPACE}/dist" bytes=$(wc -c < "onionwire-$TARGET") if [ "$bytes" -eq 0 ]; then echo "refusing empty binary onionwire-$TARGET" >&2 exit 1 fi file "onionwire-$TARGET" sha256sum "onionwire-$TARGET" > "onionwire-$TARGET.sha256" sha256sum -c "onionwire-$TARGET.sha256" ls -l - name: Upload dist artifact uses: https://code.forgejo.org/actions/upload-artifact@v3 with: name: onionwire-aarch64-unknown-linux-gnu path: dist/ if-no-files-found: error retention-days: 1 x86_64: needs: version runs-on: docker-amd64 timeout-minutes: 120 env: TARGET: x86_64-unknown-linux-gnu CARGO_TARGET_VOLUME: onionwire-target-x86_64 BUILD_CONTAINER: onionwire-release-${{ github.run_id }}-x86_64 steps: - name: Checkout source uses: https://code.forgejo.org/actions/checkout@v4 with: ref: ${{ needs.version.outputs.sha }} - 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 cd "${GITHUB_WORKSPACE}" echo "workspace: $GITHUB_WORKSPACE" docker volume create "$CARGO_REGISTRY_VOLUME" > /dev/null docker volume create "$CARGO_TARGET_VOLUME" > /dev/null docker rm -f "$BUILD_CONTAINER" > /dev/null 2>&1 || true docker create --name "$BUILD_CONTAINER" -i \ -e CARGO_TARGET_DIR=/target \ -e CARGO_BUILD_JOBS=2 \ -e CARGO_TERM_COLOR=never \ -v "$CARGO_REGISTRY_VOLUME":/usr/local/cargo/registry \ -v "$CARGO_TARGET_VOLUME":/target \ -w /src \ "$RUST_IMAGE" \ sh -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src \ && 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' tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees \ --exclude=./.ci-tools . \ | docker start -a -i "$BUILD_CONTAINER" mkdir -p dist docker cp "$BUILD_CONTAINER:/target/release/onionwire" "dist/onionwire-$TARGET" docker rm -f "$BUILD_CONTAINER" > /dev/null - name: Pack and checksum run: | set -euo pipefail cd "${GITHUB_WORKSPACE}/dist" bytes=$(wc -c < "onionwire-$TARGET") if [ "$bytes" -eq 0 ]; then echo "refusing empty binary onionwire-$TARGET" >&2 exit 1 fi file "onionwire-$TARGET" sha256sum "onionwire-$TARGET" > "onionwire-$TARGET.sha256" sha256sum -c "onionwire-$TARGET.sha256" ls -l - name: Upload dist artifact uses: https://code.forgejo.org/actions/upload-artifact@v3 with: name: onionwire-x86_64-unknown-linux-gnu path: dist/ if-no-files-found: error retention-days: 1 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. 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 }} TAG: ${{ needs.version.outputs.tag }} run: | set -euo pipefail mkdir -p dist find artifacts -type f -print for target in aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu; do src=$(find artifacts -type f -name "onionwire-$target" -print -quit) sum=$(find artifacts -type f -name "onionwire-$target.sha256" -print -quit) if [ -z "$src" ] || [ -z "$sum" ]; then echo "missing artifact for $target" >&2 find artifacts -type f >&2 || true exit 1 fi cp "$src" "dist/onionwire-$target" cp "$sum" "dist/onionwire-$target.sha256" done missing=0 for f in \ dist/onionwire-aarch64-unknown-linux-gnu \ dist/onionwire-aarch64-unknown-linux-gnu.sha256 \ dist/onionwire-x86_64-unknown-linux-gnu \ dist/onionwire-x86_64-unknown-linux-gnu.sha256 do bytes=$(wc -c < "$f") echo "on disk: $f $bytes bytes" if [ "$bytes" -eq 0 ]; then echo "refusing empty asset $f" >&2 missing=1 fi file "$f" || true done if [ "$missing" -ne 0 ]; then exit 1 fi echo "publishing $TAG from $REPO_API" .ci-tools/scripts/publish-release.sh \ "$TAG" "OnionWire $TAG" \ .ci-tools/scripts/release-body.md \ dist/onionwire-aarch64-unknown-linux-gnu \ dist/onionwire-aarch64-unknown-linux-gnu.sha256 \ 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' 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}' \ -u "sirius:${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 \ -u "sirius:${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 \ -u "sirius:${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