From 10028c4abb0c5010a9aae5828c2f43841b849a23 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Wed, 4 Nov 2026 00:49:59 +0000 Subject: [PATCH] Use the host target for source-built release tools --- cmd/releasekit/woodpecker_test.go | 5 +++++ docs/release.md | 14 ++++++++++---- docs/roadmap/implementation.md | 2 ++ examples/woodpecker/releasekit-source-delivery.yml | 3 +++ scripts/release | 3 +++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cmd/releasekit/woodpecker_test.go b/cmd/releasekit/woodpecker_test.go index 5cb28f3..fbbe2da 100644 --- a/cmd/releasekit/woodpecker_test.go +++ b/cmd/releasekit/woodpecker_test.go @@ -321,6 +321,7 @@ func TestWoodpeckerSourceDeliveryTemplateSelfBootstraps(t *testing.T) { commit := pushTaggedCLIRepository(t, repository) goDir, goLog := installGoBootstrapShim(t) env := templateEnvironment(repository, commit, goDir, goLog) + env["GOOS"], env["GOARCH"] = foreignTarget() useSyntheticModuleProxy(t, env, proxy.URL) proxyRequests.Store(0) env["CI_COMMIT_SHA"] = strings.Repeat("0", len(commit)) @@ -343,6 +344,9 @@ func TestWoodpeckerSourceDeliveryTemplateSelfBootstraps(t *testing.T) { t.Fatalf("self-bootstrapped command arguments = %q", output) } log := readWoodpeckerFixtureFile(t, goLog) + if !strings.Contains(log, "build-target="+runtime.GOOS+"/"+runtime.GOARCH) { + t.Fatalf("source build did not use host target: %s", log) + } if !strings.Contains(log, "GOWORK=off GOTOOLCHAIN=local") || !strings.Contains(log, "build -mod=readonly -o ") || !strings.Contains(log, "./cmd/releasekit") { t.Fatalf("self-bootstrap Go command = %q", log) } @@ -427,6 +431,7 @@ func installGoBootstrapShim(t *testing.T) (string, string) { shim := `#!/bin/sh printf 'cwd=%s GOWORK=%s GOTOOLCHAIN=%s %s\n' "$PWD" "$GOWORK" "$GOTOOLCHAIN" "$*" >> "$RELEASEKIT_GO_LOG" case " $* " in *" -deps "*) printf 'target=%s/%s\n' "$GOOS" "$GOARCH" >> "$RELEASEKIT_GO_LOG" ;; esac +if [ "$1" = build ]; then printf 'build-target=%s/%s\n' "$GOOS" "$GOARCH" >> "$RELEASEKIT_GO_LOG"; fi "$RELEASEKIT_REAL_GO" "$@" status=$? if [ "$status" -eq 0 ] && [ "$1" = "tool" ] && [ -n "${RELEASEKIT_SUM_LOG:-}" ]; then diff --git a/docs/release.md b/docs/release.md index cfa97d3..ac61d4b 100644 --- a/docs/release.md +++ b/docs/release.md @@ -193,10 +193,16 @@ immutable version from its tag: ```sh git fetch origin "refs/tags/vX.Y.Z:refs/tags/vX.Y.Z" git checkout --detach "vX.Y.Z" -GOTOOLCHAIN=local go mod download -mkdir -p .releasekit/bin -GOTOOLCHAIN=local GOPROXY=off GOSUMDB=off go build -o .releasekit/bin/releasekit ./cmd/releasekit -.releasekit/bin/releasekit deliver "vX.Y.Z" +( + set -e + releasekit_host_os=$(GOTOOLCHAIN=local go env GOHOSTOS) + releasekit_host_arch=$(GOTOOLCHAIN=local go env GOHOSTARCH) + export GOOS="$releasekit_host_os" GOARCH="$releasekit_host_arch" + GOTOOLCHAIN=local go mod download + mkdir -p .releasekit/bin + GOTOOLCHAIN=local GOPROXY=off GOSUMDB=off go build -o .releasekit/bin/releasekit ./cmd/releasekit + .releasekit/bin/releasekit deliver "vX.Y.Z" +) ``` For an older tag whose CLI predates `token_file`, supply the token through its diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 67d1fa6..647c1b5 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -70,6 +70,8 @@ checks in Stage 6. ## Stage 3: Normalize source-built launchers +**Completed.** + 1. Apply the same recipe in the [maintainer launcher](../../scripts/release) before building and executing ReleaseKit. Prefix the two queries with `GOTOOLCHAIN=local` to match its existing build. Preserve usage checking, diff --git a/examples/woodpecker/releasekit-source-delivery.yml b/examples/woodpecker/releasekit-source-delivery.yml index 908c638..8b834dc 100644 --- a/examples/woodpecker/releasekit-source-delivery.yml +++ b/examples/woodpecker/releasekit-source-delivery.yml @@ -30,6 +30,9 @@ steps: trap 'rm -rf "$${bootstrap_dir}"' EXIT export GOWORK=off export GOTOOLCHAIN=local + releasekit_host_os=$(go env GOHOSTOS) || exit $? + releasekit_host_arch=$(go env GOHOSTARCH) || exit $? + export GOOS="$${releasekit_host_os}" GOARCH="$${releasekit_host_arch}" go build -mod=readonly -o "$${bootstrap_dir}/releasekit" ./cmd/releasekit "$${bootstrap_dir}/releasekit" ci-deliver \ --repo "$${CI_WORKSPACE}" \ diff --git a/scripts/release b/scripts/release index 7286be1..0a6cff9 100755 --- a/scripts/release +++ b/scripts/release @@ -6,6 +6,9 @@ if [ "$#" -ne 1 ]; then exit 2 fi +releasekit_host_os=$(GOTOOLCHAIN=local go env GOHOSTOS) || exit $? +releasekit_host_arch=$(GOTOOLCHAIN=local go env GOHOSTARCH) || exit $? +export GOOS="$releasekit_host_os" GOARCH="$releasekit_host_arch" mkdir -p .releasekit/bin GOTOOLCHAIN=local go build -o .releasekit/bin/releasekit ./cmd/releasekit exec .releasekit/bin/releasekit publish "$1"