@antelopejs/tooling-configs 0.2.13 → 0.2.15
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/bin/api-diff.mjs +12 -1
- package/dist/bin/garden.mjs +3 -1
- package/dist/bin/sync.mjs +33 -18
- package/dist/bin/verify.mjs +2611 -2387
- package/dist/{ci-workflow-BDy6hQJ6.mjs → ci-workflow-C0nT5SnX.mjs} +116 -22
- package/dist/verify/index.d.mts +4 -4
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
3
|
+
import { isMap, isPair, isScalar, isSeq, parseDocument, visit } from "yaml";
|
|
4
4
|
//#region src/guardrails/workflow.ts
|
|
5
5
|
const CI_NODE_PATTERN = /^AntelopeJS\/\.github\/\.github\/workflows\/ci-node\.yml@\S+$/;
|
|
6
|
+
const CI_RENOVATE_SYNC_PATTERN = /^AntelopeJS\/\.github\/\.github\/workflows\/ci-renovate-sync\.yml@\S+$/;
|
|
6
7
|
const MISSING_CHECKS_WORKFLOW = "No workflow in .github/workflows runs pnpm run checks. Add a step running `pnpm run checks` (or `pnpm checks`), or a job using AntelopeJS/.github/.github/workflows/ci-node.yml@<ref>.";
|
|
7
8
|
function hasChecksWorkflow(root) {
|
|
8
9
|
const directory = join(root, ".github/workflows");
|
|
@@ -27,22 +28,29 @@ function hasChecksWorkflow(root) {
|
|
|
27
28
|
}
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
function ciNodeCallers(text) {
|
|
31
|
+
function callers(text, pattern) {
|
|
32
32
|
const document = parseDocument(text);
|
|
33
33
|
const jobs = document.errors.length ? void 0 : document.get("jobs", true);
|
|
34
34
|
if (!isMap(jobs)) return [];
|
|
35
|
-
const
|
|
35
|
+
const found = [];
|
|
36
36
|
for (const { key, value: job } of jobs.items) {
|
|
37
37
|
if (!isMap(job)) continue;
|
|
38
38
|
const uses = job.get("uses", true);
|
|
39
|
-
if (isScalar(uses) &&
|
|
39
|
+
if (isScalar(uses) && pattern.test(String(uses.value))) found.push({
|
|
40
40
|
id: String(isScalar(key) ? key.value : key),
|
|
41
41
|
uses: String(uses.value),
|
|
42
42
|
named: job.has("name")
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
return
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
/** Jobs of a workflow file that call the shared Node CI; empty when the YAML does not parse. */
|
|
48
|
+
function ciNodeCallers(text) {
|
|
49
|
+
return callers(text, CI_NODE_PATTERN);
|
|
50
|
+
}
|
|
51
|
+
/** Jobs of a workflow file that call the shared Renovate sync at any ref; empty when the YAML does not parse. */
|
|
52
|
+
function ciRenovateSyncCallers(text) {
|
|
53
|
+
return callers(text, CI_RENOVATE_SYNC_PATTERN);
|
|
46
54
|
}
|
|
47
55
|
//#endregion
|
|
48
56
|
//#region src/guardrails/ci-workflow.ts
|
|
@@ -50,7 +58,9 @@ const CI_PATH = ".github/workflows/ci.yml";
|
|
|
50
58
|
const MUTATION_PATH = ".github/workflows/mutation.yml";
|
|
51
59
|
/** The status context GitHub derives from the caller job id and the shared workflow's `checks` job. */
|
|
52
60
|
const CI_CONTEXT = `ci / checks`;
|
|
61
|
+
const RENOVATE_SYNC_JOB_ID = "renovate-sync";
|
|
53
62
|
const CI_NODE_REF = "AntelopeJS/.github/.github/workflows/ci-node.yml@v1";
|
|
63
|
+
const CI_RENOVATE_SYNC_REF = "AntelopeJS/.github/.github/workflows/ci-renovate-sync.yml@v1";
|
|
54
64
|
const MUTATION_REF = "AntelopeJS/.github/.github/workflows/mutation.yml@v1";
|
|
55
65
|
const CI_CALLER = `name: ci
|
|
56
66
|
|
|
@@ -67,11 +77,22 @@ permissions:
|
|
|
67
77
|
|
|
68
78
|
jobs:
|
|
69
79
|
ci:
|
|
80
|
+
permissions:
|
|
81
|
+
contents: read
|
|
82
|
+
uses: ${CI_NODE_REF}
|
|
83
|
+
with:
|
|
84
|
+
renovate-sync: false
|
|
85
|
+
${RENOVATE_SYNC_JOB_ID}:
|
|
86
|
+
if: >-
|
|
87
|
+
github.event_name == 'pull_request'
|
|
88
|
+
&& startsWith(github.head_ref, 'renovate/')
|
|
89
|
+
&& github.event.pull_request.head.repo.full_name == github.repository
|
|
70
90
|
permissions:
|
|
71
91
|
contents: write
|
|
72
92
|
actions: write
|
|
73
|
-
uses: ${
|
|
93
|
+
uses: ${CI_RENOVATE_SYNC_REF}
|
|
74
94
|
`;
|
|
95
|
+
const PRINT_WIDTH = 80;
|
|
75
96
|
const WEEK_MINUTES = 10080;
|
|
76
97
|
/** Spreads the weekly runs of different repositories over the week so they do not queue together. */
|
|
77
98
|
function mutationCaller(packageName) {
|
|
@@ -93,6 +114,35 @@ jobs:
|
|
|
93
114
|
uses: ${MUTATION_REF}
|
|
94
115
|
`;
|
|
95
116
|
}
|
|
117
|
+
function flatSequence(seq) {
|
|
118
|
+
const items = [];
|
|
119
|
+
for (const item of seq.items) {
|
|
120
|
+
if (!isScalar(item)) return void 0;
|
|
121
|
+
items.push(String(item.source ?? item.value));
|
|
122
|
+
}
|
|
123
|
+
return `[${items.join(", ")}]`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* oxfmt pads flow maps but not flow sequences and breaks a long flow sequence in a style YAML serializers cannot
|
|
127
|
+
* produce, so a rewritten file is only left formatted by turning every non-empty flow map and every flow sequence that
|
|
128
|
+
* would overflow the print width into block style.
|
|
129
|
+
*/
|
|
130
|
+
function blockOverflowingFlow(document) {
|
|
131
|
+
visit(document, {
|
|
132
|
+
Map(_key, map) {
|
|
133
|
+
if (map.flow && map.items.length) map.flow = false;
|
|
134
|
+
},
|
|
135
|
+
Seq(_key, seq, path) {
|
|
136
|
+
if (!seq.flow) return;
|
|
137
|
+
const flat = flatSequence(seq);
|
|
138
|
+
const parent = path.at(-1);
|
|
139
|
+
const owner = isPair(parent) && isScalar(parent.key) ? parent.key : null;
|
|
140
|
+
const nesting = path.filter((ancestor) => isMap(ancestor) || isSeq(ancestor)).length;
|
|
141
|
+
const lead = owner === null ? 2 : String(owner.value).length + 2;
|
|
142
|
+
if (flat === void 0 || 2 * Math.max(nesting - 1, 0) + lead + flat.length > PRINT_WIDTH) seq.flow = false;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
96
146
|
function renameNeeds(document, from, to) {
|
|
97
147
|
const jobs = document.get("jobs", true);
|
|
98
148
|
if (!isMap(jobs)) return;
|
|
@@ -117,16 +167,59 @@ function addDispatch(document) {
|
|
|
117
167
|
else if (isSeq(trigger)) trigger.add("workflow_dispatch");
|
|
118
168
|
else document.set("on", document.createNode(isScalar(trigger) && trigger.value ? [String(trigger.value), "workflow_dispatch"] : ["workflow_dispatch"]));
|
|
119
169
|
}
|
|
120
|
-
function
|
|
170
|
+
function grants(job, expected) {
|
|
121
171
|
const granted = job.get("permissions", true);
|
|
122
|
-
|
|
172
|
+
const names = Object.keys(expected);
|
|
173
|
+
return isMap(granted) && granted.items.length === names.length && names.every((name) => granted.get(name) === expected[name]);
|
|
174
|
+
}
|
|
175
|
+
function grant(document, job, expected) {
|
|
176
|
+
if (grants(job, expected)) return false;
|
|
177
|
+
job.set("permissions", document.createNode(expected));
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
function skipsRenovateSync(job) {
|
|
181
|
+
const inputs = job.get("with", true);
|
|
182
|
+
return isMap(inputs) && inputs.get("renovate-sync") === false;
|
|
183
|
+
}
|
|
184
|
+
function skipRenovateSync(document, job) {
|
|
185
|
+
if (skipsRenovateSync(job)) return false;
|
|
186
|
+
const inputs = job.get("with", true);
|
|
187
|
+
if (isMap(inputs)) inputs.set("renovate-sync", false);
|
|
188
|
+
else job.set("with", document.createNode({ "renovate-sync": false }));
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
function canonicalSyncJob() {
|
|
192
|
+
const job = parseDocument(CI_CALLER).getIn(["jobs", RENOVATE_SYNC_JOB_ID], true);
|
|
193
|
+
if (!isMap(job)) throw new Error("CI_CALLER has no renovate-sync job");
|
|
194
|
+
return job;
|
|
195
|
+
}
|
|
196
|
+
function ensureSyncJob(document, jobs, syncCallers) {
|
|
197
|
+
if (!syncCallers.length) {
|
|
198
|
+
jobs.set(RENOVATE_SYNC_JOB_ID, canonicalSyncJob());
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
let changed = false;
|
|
202
|
+
for (const { id } of syncCallers) {
|
|
203
|
+
const job = jobs.get(id, true);
|
|
204
|
+
if (isMap(job)) changed = grant(document, job, {
|
|
205
|
+
contents: "write",
|
|
206
|
+
actions: "write"
|
|
207
|
+
}) || changed;
|
|
208
|
+
}
|
|
209
|
+
return changed;
|
|
210
|
+
}
|
|
211
|
+
function assertNoClash(jobs, callerId, hasSyncCaller) {
|
|
212
|
+
if (callerId !== "ci" && jobs.has("ci")) throw new Error(`${CI_PATH}: a job named ci already exists besides the ${callerId} job that calls ci-node.yml. Rename or merge them, then rerun antelopejs-sync.`);
|
|
213
|
+
if (hasSyncCaller || !jobs.has(RENOVATE_SYNC_JOB_ID)) return;
|
|
214
|
+
throw new Error(callerId === RENOVATE_SYNC_JOB_ID ? `${CI_PATH}: the job ${RENOVATE_SYNC_JOB_ID} calls ci-node.yml, but that id is reserved for the job calling ci-renovate-sync.yml. Rename it, then rerun antelopejs-sync.` : `${CI_PATH}: a job named ${RENOVATE_SYNC_JOB_ID} already exists and does not call ci-renovate-sync.yml. Rename or merge it, then rerun antelopejs-sync.`);
|
|
123
215
|
}
|
|
124
216
|
/**
|
|
125
217
|
* Keeps the shared CI caller on the job id `ci` with no `name`, so the shared workflow reports `ci / checks`,
|
|
126
|
-
* dispatchable and
|
|
127
|
-
*
|
|
218
|
+
* dispatchable and read-only, with the Renovate sync it would otherwise run turned off. The write permissions the sync
|
|
219
|
+
* needs to push and dispatch the caller live on a separate job calling ci-renovate-sync.yml, which is added when missing.
|
|
220
|
+
* No `uses:` ref is ever rewritten. A workflow with no caller job is repository-specific CI and is left as it is.
|
|
128
221
|
*/
|
|
129
|
-
function ciWorkflow(current, callers) {
|
|
222
|
+
function ciWorkflow(current, callers, syncCallers) {
|
|
130
223
|
if (current === void 0) return CI_CALLER;
|
|
131
224
|
if (!callers.length) return current;
|
|
132
225
|
const document = parseDocument(current);
|
|
@@ -134,7 +227,7 @@ function ciWorkflow(current, callers) {
|
|
|
134
227
|
const jobs = document.get("jobs", true);
|
|
135
228
|
if (!isMap(jobs)) return current;
|
|
136
229
|
const caller = callers.find(({ id }) => id === "ci") ?? callers[0];
|
|
137
|
-
|
|
230
|
+
assertNoClash(jobs, caller.id, syncCallers.length > 0);
|
|
138
231
|
const pair = jobs.items.find(({ key }) => isScalar(key) && key.value === caller.id);
|
|
139
232
|
if (!pair || !isMap(pair.value)) return current;
|
|
140
233
|
let changed = false;
|
|
@@ -147,18 +240,19 @@ function ciWorkflow(current, callers) {
|
|
|
147
240
|
renameNeeds(document, caller.id, "ci");
|
|
148
241
|
changed = true;
|
|
149
242
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
actions: "write"
|
|
154
|
-
}));
|
|
155
|
-
changed = true;
|
|
156
|
-
}
|
|
243
|
+
changed = grant(document, pair.value, { contents: "read" }) || changed;
|
|
244
|
+
changed = skipRenovateSync(document, pair.value) || changed;
|
|
245
|
+
changed = ensureSyncJob(document, jobs, syncCallers) || changed;
|
|
157
246
|
if (!hasDispatch(document)) {
|
|
158
247
|
addDispatch(document);
|
|
159
248
|
changed = true;
|
|
160
249
|
}
|
|
161
|
-
|
|
250
|
+
if (!changed) return current;
|
|
251
|
+
blockOverflowingFlow(document);
|
|
252
|
+
return document.toString({
|
|
253
|
+
lineWidth: 0,
|
|
254
|
+
flowCollectionPadding: false
|
|
255
|
+
});
|
|
162
256
|
}
|
|
163
257
|
//#endregion
|
|
164
|
-
export {
|
|
258
|
+
export { MUTATION_PATH as a, MISSING_CHECKS_WORKFLOW as c, hasChecksWorkflow as d, CI_RENOVATE_SYNC_REF as i, ciNodeCallers as l, CI_NODE_REF as n, ciWorkflow as o, CI_PATH as r, mutationCaller as s, CI_CONTEXT as t, ciRenovateSyncCallers as u };
|
package/dist/verify/index.d.mts
CHANGED
|
@@ -37,7 +37,7 @@ type BehaviourMethod = {
|
|
|
37
37
|
interface FormalCheck {
|
|
38
38
|
name: string;
|
|
39
39
|
covers: string[];
|
|
40
|
-
/** Globs of the check's own files (its model, its tests): a diff that changes one
|
|
40
|
+
/** Globs of the check's own files (its model, its tests): a diff that changes one runs the check, even when no covered file changed, and also runs it on the base. */
|
|
41
41
|
files?: string[];
|
|
42
42
|
/** Runs from the repository root; exits 0 while every finding breaks as recorded. */
|
|
43
43
|
command: string[];
|
|
@@ -171,7 +171,7 @@ interface JourneyContext {
|
|
|
171
171
|
service(name: string): ServiceEndpoint;
|
|
172
172
|
/** Runs a command inside a service's container: the read-back through the native client. */
|
|
173
173
|
native(name: string, service: string, args: string[]): Promise<CommandResult>;
|
|
174
|
-
/** Writes the fixture project of the interface or module kind and returns its folder. */
|
|
174
|
+
/** Writes the fixture project of the interface or module kind and returns its folder. Each call writes a fresh project, so a journey can hold several. */
|
|
175
175
|
fixture(options?: {
|
|
176
176
|
moduleConfig?: JsonObject;
|
|
177
177
|
}): string;
|
|
@@ -197,8 +197,8 @@ interface InterfaceCall<Api> {
|
|
|
197
197
|
}
|
|
198
198
|
/** Repo-owned hooks of the interface kind for contracts that are not interface proxies. */
|
|
199
199
|
interface InterfaceHooks<Api> {
|
|
200
|
-
/** Runs in the stub provider module after the generic stubs attach, for example to call `internal.SetClient
|
|
201
|
-
provide?(api: Api): void | Promise<void>;
|
|
200
|
+
/** Runs in the stub provider module after the generic stubs attach, for example to call `internal.SetClient`; `services` are the run's backing services as they answer from the host. */
|
|
201
|
+
provide?(api: Api, services: ServiceEndpoint[]): void | Promise<void>;
|
|
202
202
|
/** Plain exported functions, by path such as `.:GetClient`, called by the driver module. */
|
|
203
203
|
calls?: {
|
|
204
204
|
[path: string]: InterfaceCall<Api>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/tooling-configs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "Shared tooling presets for AntelopeJS repositories: oxlint (with the vendored anti-slop rules), oxfmt, ESLint for Nuxt layers, Knip, and an interface range check",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|