From 784b12a1d622d4692bb11dca3bb5c6dfa20edd60 Mon Sep 17 00:00:00 2001 From: mattpeng Date: Mon, 23 Mar 2026 15:48:34 +0800 Subject: [PATCH 1/3] feat: add version flag and release workflow --- .github/workflows/release.yml | 90 +++++++++++++++++++++++++++++++++++ README.md | 19 ++++++++ src/main.ts | 8 ++++ tests/cli.test.ts | 29 +++++++++++ 4 files changed, 146 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3144bb3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,90 @@ +name: Release + +on: + pull_request: + branches: + - master + push: + branches: + - master + tags: + - "v*" + workflow_dispatch: + +permissions: + contents: read + +env: + NODE_VERSION: "20" + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + +jobs: + verify: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: pnpm + registry-url: https://registry.npmjs.org + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run tests + run: pnpm test + + - name: Run typecheck + run: pnpm typecheck + + - name: Build package + run: pnpm build + + publish: + needs: verify + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: pnpm + registry-url: https://registry.npmjs.org + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Verify tag matches package version + run: | + PACKAGE_VERSION="$(node -p "require('./package.json').version")" + TAG_VERSION="${GITHUB_REF_NAME#v}" + + if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then + echo "Tag version $TAG_VERSION does not match package.json version $PACKAGE_VERSION" + exit 1 + fi + + - name: Publish to npm + run: pnpm publish --no-git-checks + env: + NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} diff --git a/README.md b/README.md index 64343f0..c61e705 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ After install, use the `codexm` command. ## Commands ```bash +codexm --version codexm current codexm list [name] codexm save @@ -29,6 +30,24 @@ codexm doctor Use `--json` on query and mutation commands when you need machine-readable output. +## CI And Release + +GitHub Actions will run tests, typecheck, and build on pushes to `master`, pull requests targeting `master`, and manual runs. + +Publishing to npm happens automatically when you push a tag like `v0.0.5`, as long as the tag matches the `package.json` version. + +Before enabling auto publish, add an Actions secret named `NPM_TOKEN` with your npm publish token. + +```bash +git switch master +git pull --ff-only +npm version 0.0.5 --no-git-tag-version +git commit -am "chore: bump version to 0.0.5" +git push origin master +git tag v0.0.5 +git push origin v0.0.5 +``` + ## Typical flow 1. Log into a target account with the native Codex CLI. diff --git a/src/main.ts b/src/main.ts index 0fc1f92..2db5423 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,6 +2,7 @@ import { stdin as defaultStdin, stdout as defaultStdout, stderr as defaultStderr import dayjs from "dayjs"; import timezone from "dayjs/plugin/timezone.js"; import utc from "dayjs/plugin/utc.js"; +import packageJson from "../package.json"; import { maskAccountId } from "./auth-snapshot.js"; import { @@ -98,6 +99,8 @@ function printHelp(stream: NodeJS.WriteStream): void { stream.write(`codexm - manage multiple Codex ChatGPT auth snapshots Usage: + codexm --version + codexm --help codexm current [--json] codexm list [name] [--json] codexm save [--force] [--json] @@ -449,6 +452,11 @@ export async function runCli( const json = parsed.flags.has("--json"); try { + if (parsed.flags.has("--version")) { + streams.stdout.write(`${packageJson.version}\n`); + return 0; + } + if (!parsed.command || parsed.flags.has("--help")) { printHelp(streams.stdout); return 0; diff --git a/tests/cli.test.ts b/tests/cli.test.ts index 2736261..c186548 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -4,6 +4,7 @@ import { describe, expect, test } from "@rstest/core"; import dayjs from "dayjs"; import timezone from "dayjs/plugin/timezone.js"; import utc from "dayjs/plugin/utc.js"; +import packageJson from "../package.json"; import { runCli } from "../src/main.js"; import { createAccountStore } from "../src/account-store.js"; @@ -70,6 +71,34 @@ function createInteractiveStdin(): NodeJS.ReadStream & { } describe("CLI", () => { + test("prints version from --version", async () => { + const stdout = captureWritable(); + const stderr = captureWritable(); + + const exitCode = await runCli(["--version"], { + stdout: stdout.stream, + stderr: stderr.stream, + }); + + expect(exitCode).toBe(0); + expect(stdout.read()).toBe(`${packageJson.version}\n`); + expect(stderr.read()).toBe(""); + }); + + test("includes version flag in help output", async () => { + const stdout = captureWritable(); + const stderr = captureWritable(); + + const exitCode = await runCli(["--help"], { + stdout: stdout.stream, + stderr: stderr.stream, + }); + + expect(exitCode).toBe(0); + expect(stdout.read()).toContain("codexm --version"); + expect(stderr.read()).toBe(""); + }); + test("supports save and current in json mode", async () => { const homeDir = await createTempHome(); From e6505c43b2e16027826fd704628f1d0c5443b13d Mon Sep 17 00:00:00 2001 From: mattpeng Date: Mon, 23 Mar 2026 15:49:34 +0800 Subject: [PATCH 2/3] chore: bump version to 0.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4547881..e7a9249 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codex-team", - "version": "0.0.4", + "version": "0.0.5", "description": "Manage multiple Codex ChatGPT auth snapshots and quota usage from the command line.", "license": "MIT", "type": "module", From cfaeb425422ea5ff36131747efa735c47ee1e655 Mon Sep 17 00:00:00 2001 From: mattpeng Date: Mon, 23 Mar 2026 15:57:22 +0800 Subject: [PATCH 3/3] docs: remove ci release section from readme --- README.md | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/README.md b/README.md index c61e705..86f284f 100644 --- a/README.md +++ b/README.md @@ -30,24 +30,6 @@ codexm doctor Use `--json` on query and mutation commands when you need machine-readable output. -## CI And Release - -GitHub Actions will run tests, typecheck, and build on pushes to `master`, pull requests targeting `master`, and manual runs. - -Publishing to npm happens automatically when you push a tag like `v0.0.5`, as long as the tag matches the `package.json` version. - -Before enabling auto publish, add an Actions secret named `NPM_TOKEN` with your npm publish token. - -```bash -git switch master -git pull --ff-only -npm version 0.0.5 --no-git-tag-version -git commit -am "chore: bump version to 0.0.5" -git push origin master -git tag v0.0.5 -git push origin v0.0.5 -``` - ## Typical flow 1. Log into a target account with the native Codex CLI.