diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bcabe1d..5779a3d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,8 +31,6 @@ jobs: - run: pnpm test - - run: pnpm build - - name: Bump patch version run: | git config user.name "github-actions[bot]" @@ -43,6 +41,8 @@ jobs: git commit -m "chore: bump version to $VERSION [skip ci]" git push + - run: pnpm build + - name: Publish to npm run: pnpm publish --no-git-checks env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f62e8ca..a2df4b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,6 @@ jobs: - run: pnpm install --frozen-lockfile - - run: pnpm test - - run: pnpm build + + - run: pnpm test diff --git a/__tests__/bin.test.ts b/__tests__/bin.test.ts new file mode 100644 index 0000000..aa1c0ea --- /dev/null +++ b/__tests__/bin.test.ts @@ -0,0 +1,20 @@ +import { describe, it, expect } from "vitest"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; +import { execFileSync } from "node:child_process"; + +describe("CLI version", () => { + it("reports the version from package.json", () => { + const pkg = JSON.parse( + readFileSync(join(__dirname, "..", "package.json"), "utf-8"), + ); + + const output = execFileSync( + "node", + [join(__dirname, "..", "dist", "bin.cjs"), "--version"], + { encoding: "utf-8" }, + ).trim(); + + expect(output).toBe(pkg.version); + }); +}); diff --git a/src/bin.ts b/src/bin.ts index 88057fb..0312632 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -1,3 +1,5 @@ +import { readFileSync } from "node:fs"; +import { join } from "node:path"; import { Command } from "commander"; import { whoamiCommand } from "./commands/whoami.js"; import { artistsCommand } from "./commands/artists.js"; @@ -6,12 +8,15 @@ import { sandboxesCommand } from "./commands/sandboxes.js"; import { notificationsCommand } from "./commands/notifications.js"; import { orgsCommand } from "./commands/orgs.js"; +const pkgPath = join(__dirname, "..", "package.json"); +const { version } = JSON.parse(readFileSync(pkgPath, "utf-8")); + const program = new Command(); program .name("recoup") .description("Recoup platform CLI") - .version("0.1.0"); + .version(version); program.addCommand(whoamiCommand); program.addCommand(artistsCommand);