diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f677dd9..fff9733 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -103,6 +103,8 @@ jobs: test -f bin/gh-attach-darwin-arm64 test -f bin/gh-attach-windows-amd64.exe - run: npm test + env: + GH_ATTACH_BUILD_VERSION: ${{ needs.next-version.outputs.version }} - name: Release run: npx semantic-release env: diff --git a/test/e2e/binary.test.ts b/test/e2e/binary.test.ts index 3346262..8abffb8 100644 --- a/test/e2e/binary.test.ts +++ b/test/e2e/binary.test.ts @@ -20,6 +20,9 @@ const ROOT = resolve(import.meta.dirname, "../.."); const CJS_PATH = resolve(ROOT, "dist/cli-pkg.cjs"); const BIN_PATH = resolve(ROOT, "bin/gh-attach-linux-amd64"); const TEST_IMAGE_PATH = join(import.meta.dirname, "../fixtures/test-image.png"); +const EXPECTED_VERSION = + process.env.GH_ATTACH_BUILD_VERSION ?? + JSON.parse(readFileSync(resolve(ROOT, "package.json"), "utf8")).version; const GITHUB_TOKEN = process.env.GITHUB_TOKEN; const E2E_TEST_REPO = process.env.E2E_TEST_REPO; @@ -67,10 +70,7 @@ describe("Binary Distribution E2E", () => { const output = execSync(`${BIN_PATH} --version`, { encoding: "utf8", }).trim(); - const pkgVersion = JSON.parse( - readFileSync(resolve(ROOT, "package.json"), "utf8"), - ).version; - expect(output).toBe(pkgVersion); + expect(output).toBe(EXPECTED_VERSION); }); it("uploads a file via release-asset strategy", () => { diff --git a/test/integration/cli/binary.test.ts b/test/integration/cli/binary.test.ts index 1546063..bebc6cc 100644 --- a/test/integration/cli/binary.test.ts +++ b/test/integration/cli/binary.test.ts @@ -6,6 +6,9 @@ import { resolve } from "path"; const ROOT = resolve(import.meta.dirname, "../../.."); const CJS_PATH = resolve(ROOT, "dist/cli-pkg.cjs"); const ESM_PATH = resolve(ROOT, "dist/cli.js"); +const EXPECTED_VERSION = + process.env.GH_ATTACH_BUILD_VERSION ?? + JSON.parse(readFileSync(resolve(ROOT, "package.json"), "utf8")).version; /** * Runs the CJS bundle with given arguments and returns stdout. @@ -30,12 +33,9 @@ describe("CJS Bundle (pkg target)", () => { expect(firstLines).not.toMatch(/^import\s+\{/m); }); - it("should output version matching package.json", () => { - const pkgVersion = JSON.parse( - readFileSync(resolve(ROOT, "package.json"), "utf8"), - ).version; + it("should output version matching the build version", () => { const output = runCjs("--version"); - expect(output).toBe(pkgVersion); + expect(output).toBe(EXPECTED_VERSION); }); it("should display help text", () => { @@ -90,10 +90,7 @@ describe("Binary Artifacts", () => { const output = execSync(`${binPath} --version`, { encoding: "utf8", }).trim(); - const pkgVersion = JSON.parse( - readFileSync(resolve(ROOT, "package.json"), "utf8"), - ).version; - expect(output).toBe(pkgVersion); + expect(output).toBe(EXPECTED_VERSION); }); it("should produce Linux binary that can display help", () => { diff --git a/test/integration/cli/ghExtension.test.ts b/test/integration/cli/ghExtension.test.ts index 3f81ec1..ce126a2 100644 --- a/test/integration/cli/ghExtension.test.ts +++ b/test/integration/cli/ghExtension.test.ts @@ -11,6 +11,8 @@ const PACKAGE_JSON = JSON.parse( ) as { version: string; }; +const EXPECTED_VERSION = + process.env.GH_ATTACH_BUILD_VERSION ?? PACKAGE_JSON.version; const HAS_GH = spawnSync("gh", ["--version"], { encoding: "utf8", @@ -77,7 +79,7 @@ describe("GitHub CLI extension integration", () => { runGh(["extension", "install", "."], { cwd: ROOT, env }); expect(runGh(["attach", "--version"], { cwd: ROOT, env })).toBe( - PACKAGE_JSON.version, + EXPECTED_VERSION, ); expect(runGh(["attach", "--help"], { cwd: ROOT, env })).toContain( "upload",