Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ jobs:
- run: npm ci
- run: npm run build

release-parity:
name: Release parity
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run build
env:
GH_ATTACH_BUILD_VERSION: 9.9.9
- run: npm test
env:
GH_ATTACH_BUILD_VERSION: 9.9.9

test:
name: Test (Node ${{ matrix.node }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
Expand Down
16 changes: 14 additions & 2 deletions src/core/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ export const DEVELOPMENT_VERSION = "0.0.0-development";

const MAX_PACKAGE_SEARCH_DEPTH = 3;

function readInjectedBuildVersion(): string | undefined {
const version =
process.env.__PKG_VERSION__ ?? process.env.GH_ATTACH_BUILD_VERSION;

if (typeof version === "string" && version.length > 0) {
return version;
}

return undefined;
}

function readPackageVersion(pkgPath: string): string | undefined {
if (!existsSync(pkgPath)) {
return undefined;
Expand Down Expand Up @@ -36,8 +47,9 @@ export function resolvePackageVersion(
moduleUrl: string,
fallback = DEVELOPMENT_VERSION,
): string {
if (process.env.__PKG_VERSION__) {
return process.env.__PKG_VERSION__;
const injectedBuildVersion = readInjectedBuildVersion();
if (injectedBuildVersion) {
return injectedBuildVersion;
}

try {
Expand Down
23 changes: 23 additions & 0 deletions test/unit/core/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("resolvePackageVersion", () => {

beforeEach(() => {
delete process.env.__PKG_VERSION__;
delete process.env.GH_ATTACH_BUILD_VERSION;

tempRoot = mkdtempSync(join(tmpdir(), "gh-attach-version-"));
writeFileSync(
Expand All @@ -25,6 +26,7 @@ describe("resolvePackageVersion", () => {

afterEach(() => {
delete process.env.__PKG_VERSION__;
delete process.env.GH_ATTACH_BUILD_VERSION;
rmSync(tempRoot, { recursive: true, force: true });
});

Expand Down Expand Up @@ -54,6 +56,27 @@ describe("resolvePackageVersion", () => {
expect(version).toBe("2.3.4");
});

it("uses the release build version during source-driven runs", () => {
process.env.GH_ATTACH_BUILD_VERSION = "3.4.5";

const version = resolvePackageVersion(
pathToFileURL(join(tempRoot, "src", "mcp", "index.ts")).href,
);

expect(version).toBe("3.4.5");
});

it("prefers the bundled build version over the runtime release override", () => {
process.env.__PKG_VERSION__ = "2.3.4";
process.env.GH_ATTACH_BUILD_VERSION = "3.4.5";

const version = resolvePackageVersion(
pathToFileURL(join(tempRoot, "dist", "mcp.js")).href,
);

expect(version).toBe("2.3.4");
});

it("falls back to the development version when package metadata is missing", () => {
const orphanRoot = mkdtempSync(
join(tmpdir(), "gh-attach-version-missing-"),
Expand Down