@milkenjoyer/toolchain 0.9.0 → 0.10.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 +5 -1
- package/dist/verdict.d.mts +3 -0
- package/dist/verdict.mjs +39 -0
- package/dist/verification-2bhNnJr-.mjs +111 -0
- package/dist/verification-MNG9WKEH.d.mts +40 -0
- package/dist/verification.d.mts +2 -28
- package/dist/verification.mjs +1 -97
- package/package.json +3 -1
- package/src/verdict.ts +50 -0
- package/src/verification.ts +50 -22
package/README.md
CHANGED
|
@@ -36,6 +36,10 @@ In CI, give the job `permissions: contents: write`, set `GH_TOKEN: ${{ github.to
|
|
|
36
36
|
|
|
37
37
|
## Verification check
|
|
38
38
|
|
|
39
|
-
The `
|
|
39
|
+
The `verdict` bin posts a `verdict` commit status of `success` on the PR head SHA for Renovate or changes containing only docs, art, media, fonts or changesets. Files under any `skills/` directory require a live run and do not qualify for the docs exemption. Unknown or truncated file lists do not qualify for the docs exemption either. Code PRs post no status and wait for an independent live verdict. Rerunning CI cannot overwrite a live verdict on a code PR.
|
|
40
|
+
|
|
41
|
+
On `pull_request`, run this before any docs-only scope skip. Give the job `permissions: statuses: write` alongside `contents: read`, set `GH_TOKEN: ${{ github.token }}`, and run `vp exec verdict`. It reads `GITHUB_EVENT_PATH` and accepts `GITHUB_TOKEN` as a fallback. Other events exit successfully without posting.
|
|
42
|
+
|
|
43
|
+
The `verification` check requires a code-tier PR body to contain a `## Verification` section naming at least one real run in backticks. Record each command or verifier recipe and its outcome. Renovate PRs and PRs changing only Markdown, MDX, LICENSE files, art, media or fonts outside `skills/` directories are exempt. Changeset-only PRs are exempt. An unknown or truncated file list requires verification. HTML comments do not count as runs.
|
|
40
44
|
|
|
41
45
|
In the PR job, set `permissions: contents: read` and `GH_TOKEN: ${{ github.token }}`, then run `vp exec verification`. The check reads the original pull request event and compares its base and head through the GitHub API. After editing a failing body, push again because a rerun reads the body from the original event.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { i as VerificationError } from "./verification-MNG9WKEH.mjs";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
export declare const checkVerdict: Effect.Effect<number, import("effect/Config").ConfigError | import("effect/PlatformError").PlatformError | import("effect/Schema").SchemaError | VerificationError, import("effect/FileSystem").FileSystem>;
|
package/dist/verdict.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { a as readPullRequest, i as github, n as autoPass } from "./verification-2bhNnJr-.mjs";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { NodeServices } from "@effect/platform-node";
|
|
5
|
+
import * as Cause from "effect/Cause";
|
|
6
|
+
import * as Exit from "effect/Exit";
|
|
7
|
+
import * as Console from "effect/Console";
|
|
8
|
+
// src/verdict.ts
|
|
9
|
+
const checkVerdict = Effect.gen(function* () {
|
|
10
|
+
const request = yield* readPullRequest;
|
|
11
|
+
if (request === void 0) return 0;
|
|
12
|
+
const { octokit, owner, repo, number, sha, pr } = request;
|
|
13
|
+
const reason = autoPass(pr);
|
|
14
|
+
if (reason === void 0) {
|
|
15
|
+
yield* Console.log(`PR #${number} at ${sha} waits for an independent live verdict.`);
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
const description = `PASS: auto, ${reason}`.slice(0, 139);
|
|
19
|
+
yield* github(() => octokit.rest.repos.createCommitStatus({
|
|
20
|
+
owner,
|
|
21
|
+
repo,
|
|
22
|
+
sha,
|
|
23
|
+
context: "verdict",
|
|
24
|
+
state: "success",
|
|
25
|
+
description
|
|
26
|
+
}));
|
|
27
|
+
yield* Console.log(`Posted verdict: success on PR #${number} at ${sha}: ${description}`);
|
|
28
|
+
return 0;
|
|
29
|
+
});
|
|
30
|
+
if (import.meta.main) {
|
|
31
|
+
const exit = await Effect.runPromiseExit(checkVerdict.pipe(Effect.provide(NodeServices.layer)));
|
|
32
|
+
if (Exit.isSuccess(exit)) process.exitCode = exit.value;
|
|
33
|
+
else {
|
|
34
|
+
const error = Cause.squash(exit.cause);
|
|
35
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export { checkVerdict };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as Data from "effect/Data";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { FileSystem } from "effect/FileSystem";
|
|
5
|
+
import { NodeServices } from "@effect/platform-node";
|
|
6
|
+
import { Octokit } from "@octokit/rest";
|
|
7
|
+
import * as Cause from "effect/Cause";
|
|
8
|
+
import * as Config from "effect/Config";
|
|
9
|
+
import * as Exit from "effect/Exit";
|
|
10
|
+
import * as Redacted from "effect/Redacted";
|
|
11
|
+
import * as Console from "effect/Console";
|
|
12
|
+
// src/verification.ts
|
|
13
|
+
const exemptions = [{
|
|
14
|
+
reason: "Renovate PR",
|
|
15
|
+
applies: (pr) => pr.author === "renovate[bot]"
|
|
16
|
+
}, {
|
|
17
|
+
reason: "changes only docs, content or art",
|
|
18
|
+
applies: (pr) => pr.files !== void 0 && pr.files.length > 0 && pr.files.every((file) => !file.split("/").includes("skills") && /^(?:LICENSE.*|.*\.(?:md|mdx|png|jpg|jpeg|gif|webp|avif|svg|ico|mp4|webm|mov|mp3|wav|ogg|woff|woff2|ttf|otf))$/iu.test(file.split("/").at(-1) ?? ""))
|
|
19
|
+
}];
|
|
20
|
+
const autoPass = (pr) => exemptions.find((entry) => entry.applies(pr))?.reason;
|
|
21
|
+
const verdict = (pr) => {
|
|
22
|
+
const exemption = autoPass(pr);
|
|
23
|
+
if (exemption !== void 0) return {
|
|
24
|
+
_tag: "Exempt",
|
|
25
|
+
reason: exemption
|
|
26
|
+
};
|
|
27
|
+
const lines = (pr.body ?? "").replaceAll(/<!--[\s\S]*?-->/gu, "").split(/\r?\n/u);
|
|
28
|
+
const start = lines.findIndex((line) => /^##\s+Verification\s*$/iu.test(line));
|
|
29
|
+
if (start === -1) return {
|
|
30
|
+
_tag: "Unproven",
|
|
31
|
+
reason: "has no ## Verification section"
|
|
32
|
+
};
|
|
33
|
+
const fencedRun = "\0";
|
|
34
|
+
const [section = ""] = lines.slice(start + 1).join("\n").replaceAll(/^ {0,3}(`{3,}|~{3,})[^\n]*\n([\s\S]*?)^ {0,3}\1[ \t]*$/gmu, (_fence, _marker, content) => content.trim() === "" ? "" : fencedRun).split(/^(?:# |## )/mu);
|
|
35
|
+
return section.includes(fencedRun) || /`[^`\s][^`]*`/u.test(section) ? { _tag: "Proven" } : {
|
|
36
|
+
_tag: "Unproven",
|
|
37
|
+
reason: "names no run"
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
var VerificationError = class extends Data.TaggedError("VerificationError") {};
|
|
41
|
+
const github = (request) => Effect.tryPromise({
|
|
42
|
+
try: request,
|
|
43
|
+
catch: (cause) => new VerificationError({ message: cause instanceof Error ? cause.message : String(cause) })
|
|
44
|
+
});
|
|
45
|
+
const PullRequestEvent = Schema.fromJsonString(Schema.Struct({
|
|
46
|
+
pull_request: Schema.Struct({
|
|
47
|
+
number: Schema.Finite,
|
|
48
|
+
body: Schema.NullOr(Schema.String),
|
|
49
|
+
user: Schema.Struct({ login: Schema.String }),
|
|
50
|
+
base: Schema.Struct({ sha: Schema.String }),
|
|
51
|
+
head: Schema.Struct({ sha: Schema.String })
|
|
52
|
+
}),
|
|
53
|
+
repository: Schema.Struct({ full_name: Schema.String })
|
|
54
|
+
}));
|
|
55
|
+
const readPullRequest = Effect.gen(function* () {
|
|
56
|
+
if ((yield* Config.String("GITHUB_EVENT_NAME").pipe(Config.withDefault(""))) !== "pull_request") {
|
|
57
|
+
yield* Console.log("Not a pull_request event, so there is no PR to check.");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const fs = yield* FileSystem;
|
|
61
|
+
const eventPath = yield* Config.String("GITHUB_EVENT_PATH");
|
|
62
|
+
const payload = yield* fs.readFileString(eventPath);
|
|
63
|
+
const { pull_request: pr, repository } = yield* Schema.decodeEffect(PullRequestEvent)(payload);
|
|
64
|
+
const [, owner, repo] = /^([^/\s]+)\/([^/\s]+)$/u.exec(repository.full_name) ?? [];
|
|
65
|
+
if (owner === void 0 || repo === void 0) return yield* new VerificationError({ message: "Invalid repository.full_name" });
|
|
66
|
+
const token = yield* Config.schema(Schema.Redacted(Schema.NonEmptyString), "GH_TOKEN").pipe(Config.orElse(() => Config.schema(Schema.Redacted(Schema.NonEmptyString), "GITHUB_TOKEN")), Effect.mapError(() => new VerificationError({ message: "Missing GH_TOKEN or GITHUB_TOKEN" })));
|
|
67
|
+
const octokit = new Octokit({ auth: Redacted.value(token) });
|
|
68
|
+
const { data } = yield* github(() => octokit.rest.repos.compareCommitsWithBasehead({
|
|
69
|
+
owner,
|
|
70
|
+
repo,
|
|
71
|
+
basehead: `${pr.base.sha}...${pr.head.sha}`
|
|
72
|
+
}));
|
|
73
|
+
return {
|
|
74
|
+
octokit,
|
|
75
|
+
owner,
|
|
76
|
+
repo,
|
|
77
|
+
number: pr.number,
|
|
78
|
+
sha: pr.head.sha,
|
|
79
|
+
pr: {
|
|
80
|
+
author: pr.user.login,
|
|
81
|
+
body: pr.body,
|
|
82
|
+
files: data.files === void 0 || data.files.length >= 300 ? void 0 : data.files.map((file) => file.filename)
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const checkVerification = Effect.gen(function* () {
|
|
87
|
+
const request = yield* readPullRequest;
|
|
88
|
+
if (request === void 0) return 0;
|
|
89
|
+
const { number } = request;
|
|
90
|
+
const result = verdict(request.pr);
|
|
91
|
+
if (result._tag === "Exempt") {
|
|
92
|
+
yield* Console.log(`PR #${number} is exempt: ${result.reason}.`);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
if (result._tag === "Proven") {
|
|
96
|
+
yield* Console.log(`PR #${number}'s ## Verification names a run.`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
yield* Console.error(`PR #${number} ${result.reason}. Add a ## Verification section naming each real run (the command or verifier recipe in backticks) and its outcome, then push again after editing the body: a rerun reads the body from the original event.`);
|
|
100
|
+
return 1;
|
|
101
|
+
});
|
|
102
|
+
if (import.meta.main) {
|
|
103
|
+
const exit = await Effect.runPromiseExit(checkVerification.pipe(Effect.provide(NodeServices.layer)));
|
|
104
|
+
if (Exit.isSuccess(exit)) process.exitCode = exit.value;
|
|
105
|
+
else {
|
|
106
|
+
const error = Cause.squash(exit.cause);
|
|
107
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export { readPullRequest as a, github as i, autoPass as n, verdict as o, checkVerification as r, VerificationError as t };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { FileSystem } from "effect/FileSystem";
|
|
4
|
+
import { Octokit } from "@octokit/rest";
|
|
5
|
+
import * as Cause from "effect/Cause";
|
|
6
|
+
import * as Config from "effect/Config";
|
|
7
|
+
type PullRequest = {
|
|
8
|
+
readonly author: string;
|
|
9
|
+
readonly body: string | null;
|
|
10
|
+
readonly files: ReadonlyArray<string> | undefined;
|
|
11
|
+
};
|
|
12
|
+
type Verdict = {
|
|
13
|
+
readonly _tag: "Exempt";
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly _tag: "Proven";
|
|
17
|
+
} | {
|
|
18
|
+
readonly _tag: "Unproven";
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
};
|
|
21
|
+
declare const autoPass: (pr: PullRequest) => string | undefined;
|
|
22
|
+
declare const verdict: (pr: PullRequest) => Verdict;
|
|
23
|
+
declare const VerificationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
24
|
+
readonly _tag: "VerificationError";
|
|
25
|
+
} & Readonly<A>;
|
|
26
|
+
declare class VerificationError extends VerificationError_base<{
|
|
27
|
+
readonly message: string;
|
|
28
|
+
}> {}
|
|
29
|
+
declare const github: <A>(request: () => Promise<A>) => Effect.Effect<A, VerificationError, never>;
|
|
30
|
+
type PullRequestContext = {
|
|
31
|
+
readonly octokit: Octokit;
|
|
32
|
+
readonly owner: string;
|
|
33
|
+
readonly repo: string;
|
|
34
|
+
readonly number: number;
|
|
35
|
+
readonly sha: string;
|
|
36
|
+
readonly pr: PullRequest;
|
|
37
|
+
};
|
|
38
|
+
declare const readPullRequest: Effect.Effect<PullRequestContext | undefined, Config.ConfigError | import("effect/PlatformError").PlatformError | Schema.SchemaError | VerificationError, FileSystem>;
|
|
39
|
+
declare const checkVerification: Effect.Effect<0 | 1, Config.ConfigError | import("effect/PlatformError").PlatformError | Schema.SchemaError | VerificationError, FileSystem>;
|
|
40
|
+
export { autoPass as a, readPullRequest as c, VerificationError as i, verdict as l, PullRequestContext as n, checkVerification as o, Verdict as r, github as s, PullRequest as t };
|
package/dist/verification.d.mts
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { FileSystem } from "effect/FileSystem";
|
|
4
|
-
import * as Cause from "effect/Cause";
|
|
5
|
-
import * as Config from "effect/Config";
|
|
6
|
-
export type PullRequest = {
|
|
7
|
-
readonly author: string;
|
|
8
|
-
readonly body: string | null;
|
|
9
|
-
readonly files: ReadonlyArray<string> | undefined;
|
|
10
|
-
};
|
|
11
|
-
export type Verdict = {
|
|
12
|
-
readonly _tag: "Exempt";
|
|
13
|
-
readonly reason: string;
|
|
14
|
-
} | {
|
|
15
|
-
readonly _tag: "Proven";
|
|
16
|
-
} | {
|
|
17
|
-
readonly _tag: "Unproven";
|
|
18
|
-
readonly reason: string;
|
|
19
|
-
};
|
|
20
|
-
export declare const verdict: (pr: PullRequest) => Verdict;
|
|
21
|
-
declare const VerificationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
22
|
-
readonly _tag: "VerificationError";
|
|
23
|
-
} & Readonly<A>;
|
|
24
|
-
declare class VerificationError extends VerificationError_base<{
|
|
25
|
-
readonly message: string;
|
|
26
|
-
}> {}
|
|
27
|
-
export declare const checkVerification: Effect.Effect<0 | 1, Config.ConfigError | import("effect/PlatformError").PlatformError | Schema.SchemaError | VerificationError, FileSystem>;
|
|
28
|
-
export {};
|
|
1
|
+
import { a as autoPass, c as readPullRequest, i as VerificationError, l as verdict, n as PullRequestContext, o as checkVerification, r as Verdict, s as github, t as PullRequest } from "./verification-MNG9WKEH.mjs";
|
|
2
|
+
export { PullRequest, PullRequestContext, Verdict, VerificationError, autoPass, checkVerification, github, readPullRequest, verdict };
|
package/dist/verification.mjs
CHANGED
|
@@ -1,98 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import * as Schema from "effect/Schema";
|
|
4
|
-
import * as Effect from "effect/Effect";
|
|
5
|
-
import { FileSystem } from "effect/FileSystem";
|
|
6
|
-
import { NodeServices } from "@effect/platform-node";
|
|
7
|
-
import { Octokit } from "@octokit/rest";
|
|
8
|
-
import * as Cause from "effect/Cause";
|
|
9
|
-
import * as Config from "effect/Config";
|
|
10
|
-
import * as Exit from "effect/Exit";
|
|
11
|
-
import * as Redacted from "effect/Redacted";
|
|
12
|
-
import * as Console from "effect/Console";
|
|
13
|
-
// src/verification.ts
|
|
14
|
-
const exemptions = [{
|
|
15
|
-
reason: "Renovate PR",
|
|
16
|
-
applies: (pr) => pr.author === "renovate[bot]"
|
|
17
|
-
}, {
|
|
18
|
-
reason: "changes only docs, content or art",
|
|
19
|
-
applies: (pr) => pr.files !== void 0 && pr.files.length > 0 && pr.files.every((file) => /^(?:LICENSE.*|.*\.(?:md|mdx|png|jpg|jpeg|gif|webp|avif|svg|ico|mp4|webm|mov|mp3|wav|ogg|woff|woff2|ttf|otf))$/iu.test(file.split("/").at(-1) ?? ""))
|
|
20
|
-
}];
|
|
21
|
-
const verdict = (pr) => {
|
|
22
|
-
const exemption = exemptions.find((entry) => entry.applies(pr));
|
|
23
|
-
if (exemption !== void 0) return {
|
|
24
|
-
_tag: "Exempt",
|
|
25
|
-
reason: exemption.reason
|
|
26
|
-
};
|
|
27
|
-
const lines = (pr.body ?? "").replaceAll(/<!--[\s\S]*?-->/gu, "").split(/\r?\n/u);
|
|
28
|
-
const start = lines.findIndex((line) => /^##\s+Verification\s*$/iu.test(line));
|
|
29
|
-
if (start === -1) return {
|
|
30
|
-
_tag: "Unproven",
|
|
31
|
-
reason: "has no ## Verification section"
|
|
32
|
-
};
|
|
33
|
-
const fencedRun = "\0";
|
|
34
|
-
const [section = ""] = lines.slice(start + 1).join("\n").replaceAll(/^ {0,3}(`{3,}|~{3,})[^\n]*\n([\s\S]*?)^ {0,3}\1[ \t]*$/gmu, (_fence, _marker, content) => content.trim() === "" ? "" : fencedRun).split(/^(?:# |## )/mu);
|
|
35
|
-
return section.includes(fencedRun) || /`[^`\s][^`]*`/u.test(section) ? { _tag: "Proven" } : {
|
|
36
|
-
_tag: "Unproven",
|
|
37
|
-
reason: "names no run"
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
var VerificationError = class extends Data.TaggedError("VerificationError") {};
|
|
41
|
-
const github = (request) => Effect.tryPromise({
|
|
42
|
-
try: request,
|
|
43
|
-
catch: (cause) => new VerificationError({ message: cause instanceof Error ? cause.message : String(cause) })
|
|
44
|
-
});
|
|
45
|
-
const PullRequestEvent = Schema.fromJsonString(Schema.Struct({
|
|
46
|
-
pull_request: Schema.Struct({
|
|
47
|
-
number: Schema.Finite,
|
|
48
|
-
body: Schema.NullOr(Schema.String),
|
|
49
|
-
user: Schema.Struct({ login: Schema.String }),
|
|
50
|
-
base: Schema.Struct({ sha: Schema.String }),
|
|
51
|
-
head: Schema.Struct({ sha: Schema.String })
|
|
52
|
-
}),
|
|
53
|
-
repository: Schema.Struct({ full_name: Schema.String })
|
|
54
|
-
}));
|
|
55
|
-
const checkVerification = Effect.gen(function* () {
|
|
56
|
-
if ((yield* Config.String("GITHUB_EVENT_NAME").pipe(Config.withDefault(""))) !== "pull_request") {
|
|
57
|
-
yield* Console.log("Not a pull_request event, so there is no PR to check.");
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
60
|
-
const fs = yield* FileSystem;
|
|
61
|
-
const eventPath = yield* Config.String("GITHUB_EVENT_PATH");
|
|
62
|
-
const payload = yield* fs.readFileString(eventPath);
|
|
63
|
-
const { pull_request: pr, repository } = yield* Schema.decodeEffect(PullRequestEvent)(payload);
|
|
64
|
-
const [, owner, repo] = /^([^/\s]+)\/([^/\s]+)$/u.exec(repository.full_name) ?? [];
|
|
65
|
-
if (owner === void 0 || repo === void 0) return yield* new VerificationError({ message: "Invalid repository.full_name" });
|
|
66
|
-
const token = yield* Config.schema(Schema.Redacted(Schema.NonEmptyString), "GH_TOKEN").pipe(Config.orElse(() => Config.schema(Schema.Redacted(Schema.NonEmptyString), "GITHUB_TOKEN")), Effect.mapError(() => new VerificationError({ message: "Missing GH_TOKEN or GITHUB_TOKEN" })));
|
|
67
|
-
const octokit = new Octokit({ auth: Redacted.value(token) });
|
|
68
|
-
const { data } = yield* github(() => octokit.rest.repos.compareCommitsWithBasehead({
|
|
69
|
-
owner,
|
|
70
|
-
repo,
|
|
71
|
-
basehead: `${pr.base.sha}...${pr.head.sha}`
|
|
72
|
-
}));
|
|
73
|
-
const result = verdict({
|
|
74
|
-
author: pr.user.login,
|
|
75
|
-
body: pr.body,
|
|
76
|
-
files: data.files === void 0 || data.files.length >= 300 ? void 0 : data.files.map((file) => file.filename)
|
|
77
|
-
});
|
|
78
|
-
if (result._tag === "Exempt") {
|
|
79
|
-
yield* Console.log(`PR #${pr.number} is exempt: ${result.reason}.`);
|
|
80
|
-
return 0;
|
|
81
|
-
}
|
|
82
|
-
if (result._tag === "Proven") {
|
|
83
|
-
yield* Console.log(`PR #${pr.number}'s ## Verification names a run.`);
|
|
84
|
-
return 0;
|
|
85
|
-
}
|
|
86
|
-
yield* Console.error(`PR #${pr.number} ${result.reason}. Add a ## Verification section naming each real run (the command or verifier recipe in backticks) and its outcome, then push again after editing the body: a rerun reads the body from the original event.`);
|
|
87
|
-
return 1;
|
|
88
|
-
});
|
|
89
|
-
if (import.meta.main) {
|
|
90
|
-
const exit = await Effect.runPromiseExit(checkVerification.pipe(Effect.provide(NodeServices.layer)));
|
|
91
|
-
if (Exit.isSuccess(exit)) process.exitCode = exit.value;
|
|
92
|
-
else {
|
|
93
|
-
const error = Cause.squash(exit.cause);
|
|
94
|
-
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
95
|
-
process.exitCode = 1;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
export { checkVerification, verdict };
|
|
2
|
+
export { t as VerificationError, n as autoPass, r as checkVerification, i as github, a as readPullRequest, o as verdict } from "./verification-2bhNnJr-.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkenjoyer/toolchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/birbprophet/agent-kit.git",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
10
|
"proof": "./src/proof.ts",
|
|
11
|
+
"verdict": "./src/verdict.ts",
|
|
11
12
|
"verification": "./src/verification.ts"
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
@@ -16,6 +17,7 @@
|
|
|
16
17
|
"node-version",
|
|
17
18
|
"renovate.json",
|
|
18
19
|
"src/proof.ts",
|
|
20
|
+
"src/verdict.ts",
|
|
19
21
|
"src/verification.ts",
|
|
20
22
|
"tsconfig.base.json",
|
|
21
23
|
"vscode/extensions.json",
|
package/src/verdict.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { NodeServices } from "@effect/platform-node";
|
|
3
|
+
import * as Cause from "effect/Cause";
|
|
4
|
+
import * as Console from "effect/Console";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Exit from "effect/Exit";
|
|
7
|
+
|
|
8
|
+
import { autoPass, github, readPullRequest } from "./verification.ts";
|
|
9
|
+
|
|
10
|
+
export const checkVerdict = Effect.gen(function* () {
|
|
11
|
+
const request = yield* readPullRequest;
|
|
12
|
+
if (request === undefined) return 0;
|
|
13
|
+
const { octokit, owner, repo, number, sha, pr } = request;
|
|
14
|
+
const reason = autoPass(pr);
|
|
15
|
+
if (reason === undefined) {
|
|
16
|
+
yield* Console.log(
|
|
17
|
+
`PR #${number} at ${sha} waits for an independent live verdict.`
|
|
18
|
+
);
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
const description = `PASS: auto, ${reason}`.slice(0, 139);
|
|
22
|
+
yield* github(() =>
|
|
23
|
+
octokit.rest.repos.createCommitStatus({
|
|
24
|
+
owner,
|
|
25
|
+
repo,
|
|
26
|
+
sha,
|
|
27
|
+
context: "verdict",
|
|
28
|
+
state: "success",
|
|
29
|
+
description,
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
yield* Console.log(
|
|
33
|
+
`Posted verdict: success on PR #${number} at ${sha}: ${description}`
|
|
34
|
+
);
|
|
35
|
+
return 0;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (import.meta.main) {
|
|
39
|
+
const exit = await Effect.runPromiseExit(
|
|
40
|
+
checkVerdict.pipe(Effect.provide(NodeServices.layer))
|
|
41
|
+
);
|
|
42
|
+
if (Exit.isSuccess(exit)) process.exitCode = exit.value;
|
|
43
|
+
else {
|
|
44
|
+
const error = Cause.squash(exit.cause);
|
|
45
|
+
process.stderr.write(
|
|
46
|
+
`${error instanceof Error ? error.message : String(error)}\n`
|
|
47
|
+
);
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/verification.ts
CHANGED
|
@@ -35,18 +35,22 @@ const exemptions: ReadonlyArray<{
|
|
|
35
35
|
applies: (pr) =>
|
|
36
36
|
pr.files !== undefined &&
|
|
37
37
|
pr.files.length > 0 &&
|
|
38
|
-
pr.files.every(
|
|
39
|
-
|
|
40
|
-
file.split("/").
|
|
41
|
-
|
|
38
|
+
pr.files.every(
|
|
39
|
+
(file) =>
|
|
40
|
+
!file.split("/").includes("skills") &&
|
|
41
|
+
/^(?:LICENSE.*|.*\.(?:md|mdx|png|jpg|jpeg|gif|webp|avif|svg|ico|mp4|webm|mov|mp3|wav|ogg|woff|woff2|ttf|otf))$/iu.test(
|
|
42
|
+
file.split("/").at(-1) ?? ""
|
|
43
|
+
)
|
|
42
44
|
),
|
|
43
45
|
},
|
|
44
46
|
];
|
|
45
47
|
|
|
48
|
+
export const autoPass = (pr: PullRequest): string | undefined =>
|
|
49
|
+
exemptions.find((entry) => entry.applies(pr))?.reason;
|
|
50
|
+
|
|
46
51
|
export const verdict = (pr: PullRequest): Verdict => {
|
|
47
|
-
const exemption =
|
|
48
|
-
if (exemption !== undefined)
|
|
49
|
-
return { _tag: "Exempt", reason: exemption.reason };
|
|
52
|
+
const exemption = autoPass(pr);
|
|
53
|
+
if (exemption !== undefined) return { _tag: "Exempt", reason: exemption };
|
|
50
54
|
const lines = (pr.body ?? "")
|
|
51
55
|
.replaceAll(/<!--[\s\S]*?-->/gu, "")
|
|
52
56
|
.split(/\r?\n/u);
|
|
@@ -70,11 +74,11 @@ export const verdict = (pr: PullRequest): Verdict => {
|
|
|
70
74
|
: { _tag: "Unproven", reason: "names no run" };
|
|
71
75
|
};
|
|
72
76
|
|
|
73
|
-
class VerificationError extends Data.TaggedError("VerificationError")<{
|
|
77
|
+
export class VerificationError extends Data.TaggedError("VerificationError")<{
|
|
74
78
|
readonly message: string;
|
|
75
79
|
}> {}
|
|
76
80
|
|
|
77
|
-
const github = <A>(request: () => Promise<A>) =>
|
|
81
|
+
export const github = <A>(request: () => Promise<A>) =>
|
|
78
82
|
Effect.tryPromise({
|
|
79
83
|
try: request,
|
|
80
84
|
catch: (cause) =>
|
|
@@ -96,13 +100,22 @@ const PullRequestEvent = Schema.fromJsonString(
|
|
|
96
100
|
})
|
|
97
101
|
);
|
|
98
102
|
|
|
99
|
-
export
|
|
103
|
+
export type PullRequestContext = {
|
|
104
|
+
readonly octokit: Octokit;
|
|
105
|
+
readonly owner: string;
|
|
106
|
+
readonly repo: string;
|
|
107
|
+
readonly number: number;
|
|
108
|
+
readonly sha: string;
|
|
109
|
+
readonly pr: PullRequest;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const readPullRequest = Effect.gen(function* () {
|
|
100
113
|
const event = yield* Config.String("GITHUB_EVENT_NAME").pipe(
|
|
101
114
|
Config.withDefault("")
|
|
102
115
|
);
|
|
103
116
|
if (event !== "pull_request") {
|
|
104
117
|
yield* Console.log("Not a pull_request event, so there is no PR to check.");
|
|
105
|
-
return
|
|
118
|
+
return undefined;
|
|
106
119
|
}
|
|
107
120
|
const fs = yield* FileSystem;
|
|
108
121
|
const eventPath = yield* Config.String("GITHUB_EVENT_PATH");
|
|
@@ -135,24 +148,39 @@ export const checkVerification = Effect.gen(function* () {
|
|
|
135
148
|
basehead: `${pr.base.sha}...${pr.head.sha}`,
|
|
136
149
|
})
|
|
137
150
|
);
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
const request: PullRequestContext = {
|
|
152
|
+
octokit,
|
|
153
|
+
owner,
|
|
154
|
+
repo,
|
|
155
|
+
number: pr.number,
|
|
156
|
+
sha: pr.head.sha,
|
|
157
|
+
pr: {
|
|
158
|
+
author: pr.user.login,
|
|
159
|
+
body: pr.body,
|
|
160
|
+
files:
|
|
161
|
+
data.files === undefined || data.files.length >= 300
|
|
162
|
+
? undefined
|
|
163
|
+
: data.files.map((file) => file.filename),
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
return request;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
export const checkVerification = Effect.gen(function* () {
|
|
170
|
+
const request = yield* readPullRequest;
|
|
171
|
+
if (request === undefined) return 0;
|
|
172
|
+
const { number } = request;
|
|
173
|
+
const result = verdict(request.pr);
|
|
146
174
|
if (result._tag === "Exempt") {
|
|
147
|
-
yield* Console.log(`PR #${
|
|
175
|
+
yield* Console.log(`PR #${number} is exempt: ${result.reason}.`);
|
|
148
176
|
return 0;
|
|
149
177
|
}
|
|
150
178
|
if (result._tag === "Proven") {
|
|
151
|
-
yield* Console.log(`PR #${
|
|
179
|
+
yield* Console.log(`PR #${number}'s ## Verification names a run.`);
|
|
152
180
|
return 0;
|
|
153
181
|
}
|
|
154
182
|
yield* Console.error(
|
|
155
|
-
`PR #${
|
|
183
|
+
`PR #${number} ${result.reason}. Add a ## Verification section naming each real run (the command or verifier recipe in backticks) and its outcome, then push again after editing the body: a rerun reads the body from the original event.`
|
|
156
184
|
);
|
|
157
185
|
return 1;
|
|
158
186
|
});
|