#!/usr/bin/env bash # Offline fallback: build and publish the x86_64 release asset from this host # when CI (.forgejo/workflows/release.yml) cannot be used. # # Usage: MINISIGN_SECRET_KEY=... FORGEJO_TOKEN=... scripts/build-release-local.sh v0.5.0 # # It runs the SAME recipe CI runs, inside the same digest-pinned builder image, # so the asset it publishes is one a verifier can reproduce. A plain host # `cargo build` would not be: different rustc, different build paths, different # bytes — and the published hash would then match nothing anyone could rebuild, # which is worse than having no fallback at all. # # Does not create or push the tag: the release workflow owns tagging. Idempotent # (same-named assets are replaced). Never moves an existing tag. set -euo pipefail tag="${1:?usage: build-release-local.sh }" target=x86_64-unknown-linux-gnu root="$(cd "$(dirname "$0")/.." && pwd)" cd "$root" # Must equal RUST_IMAGE in .forgejo/workflows/release.yml and BUILDER_IMAGE in # scripts/verify-reproducible.sh. Three copies, one digest — see docs/VERIFY.md. BUILDER_IMAGE="rust@sha256:93ce27a88655056a51dbdd8f5f2d7ddc071c7b0070fb288a37b5a285fc83971e" command -v docker >/dev/null 2>&1 || { echo "build-release-local: docker is required (the build runs in the pinned image)" >&2 exit 1 } expected="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)" if [ "$tag" != "v$expected" ]; then echo "warn: tag $tag does not match Cargo.toml version $expected (--version will report $expected)" fi sha="$(git rev-parse --verify "$tag^{commit}" 2>/dev/null)" || { echo "build-release-local: tag $tag not found — run: git fetch --tags" >&2 exit 1 } sde="$(git log -1 --format=%ct "$sha")" echo "==> $tag at $sha, SOURCE_DATE_EPOCH=$sde" work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT mkdir -p "$work/src" "$work/out" "$work/target" git archive "$sha" | tar -x -C "$work/src" docker volume create onionwire-local-registry >/dev/null docker run --rm \ -v "$work/src:/src:ro" \ -v onionwire-local-registry:/usr/local/cargo/registry \ -v "$work/target:/target" \ -v "$work/out:/out" \ -e SOURCE_DATE_EPOCH="$sde" \ -e BUILDER_IMAGE="$BUILDER_IMAGE" \ -e TARGET_TRIPLE="$target" \ -e GIT_SHA="$sha" \ -w /src \ "$BUILDER_IMAGE" \ bash scripts/reproducible-build.sh mkdir -p dist cp "$work/out/onionwire-$target" \ "$work/out/onionwire-$target.sha256" \ "$work/out/build-info-$target.txt" \ dist/ file "dist/onionwire-$target" "dist/onionwire-$target" --version echo "==> signing (needs minisign on PATH and the committed public key)" RELEASE_TAG="$tag" scripts/sign-release.sh \ "dist/onionwire-$target" "dist/onionwire-$target.sha256" echo "==> publishing to the release for $tag" scripts/publish-release.sh "$tag" "OnionWire $tag" scripts/release-body.md \ "dist/onionwire-$target" \ "dist/onionwire-$target.sha256" \ "dist/onionwire-$target.minisig" \ "dist/onionwire-$target.sha256.minisig" \ "dist/build-info-$target.txt"