@antelopejs/tooling-configs 0.2.13 → 0.2.14

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 CHANGED
@@ -45,7 +45,7 @@ The AntelopeJS guardrail pack: shared lint, format and dead-code presets, the co
45
45
  - Without `--json` it prints failures only. The exit code is non-zero only when a check could not run.
46
46
  - `--apply-pauses` sets the repository variable `NEXT_AUTOMERGE` to `shadow` on repositories where it is `on`, when `checks` is red on `next`, the ratchet file is back on a Clean repository, or governance drifted. It never sets `on` and writes nothing else.
47
47
 
48
- `antelopejs-sync` (full profile) writes the weekly mutation caller `.github/workflows/mutation.yml`, and both profiles keep the shared CI caller on the job id `ci`, so the check is reported as `ci / checks`.
48
+ `antelopejs-sync` (full profile) writes the weekly mutation caller `.github/workflows/mutation.yml`, and both profiles keep the shared CI caller on the job id `ci`, so the check is reported as `ci / checks`. The `ci` job is read-only (`contents: read`) and passes `renovate-sync: false`; the `contents: write` and `actions: write` grants that let the Renovate sync push its commit and dispatch the caller live on a separate `renovate-sync` job calling `ci-renovate-sync.yml`, which sync adds when it is missing and never re-pins.
49
49
 
50
50
  ## Shared verification skills
51
51
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { a as isString, c as object, d as optTime, f as parseJson, h as time, i as isObject, l as optNum, m as strings, n as children, o as list, p as str, r as flag, s as num, t as child, u as optStr } from "../json-BqvuCkqr.mjs";
3
3
  import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
4
- import { c as ciNodeCallers, n as CI_NODE_REF, r as CI_PATH, t as CI_CONTEXT } from "../ci-workflow-BDy6hQJ6.mjs";
4
+ import { i as CI_RENOVATE_SYNC_REF, l as ciNodeCallers, n as CI_NODE_REF, r as CI_PATH, t as CI_CONTEXT, u as ciRenovateSyncCallers } from "../ci-workflow-C0nT5SnX.mjs";
5
5
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
6
6
  import { dirname, join } from "node:path";
7
7
  import { execFileSync, spawnSync } from "node:child_process";
@@ -788,6 +788,8 @@ async function ciCaller(context, repo) {
788
788
  const unpinned = callers.filter(({ uses }) => uses !== CI_NODE_REF);
789
789
  if (unpinned.length === callers.length) findings.push(problem(repo, "ci-caller", `${CI_PATH} calls ${unpinned[0].uses}.`, `The caller uses ${CI_NODE_REF}.`));
790
790
  if (!callers.some(({ id, named }) => id === "ci" && !named)) findings.push(problem(repo, "ci-job-id", `The caller job is ${callers[0].id}${callers[0].named ? " with a name" : ""}, so the check is not reported as ${CI_CONTEXT}.`, `antelopejs-sync has renamed the caller job to ci and removed its name.`));
791
+ const syncCallers = ciRenovateSyncCallers(text);
792
+ if (!syncCallers.some(({ uses }) => uses === "AntelopeJS/.github/.github/workflows/ci-renovate-sync.yml@v1")) findings.push(problem(repo, "ci-renovate-sync", syncCallers.length ? `${CI_PATH} calls ${syncCallers[0].uses}.` : `${CI_PATH} has no job calling ci-renovate-sync.yml.`, `${CI_PATH} has a job calling ${CI_RENOVATE_SYNC_REF}.`));
791
793
  return findings;
792
794
  }
793
795
  async function renovateConfig(context, repo) {
package/dist/bin/sync.mjs CHANGED
@@ -5,7 +5,7 @@ import { o as repositoryRoot } from "../files-2FikHZ9F.mjs";
5
5
  import { a as repositoryTools, i as parseManifest, n as managedPackage, o as toolingVersions, r as packageManager, t as execCommand } from "../package-Dtjt_lSa.mjs";
6
6
  import { t as measureBaseline } from "../ratchet-DRdIYwmv.mjs";
7
7
  import { n as SUPPRESSIONS_FILE, r as adoptedBudget } from "../suppression-budget-Yyf5_J5l.mjs";
8
- import { a as ciWorkflow, c as ciNodeCallers, i as MUTATION_PATH, l as hasChecksWorkflow, o as mutationCaller, r as CI_PATH, s as MISSING_CHECKS_WORKFLOW } from "../ci-workflow-BDy6hQJ6.mjs";
8
+ import { a as MUTATION_PATH, c as MISSING_CHECKS_WORKFLOW, d as hasChecksWorkflow, l as ciNodeCallers, o as ciWorkflow, r as CI_PATH, s as mutationCaller, u as ciRenovateSyncCallers } from "../ci-workflow-C0nT5SnX.mjs";
9
9
  import { a as skillFolder, i as isVerifyKind, n as claudeLink, r as claudeLinkTarget, t as VERIFY_KINDS } from "../kinds-Bzyyi9yk.mjs";
10
10
  import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, rmdirSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
11
11
  import { dirname, join, resolve } from "node:path";
@@ -733,7 +733,7 @@ const MANAGED_ARTIFACTS = [
733
733
  path: CI_PATH,
734
734
  profiles: ["full", "template"],
735
735
  desired: (current) => ({
736
- content: ciWorkflow(current, current === void 0 ? [] : ciNodeCallers(current)),
736
+ content: ciWorkflow(current, current === void 0 ? [] : ciNodeCallers(current), current === void 0 ? [] : ciRenovateSyncCallers(current)),
737
737
  notes: []
738
738
  })
739
739
  },
@@ -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
- /** Jobs of a workflow file that call the shared Node CI; empty when the YAML does not parse. */
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 callers = [];
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) && CI_NODE_PATTERN.test(String(uses.value))) callers.push({
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 callers;
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: ${CI_NODE_REF}
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 grantsDispatch(job) {
170
+ function grants(job, expected) {
121
171
  const granted = job.get("permissions", true);
122
- return isMap(granted) && granted.items.length === 2 && granted.get("contents") === "write" && granted.get("actions") === "write";
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 granted the write permissions the renovate-sync job needs to dispatch it.
127
- * A workflow with no caller job is repository-specific CI and is left as it is.
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
- if (caller.id !== "ci" && jobs.has("ci")) throw new Error(`${CI_PATH}: a job named ci already exists besides the ${caller.id} job that calls ci-node.yml. Rename or merge them, then rerun antelopejs-sync.`);
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
- if (!grantsDispatch(pair.value)) {
151
- pair.value.set("permissions", document.createNode({
152
- contents: "write",
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
- return changed ? document.toString({ lineWidth: 0 }) : current;
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 { ciWorkflow as a, ciNodeCallers as c, MUTATION_PATH as i, hasChecksWorkflow as l, CI_NODE_REF as n, mutationCaller as o, CI_PATH as r, MISSING_CHECKS_WORKFLOW as s, CI_CONTEXT as t };
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/tooling-configs",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
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",