@jonmilner/local-ci 0.3.3 → 0.3.4
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.
- package/README.md +1 -1
- package/dist/cli.js +12 -3
- package/dist/config.d.ts +9 -0
- package/dist/config.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,6 @@ A repo without a `package.json` sets `LOCAL_CI_COMMAND`, for example in the hook
|
|
|
42
42
|
|
|
43
43
|
## State
|
|
44
44
|
|
|
45
|
-
Logs, the record of passed commits and the release lock live in `~/.local/state/local-ci/<repo>.log`, `<repo>.passed` and `<repo>.release.lock` (`$XDG_STATE_HOME` if set). A lock whose process has died is taken over.
|
|
45
|
+
Logs, the record of passed commits and the release lock live in `~/.local/state/local-ci/<repo>.log`, `<repo>.passed` and `<repo>.release.lock` (`$XDG_STATE_HOME` if set). A lock whose process has died is taken over. Each check run appends its duration and outcome to the log when it ends, e.g. `[<end time>] abc1234: pnpm check passed in 71.2s` (or `failed in`, or `did not finish after` when the check is killed by a signal or can't start); a commit that already passed is skipped and logs nothing. Ctrl-C stops local-ci along with the check, so that run logs nothing.
|
|
46
46
|
|
|
47
47
|
Part of [jonmilner/config](https://github.com/jonmilner/config#readme).
|
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { closeSync, openSync, readFileSync } from "node:fs";
|
|
|
4
4
|
import { hostname } from "node:os";
|
|
5
5
|
import { basename, dirname, resolve } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { passedCommand, recordPass, releaseEnabled, resolveCommand, statePaths } from "./config.js";
|
|
7
|
+
import { appendLog, checkRunMessage, logLine, passedCommand, recordPass, releaseEnabled, resolveCommand, statePaths, } from "./config.js";
|
|
8
8
|
import { exec } from "./exec.js";
|
|
9
9
|
import { assertGhAuth, checkStatus, postStatus, prTitleStatus, viewPr, waitForCommit, waitForOpenPr, } from "./github.js";
|
|
10
10
|
import { cannotCheckInPlace, githubRepo, parsePrePush, shasToCheck } from "./push.js";
|
|
@@ -26,7 +26,7 @@ async function repo() {
|
|
|
26
26
|
}
|
|
27
27
|
const out = (s) => process.stdout.write(`${s}\n`);
|
|
28
28
|
const err = (s) => process.stderr.write(`${s}\n`);
|
|
29
|
-
const log = (message) => out(
|
|
29
|
+
const log = (message) => out(logLine(message));
|
|
30
30
|
/** The check command itself exited non-zero, as opposed to the check being unable to run. */
|
|
31
31
|
class CheckFailed extends Error {
|
|
32
32
|
command;
|
|
@@ -36,7 +36,7 @@ class CheckFailed extends Error {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
/** Runs the check at `sha` in place, after the clean-tree rule, unless it already passed. */
|
|
39
|
-
async function runCheck({ root, passed }, sha) {
|
|
39
|
+
async function runCheck({ root, passed, log: logFile }, sha) {
|
|
40
40
|
if (passedCommand(passed, sha))
|
|
41
41
|
return;
|
|
42
42
|
const reason = cannotCheckInPlace(sha, await git("rev-parse", "HEAD"), await git("status", "--porcelain"));
|
|
@@ -44,10 +44,19 @@ async function runCheck({ root, passed }, sha) {
|
|
|
44
44
|
throw new Error(`cannot check ${sha.slice(0, 7)}: ${reason}`);
|
|
45
45
|
const command = resolveCommand(root);
|
|
46
46
|
err(`local-ci: running ${command} on ${sha.slice(0, 7)}`);
|
|
47
|
+
const started = performance.now();
|
|
47
48
|
const result = spawnSync("sh", ["-c", command], {
|
|
48
49
|
cwd: root,
|
|
49
50
|
stdio: ["ignore", "inherit", "inherit"],
|
|
50
51
|
});
|
|
52
|
+
// Every run's duration goes in the log, so a faster check can be measured against a slower one.
|
|
53
|
+
// A log that can't be written must not change the check's outcome.
|
|
54
|
+
try {
|
|
55
|
+
appendLog(logFile, checkRunMessage(sha, command, result.status, performance.now() - started));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
err(`local-ci: could not log the run: ${error instanceof Error ? error.message : String(error)}`);
|
|
59
|
+
}
|
|
51
60
|
// A spawn error or a signal means the check never finished, so it is not a failure to post.
|
|
52
61
|
if (result.status === null) {
|
|
53
62
|
const cause = result.error?.message ?? result.signal;
|
package/dist/config.d.ts
CHANGED
|
@@ -10,6 +10,15 @@ export declare function statePaths(repo: string, env?: NodeJS.ProcessEnv): {
|
|
|
10
10
|
passed: string;
|
|
11
11
|
lock: string;
|
|
12
12
|
};
|
|
13
|
+
/** A line of the repo's log: the message after an ISO timestamp. */
|
|
14
|
+
export declare function logLine(message: string, now?: Date): string;
|
|
15
|
+
/** Appends `message` to the repo's log as one timestamped line. */
|
|
16
|
+
export declare function appendLog(file: string, message: string, now?: Date): void;
|
|
17
|
+
/**
|
|
18
|
+
* How a check run ended and how long it took, e.g. `abc1234: pnpm check passed in 71.2s`.
|
|
19
|
+
* A null `status` (a spawn error or a signal) means the check never finished.
|
|
20
|
+
*/
|
|
21
|
+
export declare function checkRunMessage(sha: string, command: string, status: number | null, ms: number): string;
|
|
13
22
|
/** Records that `command` passed at `sha`, one `<sha>\t<command>` line per commit. */
|
|
14
23
|
export declare function recordPass(file: string, sha: string, command: string): void;
|
|
15
24
|
/** The command that last passed at `sha`, or undefined if it was never checked. */
|
package/dist/config.js
CHANGED
|
@@ -34,6 +34,26 @@ export function statePaths(repo, env = process.env) {
|
|
|
34
34
|
lock: join(dir, `${repo}.release.lock`),
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
/** A line of the repo's log: the message after an ISO timestamp. */
|
|
38
|
+
export function logLine(message, now = new Date()) {
|
|
39
|
+
return `[${now.toISOString()}] ${message}`;
|
|
40
|
+
}
|
|
41
|
+
/** Appends `message` to the repo's log as one timestamped line. */
|
|
42
|
+
export function appendLog(file, message, now = new Date()) {
|
|
43
|
+
appendFileSync(file, `${logLine(message, now)}\n`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* How a check run ended and how long it took, e.g. `abc1234: pnpm check passed in 71.2s`.
|
|
47
|
+
* A null `status` (a spawn error or a signal) means the check never finished.
|
|
48
|
+
*/
|
|
49
|
+
export function checkRunMessage(sha, command, status, ms) {
|
|
50
|
+
const seconds = `${(ms / 1000).toFixed(1)}s`;
|
|
51
|
+
const outcome = status === null
|
|
52
|
+
? `did not finish after ${seconds}`
|
|
53
|
+
: `${status === 0 ? "passed" : "failed"} in ${seconds}`;
|
|
54
|
+
// One line per run, even for a command written over several lines.
|
|
55
|
+
return `${sha.slice(0, 7)}: ${command.replace(/\s+/g, " ")} ${outcome}`;
|
|
56
|
+
}
|
|
37
57
|
/** Records that `command` passed at `sha`, one `<sha>\t<command>` line per commit. */
|
|
38
58
|
export function recordPass(file, sha, command) {
|
|
39
59
|
appendFileSync(file, `${sha}\t${command}\n`);
|