@jonmilner/local-ci 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +19 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -23,7 +23,7 @@ That writes `pre-push` and `commit-msg` shims, each one line that calls local-ci
23
23
  - `local-ci hooks install`: writes executable `#!/bin/sh` `pre-push` and `commit-msg` shims into the hooks directory: `core.hooksPath`, resolved against the repo root, with a Vite+ (or husky) `<dir>/_` dispatcher mapped to `<dir>`, and an absolute path into the main checkout mapped onto the current worktree. Each shim is one line: `pnpm exec local-ci pre-push "$@"` and `pnpm exec local-ci commit-msg "$1"` in a repo with a `package.json`, a global `local-ci …` without one, or `"local-ci": { "exec": "<command>" }` in `package.json` in place of `pnpm exec local-ci` (this repo runs local-ci from source that way). An existing shell hook keeps its other lines and gains the shim line, at the end, only when no line already runs `local-ci pre-push` (or `commit-msg`), so a line with an env prefix such as `LOCAL_CI_COMMAND=… local-ci pre-push "$@"` counts. It prints each file it wrote, or `hooks up to date`; a second run changes nothing. It exits 1 without `core.hooksPath` or with one outside the repo's tracked files (including `.git/hooks`), and for an existing hook in another language (a `node` or `python` shebang), naming the line to add by hand. Run it by hand and commit the result; `prepare` does not run it.
24
24
  - `local-ci pre-push`: the hook. It first checks that both hook files are in place, as `local-ci hooks install` would leave them, and refuses the push otherwise (``hooks out of date: <file> must run local-ci; run `<command> hooks install` and commit the result``), so a repo's hooks can't drift. For each commit pushed to a branch (deletes and tags are skipped) that has not already passed, runs the check command. The pushed commit must be `HEAD` with a clean working tree (`git status --porcelain` empty), so the result reflects the commit; otherwise the push is refused. A failing check blocks the push. When every commit passes, it starts `local-ci post <sha>` in the background, aimed at the pushed remote and told the pid of the `git` process doing the push (`LOCAL_CI_PUSH_PID`), and lets the push go ahead.
25
25
  - `local-ci commit-msg <file>`: lints the commit message in `<file>` with `@jonmilner/commitlint-config`, for a git `commit-msg` hook (git passes `.git/COMMIT_EDITMSG`). `local-ci commit-msg -` reads the message from stdin, for PR titles. Comment lines (starting with `#`) and everything after a `# ------------------------ >8 ------------------------` scissors line are stripped first; merge commits, `fixup!`/`squash!` and reverts are skipped. Each error or warning goes to stderr as `commit-msg: <message> [<rule>]`, followed by the offending header; it exits 1 when there are errors (warnings alone exit 0), and 2 when no file is given. It makes no network, git or GitHub calls.
26
- - `local-ci post <sha>`: when started by `pre-push`, first waits for the pushing `git` to exit (polling each second, up to 60 minutes, logging if it gives up), since git sends the push only after the whole hook exits, so a slow step after local-ci in the hook can't run out the clock; run by hand, it skips that wait. It then waits up to 3 minutes for GitHub to have the commit, posts status `check` = `success` (`<command> passed on <hostname>`), then posts `pr-title` on it for an open PR that contains it (waiting up to 30s for GitHub to link them). A PR opened after the push, or a retitled one, needs `local-ci pr-title` run by hand.
26
+ - `local-ci post <ref>`: resolves `<ref>` (a full or short sha, `HEAD`, a branch) to a local commit's full sha, failing with `<ref> is not a commit in this repo` when it names none, and with `<sha> has no passing check` when that commit never passed. When started by `pre-push`, first waits for the pushing `git` to exit (polling each second, up to 60 minutes, logging if it gives up), since git sends the push only after the whole hook exits, so a slow step after local-ci in the hook can't run out the clock; run by hand, it skips that wait. It then waits up to 3 minutes for GitHub to have the commit, posts status `check` = `success` (`<command> passed on <hostname>`), then posts `pr-title` on it for an open PR that contains it (waiting up to 30s for GitHub to link them). A PR opened after the push, or a retitled one, needs `local-ci pr-title` run by hand.
27
27
  - `local-ci pr-title [<pr>]`: lints the PR title (the current branch's PR by default) with `@jonmilner/commitlint-config` and posts status `pr-title` on its head commit, `failure` with the first error when the title does not pass.
28
28
  - `local-ci status [<sha>]`: posts `check` for a commit (default `HEAD`) that already passed, or runs the check first. When the check command fails, it posts `check` = `failure` (`<command> failed on <hostname>`) and exits non-zero; a later passing run posts `success` over it. A dirty tree, a commit that is not `HEAD`, or a `gh` error posts nothing. Use it after a push that skipped hooks (`--no-verify`) or a lost background poster.
29
29
  - `local-ci release`: publishes the repo's packages from this machine. Off unless `package.json` has `"local-ci": { "release": true }`; otherwise it prints `release not enabled` and exits 0. It needs a clean working tree, then fetches `origin` and takes a lock, so a second run exits with `release in progress`. In a temporary worktree at `origin`'s default branch:
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from "node:child_process";
2
+ import { spawn, spawnSync } from "node:child_process";
3
3
  import { closeSync, openSync, readFileSync } from "node:fs";
4
4
  import { hostname } from "node:os";
5
5
  import { basename, dirname, join, relative, resolve } from "node:path";
@@ -19,7 +19,7 @@ import { projectsDir, renovate } from "./renovate.js";
19
19
  import { lintTitle } from "./title.js";
20
20
  const USAGE = `Usage:
21
21
  local-ci pre-push run the check for each pushed commit (git pre-push hook)
22
- local-ci post <sha> wait for <sha> on GitHub, then post its check and pr-title statuses
22
+ local-ci post <ref> wait for <ref> on GitHub, then post its check and pr-title statuses
23
23
  local-ci pr-title [<pr>] lint the PR title and post the pr-title status
24
24
  local-ci commit-msg <file|->
25
25
  lint a commit message file (git commit-msg hook) or stdin (-)
@@ -32,6 +32,20 @@ const USAGE = `Usage:
32
32
  local-ci renovate --uninstall
33
33
  remove that agent`;
34
34
  const git = async (...args) => (await exec("git", args)).trim();
35
+ /** The full sha `ref` names, so a short sha or `HEAD` matches the full-sha pass records. */
36
+ function resolveCommit(ref) {
37
+ const result = spawnSync("git", ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`], {
38
+ encoding: "utf8",
39
+ });
40
+ if (result.status === 0)
41
+ return result.stdout.trim();
42
+ // `--quiet` keeps git silent only for a ref that names no commit; anything else (an ambiguous
43
+ // short sha, no repo, no git) keeps git's own message.
44
+ const stderr = result.stderr?.trim();
45
+ if (result.status === 1 && !stderr)
46
+ throw new Error(`${ref} is not a commit in this repo`);
47
+ throw new Error(`git rev-parse: ${stderr || result.error?.message || `exit ${result.status}`}`);
48
+ }
35
49
  async function repo() {
36
50
  const root = await git("rev-parse", "--show-toplevel");
37
51
  // The common dir names the repo even from a linked worktree.
@@ -222,7 +236,7 @@ async function postFailure(sha, command) {
222
236
  }
223
237
  }
224
238
  async function status(ref = "HEAD") {
225
- const sha = await git("rev-parse", "--verify", `${ref}^{commit}`);
239
+ const sha = resolveCommit(ref);
226
240
  const current = await repo();
227
241
  try {
228
242
  await runCheck(current, sha);
@@ -296,8 +310,8 @@ async function main([command, ...args]) {
296
310
  switch (command) {
297
311
  case "post":
298
312
  if (!args[0])
299
- throw new Error("post needs a commit SHA");
300
- return post(await repo(), args[0]);
313
+ throw new Error("post needs a commit SHA or ref");
314
+ return post(await repo(), resolveCommit(args[0]));
301
315
  case "pr-title":
302
316
  if (!(await prTitle(args[0])))
303
317
  process.exitCode = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jonmilner/local-ci",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Run a repo's check in a pre-push hook and post the result as GitHub commit statuses",
5
5
  "license": "MIT",
6
6
  "repository": {