@jonmilner/local-ci 0.1.0 → 0.2.0
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 +39 -6
- package/dist/github.d.ts +1 -1
- package/dist/github.js +3 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ exec pnpm exec local-ci pre-push "$@"
|
|
|
22
22
|
- `local-ci pre-push`: the hook. 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 lets the push go ahead.
|
|
23
23
|
- `local-ci post <sha>`: 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.
|
|
24
24
|
- `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.
|
|
25
|
-
- `local-ci status [<sha>]`: posts `check` for a commit (default `HEAD`) that already passed, or runs the check first. Use it after a push that skipped hooks (`--no-verify`) or a lost background poster.
|
|
25
|
+
- `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.
|
|
26
26
|
|
|
27
27
|
## Check command
|
|
28
28
|
|
package/dist/cli.js
CHANGED
|
@@ -25,6 +25,14 @@ async function repo() {
|
|
|
25
25
|
const out = (s) => process.stdout.write(`${s}\n`);
|
|
26
26
|
const err = (s) => process.stderr.write(`${s}\n`);
|
|
27
27
|
const log = (message) => out(`[${new Date().toISOString()}] ${message}`);
|
|
28
|
+
/** The check command itself exited non-zero, as opposed to the check being unable to run. */
|
|
29
|
+
class CheckFailed extends Error {
|
|
30
|
+
command;
|
|
31
|
+
constructor(command, sha) {
|
|
32
|
+
super(`${command} failed on ${sha.slice(0, 7)}`);
|
|
33
|
+
this.command = command;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
28
36
|
/** Runs the check at `sha` in place, after the clean-tree rule, unless it already passed. */
|
|
29
37
|
async function runCheck({ root, passed }, sha) {
|
|
30
38
|
if (passedCommand(passed, sha))
|
|
@@ -38,8 +46,13 @@ async function runCheck({ root, passed }, sha) {
|
|
|
38
46
|
cwd: root,
|
|
39
47
|
stdio: ["ignore", "inherit", "inherit"],
|
|
40
48
|
});
|
|
49
|
+
// A spawn error or a signal means the check never finished, so it is not a failure to post.
|
|
50
|
+
if (result.status === null) {
|
|
51
|
+
const cause = result.error?.message ?? result.signal;
|
|
52
|
+
throw new Error(`${command} did not finish on ${sha.slice(0, 7)}: ${cause}`);
|
|
53
|
+
}
|
|
41
54
|
if (result.status !== 0)
|
|
42
|
-
throw new
|
|
55
|
+
throw new CheckFailed(command, sha);
|
|
43
56
|
recordPass(passed, sha, command);
|
|
44
57
|
}
|
|
45
58
|
async function prePush(remoteUrl) {
|
|
@@ -70,10 +83,7 @@ async function post({ passed }, sha) {
|
|
|
70
83
|
if (!command) {
|
|
71
84
|
throw new Error(`${sha.slice(0, 7)} has no passing check; run local-ci status ${sha}`);
|
|
72
85
|
}
|
|
73
|
-
|
|
74
|
-
await waitForCommit(exec, sha);
|
|
75
|
-
await postStatus(exec, sha, checkStatus(command, hostname()));
|
|
76
|
-
log(`${sha.slice(0, 7)}: posted check`);
|
|
86
|
+
await postCheck(sha, checkStatus(command, hostname()));
|
|
77
87
|
const pr = await waitForOpenPr(exec, sha);
|
|
78
88
|
if (pr)
|
|
79
89
|
await prTitle(String(pr), sha);
|
|
@@ -88,10 +98,33 @@ async function prTitle(pr, sha) {
|
|
|
88
98
|
log(`#${number} ${target.slice(0, 7)}: posted pr-title ${status.state}: ${status.description}`);
|
|
89
99
|
return errors.length === 0;
|
|
90
100
|
}
|
|
101
|
+
async function postCheck(sha, status) {
|
|
102
|
+
log(`${sha.slice(0, 7)}: waiting for GitHub`);
|
|
103
|
+
await waitForCommit(exec, sha);
|
|
104
|
+
await postStatus(exec, sha, status);
|
|
105
|
+
log(`${sha.slice(0, 7)}: posted check ${status.state}`);
|
|
106
|
+
}
|
|
107
|
+
/** Posts `check` = `failure`, reporting rather than throwing a failed post so the check's own failure stays the error. */
|
|
108
|
+
async function postFailure(sha, command) {
|
|
109
|
+
try {
|
|
110
|
+
await postCheck(sha, checkStatus(command, hostname(), "failure"));
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
err(`local-ci: could not post check failure: ${error instanceof Error ? error.message : String(error)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
91
116
|
async function status(ref = "HEAD") {
|
|
92
117
|
const sha = await git("rev-parse", "--verify", `${ref}^{commit}`);
|
|
93
118
|
const current = await repo();
|
|
94
|
-
|
|
119
|
+
try {
|
|
120
|
+
await runCheck(current, sha);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
// Unlike pre-push, the commit is already on GitHub, so a failing check shows red there.
|
|
124
|
+
if (error instanceof CheckFailed)
|
|
125
|
+
await postFailure(sha, error.command);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
95
128
|
await post(current, sha);
|
|
96
129
|
}
|
|
97
130
|
async function main([command, ...args]) {
|
package/dist/github.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface StatusPayload {
|
|
|
6
6
|
}
|
|
7
7
|
/** Fails with the command that fixes it unless `gh` is logged in with `repo` scope. */
|
|
8
8
|
export declare function assertGhAuth(exec: Exec): Promise<void>;
|
|
9
|
-
export declare function checkStatus(command: string, host: string): StatusPayload;
|
|
9
|
+
export declare function checkStatus(command: string, host: string, state?: StatusPayload["state"]): StatusPayload;
|
|
10
10
|
export declare function prTitleStatus(errors: string[]): StatusPayload;
|
|
11
11
|
export declare function postStatus(exec: Exec, sha: string, status: StatusPayload): Promise<void>;
|
|
12
12
|
export interface WaitOptions {
|
package/dist/github.js
CHANGED
|
@@ -20,12 +20,9 @@ export async function assertGhAuth(exec) {
|
|
|
20
20
|
function truncate(text) {
|
|
21
21
|
return text.length <= DESCRIPTION_LIMIT ? text : `${text.slice(0, DESCRIPTION_LIMIT - 1)}…`;
|
|
22
22
|
}
|
|
23
|
-
export function checkStatus(command, host) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
context: "check",
|
|
27
|
-
description: truncate(`${command} passed on ${host}`),
|
|
28
|
-
};
|
|
23
|
+
export function checkStatus(command, host, state = "success") {
|
|
24
|
+
const outcome = state === "success" ? "passed" : "failed";
|
|
25
|
+
return { state, context: "check", description: truncate(`${command} ${outcome} on ${host}`) };
|
|
29
26
|
}
|
|
30
27
|
export function prTitleStatus(errors) {
|
|
31
28
|
return errors[0]
|