diff --git a/packages/testkit/test/stack-tools.test.ts b/packages/testkit/test/stack-tools.test.ts index 721de48e..f449f9fa 100644 --- a/packages/testkit/test/stack-tools.test.ts +++ b/packages/testkit/test/stack-tools.test.ts @@ -15,6 +15,9 @@ const ROOT = resolve(fileURLToPath(import.meta.url), "../../../.."); const TOOLS = join(ROOT, "template/.gitea/peppa-tools.sh"); const TMP = mkdtempSync(join(tmpdir(), "peppa-stack-tools-")); const ARCH = ({ x64: "amd64", arm64: "arm64" } as Record)[process.arch] ?? process.arch; +// The archive the helper asks for is named after the host (`uname -s`): linux in the checks job and at the +// agent, darwin on a developer's Mac — the tests run on both. +const OS = process.platform === "darwin" ? "darwin" : "linux"; // The user has a passwd entry (mock getent finds it) — the sandbox running these tests may have none; // the case without one has its own describe below. const HAS_USER = mkdtempSync(join(TMP, "mock-getent-ok-")); @@ -30,13 +33,13 @@ function exe(path: string, body: string) { chmodSync(path, 0o755); } -/** A mock go.dev/dl: go.linux-.tar.gz with go/bin/go answering `go version`. */ +/** A mock go.dev/dl: go.-.tar.gz with go/bin/go answering `go version`. */ function mockGoDl(version: string): string { const dl = mkdtempSync(join(TMP, "mock-go-dl-")); const src = join(dl, "src"); mkdirSync(join(src, "go/bin"), { recursive: true }); exe(join(src, "go/bin/go"), `echo "go version go${version} linux/${ARCH}"`); - execFileSync("tar", ["-czf", join(dl, `go${version}.linux-${ARCH}.tar.gz`), "-C", src, "go"]); + execFileSync("tar", ["-czf", join(dl, `go${version}.${OS}-${ARCH}.tar.gz`), "-C", src, "go"]); return dl; } @@ -76,7 +79,7 @@ describe("Go для проверок", () => { const cache = join(work, "cache"); const r = source(["go"], { PEPPA_GO_DL_BASE: `file://${dl}`, PEPPA_TOOLS_CACHE: cache, GITHUB_PATH: ghPath }, work); assert.equal(r.code, 0, r.err); - assert.match(r.err, new RegExp(`скачиваю go1\\.27\\.0\\.linux-${ARCH}\\.tar\\.gz`)); + assert.match(r.err, new RegExp(`скачиваю go1\\.27\\.0\\.${OS}-${ARCH}\\.tar\\.gz`)); assert.equal(r.go, join(cache, "go/1.27.0/go/bin/go")); assert.equal(readFileSync(ghPath, "utf8").trim(), join(cache, "go/1.27.0/go/bin")); // the second call takes the cache, nothing is downloaded diff --git a/template/.gitea/peppa-tools.sh b/template/.gitea/peppa-tools.sh index db3654f2..4c3f0eb6 100755 --- a/template/.gitea/peppa-tools.sh +++ b/template/.gitea/peppa-tools.sh @@ -48,7 +48,10 @@ _peppa_go() { url="${PEPPA_GO_DL_BASE:-https://go.dev/dl}/$tgz" _peppa_say "скачиваю $tgz" mkdir -p "$dir" || return 1 - if ! curl -fsSL --retry 3 "$url" | tar -xz -C "$dir"; then + # Итог проверяется по самому файлу go: tar на macOS считает пустой поток пустым архивом и + # отвечает успехом, когда curl ничего не скачал. + curl -fsSL --retry 3 "$url" | tar -xz -C "$dir" + if [[ ! -x "$dir/go/bin/go" ]]; then _peppa_say "не удалось скачать Go $v ($url)" rm -rf "$dir" return 1