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
90 changes: 90 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ After install, use the `codexm` command.
## Commands

```bash
codexm --version
codexm current
codexm list [name]
codexm save <name>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 <name> [--force] [--json]
Expand Down Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();

Expand Down
Loading