diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a17c0b..7b2923a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,9 @@ jobs: - name: Production build run: pnpm build + - name: Build and inspect npm CLI package + run: pnpm test:npm-cli + - name: Self-test GitHub Action uses: ./ with: diff --git a/.github/workflows/publish-npm-cli.yml b/.github/workflows/publish-npm-cli.yml new file mode 100644 index 0000000..6a59f50 --- /dev/null +++ b/.github/workflows/publish-npm-cli.yml @@ -0,0 +1,57 @@ +name: Publish npm CLI + +on: + workflow_dispatch: + inputs: + version: + description: "Semantic version to publish, for example 1.2.0" + required: true + type: string + +permissions: + contents: read + id-token: write + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Validate version + shell: bash + run: | + VERSION="${{ inputs.version }}" + [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { + echo "Version must be x.y.z" + exit 1 + } + + - name: Checkout matching release tag + uses: actions/checkout@v6 + with: + ref: v${{ inputs.version }} + + - name: Set up Node.js + uses: actions/setup-node@v6 + with: + node-version: "24" + registry-url: "https://registry.npmjs.org" + package-manager-cache: false + + - name: Enable Corepack + run: corepack enable + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build CLI package + env: + CLI_PACKAGE_VERSION: ${{ inputs.version }} + run: pnpm build:npm-cli + + - name: Verify package + run: | + node dist/npm/cli/index.mjs --help + npm pack --dry-run ./dist/npm + + - name: Publish with npm trusted publishing + run: npm publish ./dist/npm --access public diff --git a/README.md b/README.md index 0c2e970..cc6613b 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,14 @@ For private owned repositories, create a user-owned fine-grained token with only ### Local CLI +Once the npm package is published, run without installing: + +```bash +npx code-life-balance --username octocat --timezone Europe/Helsinki +``` + +For repository development, or before the npm package is published, use `pnpm cli --`. + Authenticate with GitHub CLI: ```bash @@ -197,6 +205,8 @@ Open [http://localhost:3000](http://localhost:3000) and click **Analyze my GitHu | `pnpm typecheck` | Run strict TypeScript validation. | | `pnpm check` | Run tests, typecheck, and production build. | | `pnpm cli -- --help` | Show local CLI options. | +| `pnpm build:npm-cli` | Build the dependency-free npm CLI package into `dist/npm`. | +| `pnpm test:npm-cli` | Build, execute, and dry-run-pack the npm CLI artifact. | ## Deployment diff --git a/cli/index.mjs b/cli/index.mjs index 18f3a58..5cd0384 100644 --- a/cli/index.mjs +++ b/cli/index.mjs @@ -32,7 +32,7 @@ Options: Credentials: 1. GITHUB_TOKEN environment variable, if set. - 2. Otherwise `gh auth token`, unless --no-gh is passed. + 2. Otherwise gh auth token, unless --no-gh is passed. 3. Public analysis can run without a token when --username is provided. No credential or report is sent to CodeLifeBalance infrastructure. diff --git a/docs/npm-cli-readme.md b/docs/npm-cli-readme.md new file mode 100644 index 0000000..7f33e6f --- /dev/null +++ b/docs/npm-cli-readme.md @@ -0,0 +1,62 @@ +# Code Life Balance CLI + +Run Code Life Balance locally without sending your GitHub credential or generated report to Code Life Balance infrastructure. + +## Run without installing + +```bash +npx code-life-balance --username octocat --timezone Europe/Helsinki +``` + +Or install globally: + +```bash +npm install --global code-life-balance +code-life-balance --username octocat +``` + +## Authentication + +The CLI resolves credentials in this order: + +1. `GITHUB_TOKEN`, when present. +2. Your existing `gh auth token` session. +3. No token for public-only username analysis. + +For private owned-repository analysis: + +```bash +gh auth login +code-life-balance --include-private --timezone Europe/Helsinki +``` + +Private mode verifies that the authenticated token owner matches the username being analyzed. + +## Options + +```text +--username GitHub username +--timezone IANA timezone, default UTC +--workday-start <0-23> Workday start hour, default 9 +--workday-end <1-24> Workday end hour, default 18 +--output-dir Output directory +--theme SVG theme +--card-style