@mark1russell7/site-pages 0.7.3 → 0.8.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 +6 -4
- package/build/chunks/build.js +1 -1
- package/build/chunks/data-stamp.js +1 -1
- package/build/chunks/freshness.d.ts +35 -17
- package/build/chunks/freshness.d.ts.map +1 -1
- package/build/chunks/freshness.js +322 -110
- package/build/chunks/freshness.js.map +1 -1
- package/build/cli.js +1 -1
- package/build/index.d.ts +14 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/vite.d.ts +1 -1
- package/build/vite.js +1 -1
- package/package.json +1 -1
|
@@ -194,6 +194,134 @@ function headingDate(repoDir, version, file) {
|
|
|
194
194
|
function versionCommitTime(repoDir, file) {
|
|
195
195
|
return git(repoDir, "log", "-1", "--format=%cI", "-G^\\s*\"version\":", "HEAD", "--", file)?.trim() || null;
|
|
196
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* This function reads each object `<commit>:<path>` with one process of `git cat-file --batch`. It gives the text of each
|
|
199
|
+
* object, or undefined for an object that git does not have.
|
|
200
|
+
*/
|
|
201
|
+
function readObjects(top, specs) {
|
|
202
|
+
if (specs.length === 0) return [];
|
|
203
|
+
let out;
|
|
204
|
+
try {
|
|
205
|
+
out = execFileSync("git", ["cat-file", "--batch"], {
|
|
206
|
+
cwd: top,
|
|
207
|
+
input: `${specs.join("\n")}\n`,
|
|
208
|
+
maxBuffer: 1 << 28,
|
|
209
|
+
stdio: [
|
|
210
|
+
"pipe",
|
|
211
|
+
"pipe",
|
|
212
|
+
"ignore"
|
|
213
|
+
],
|
|
214
|
+
windowsHide: true
|
|
215
|
+
});
|
|
216
|
+
} catch {
|
|
217
|
+
return specs.map(() => void 0);
|
|
218
|
+
}
|
|
219
|
+
const texts = [];
|
|
220
|
+
let at = 0;
|
|
221
|
+
for (let index = 0; index < specs.length; index += 1) {
|
|
222
|
+
const end = out.indexOf(10, at);
|
|
223
|
+
if (end < 0) {
|
|
224
|
+
texts.push(void 0);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const size = /^[0-9a-f]+ blob (\d+)$/.exec(out.toString("utf8", at, end))?.[1];
|
|
228
|
+
if (size === void 0) {
|
|
229
|
+
texts.push(void 0);
|
|
230
|
+
at = end + 1;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
texts.push(out.toString("utf8", end + 1, end + 1 + Number(size)));
|
|
234
|
+
at = end + 1 + Number(size) + 1;
|
|
235
|
+
}
|
|
236
|
+
return texts;
|
|
237
|
+
}
|
|
238
|
+
/** This function gives the name and the version of the text of a `package.json`, or undefined. */
|
|
239
|
+
function manifestOf(text) {
|
|
240
|
+
if (text === void 0) return void 0;
|
|
241
|
+
let manifest;
|
|
242
|
+
try {
|
|
243
|
+
manifest = JSON.parse(text);
|
|
244
|
+
} catch {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (manifest === null || typeof manifest !== "object") return void 0;
|
|
248
|
+
const { name, version } = manifest;
|
|
249
|
+
return typeof name === "string" && typeof version === "string" && parseVersion(version) !== null ? {
|
|
250
|
+
name,
|
|
251
|
+
version
|
|
252
|
+
} : void 0;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* This function gives the versions of each package of the repository, by its name, from each `package.json` that git
|
|
256
|
+
* tracks at `HEAD`. In CI, `HEAD` is the build commit.
|
|
257
|
+
*
|
|
258
|
+
* The first version is the version at `HEAD`, and each next version is older. Each version has the time of the commit
|
|
259
|
+
* that set it. In a shallow clone, the oldest version has no time. For two packages with one name, the function keeps
|
|
260
|
+
* the package with the higher version. A move of a file starts its history again. Outside a repository, it gives no package.
|
|
261
|
+
*/
|
|
262
|
+
function workspaceVersions(repoDir) {
|
|
263
|
+
const top = git(repoDir, "rev-parse", "--show-toplevel")?.trim();
|
|
264
|
+
if (!top) return {};
|
|
265
|
+
const paths = (git(top, "ls-files", "-z", "--", ":(glob)**/package.json") ?? "").split("\0").filter((path) => path !== "" && !path.includes("\n"));
|
|
266
|
+
const heads = readObjects(top, paths.map((path) => `HEAD:${path}`));
|
|
267
|
+
const chosen = /* @__PURE__ */ new Map();
|
|
268
|
+
paths.forEach((path, index) => {
|
|
269
|
+
const manifest = manifestOf(heads[index]);
|
|
270
|
+
if (manifest === void 0) return;
|
|
271
|
+
const old = chosen.get(manifest.name);
|
|
272
|
+
if (old === void 0 || compareVersions(manifest.version, old.version) > 0) chosen.set(manifest.name, {
|
|
273
|
+
path,
|
|
274
|
+
version: manifest.version
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
const files = [...chosen.values()].map(({ path }) => path);
|
|
278
|
+
const log = files.length === 0 ? "" : git(top, "-c", "core.quotePath=false", "log", "--format=%x00%H %cI", "--name-only", "-G\"version\"\\s*:", "HEAD", "--", ...files.map((path) => `:(literal)${path}`)) ?? "";
|
|
279
|
+
const commits = /* @__PURE__ */ new Map();
|
|
280
|
+
for (const entry of log.split("\0")) {
|
|
281
|
+
const [head = "", ...names] = entry.split("\n");
|
|
282
|
+
const [sha, date] = head.split(" ");
|
|
283
|
+
if (sha === void 0 || date === void 0 || Number.isNaN(Date.parse(date))) continue;
|
|
284
|
+
for (const name of names) {
|
|
285
|
+
if (name === "") continue;
|
|
286
|
+
let list = commits.get(name);
|
|
287
|
+
if (list === void 0) {
|
|
288
|
+
list = [];
|
|
289
|
+
commits.set(name, list);
|
|
290
|
+
}
|
|
291
|
+
list.push({
|
|
292
|
+
sha,
|
|
293
|
+
date: new Date(date).toISOString()
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const texts = readObjects(top, files.flatMap((path) => (commits.get(path) ?? []).map(({ sha }) => `${sha}:${path}`)));
|
|
298
|
+
const shallow = isShallow(top);
|
|
299
|
+
const versions = /* @__PURE__ */ new Map();
|
|
300
|
+
let next = 0;
|
|
301
|
+
for (const [name, { path, version }] of chosen) {
|
|
302
|
+
const list = commits.get(path) ?? [];
|
|
303
|
+
const history = [{ version }];
|
|
304
|
+
let complete = true;
|
|
305
|
+
for (const [index, commit] of list.entries()) {
|
|
306
|
+
const at = manifestOf(texts[next + index])?.version;
|
|
307
|
+
const current = history.at(-1);
|
|
308
|
+
if (at === void 0 || current === void 0) {
|
|
309
|
+
complete = false;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
if (at === current.version) current.since = commit.date;
|
|
313
|
+
else history.push({
|
|
314
|
+
version: at,
|
|
315
|
+
since: commit.date
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
next += list.length;
|
|
319
|
+
const oldest = history.at(-1);
|
|
320
|
+
if (shallow && complete && oldest !== void 0) delete oldest.since;
|
|
321
|
+
versions.set(name, history);
|
|
322
|
+
}
|
|
323
|
+
return Object.fromEntries(versions);
|
|
324
|
+
}
|
|
197
325
|
/** This function gives the full SHA of `HEAD`, or null. */
|
|
198
326
|
function headCommit(repoDir) {
|
|
199
327
|
const sha = git(repoDir, "rev-parse", "HEAD")?.trim();
|
|
@@ -512,14 +640,105 @@ function hasIconLink(html) {
|
|
|
512
640
|
function iconLink(href = SITE_ICON_HREF) {
|
|
513
641
|
return `<link rel="icon" href="${escapeHtml(href)}">`;
|
|
514
642
|
}
|
|
643
|
+
// src/check/schedule.ts
|
|
644
|
+
/**
|
|
645
|
+
* The reader of the schedules of a workflow: each line `cron:`, and the largest gap between its starts.
|
|
646
|
+
* The freshness gate and the rules of conventions use it.
|
|
647
|
+
* This file imports nothing, so a change of the freshness gate does not change the build of a package that reads schedules.
|
|
648
|
+
*/
|
|
649
|
+
const DAY_MS$1 = 864e5;
|
|
650
|
+
/** This function gives the values of one field of a cron line, or undefined for a form that it cannot read. */
|
|
651
|
+
function cronValues(field, low, high) {
|
|
652
|
+
const values = /* @__PURE__ */ new Set();
|
|
653
|
+
for (const part of field.split(",")) {
|
|
654
|
+
const match = /^(\*|\d+(?:-\d+)?)(?:\/(\d+))?$/.exec(part);
|
|
655
|
+
if (match === null) return void 0;
|
|
656
|
+
const [, range = "", step = "1"] = match;
|
|
657
|
+
const [from = low, to = from] = range === "*" ? [low, high] : range.split("-").map(Number);
|
|
658
|
+
const by = Number(step);
|
|
659
|
+
if (by <= 0 || from < low || to > high || from > to) return void 0;
|
|
660
|
+
for (let value = from; value <= to; value += by) values.add(value);
|
|
661
|
+
}
|
|
662
|
+
return values;
|
|
663
|
+
}
|
|
664
|
+
/** This function gives the start of each day of a cron line, in a span of two years. It gives undefined for a line that it cannot read. */
|
|
665
|
+
function cronDays(line, from, days) {
|
|
666
|
+
const fields = line.trim().split(/\s+/);
|
|
667
|
+
if (fields.length !== 5) return void 0;
|
|
668
|
+
const [minute = "", hour = "", dayOfMonth = "", month = "", dayOfWeek = ""] = fields;
|
|
669
|
+
const minutes = cronValues(minute, 0, 59);
|
|
670
|
+
const hours = cronValues(hour, 0, 23);
|
|
671
|
+
const monthDays = cronValues(dayOfMonth, 1, 31);
|
|
672
|
+
const months = cronValues(month, 1, 12);
|
|
673
|
+
const weekDays = cronValues(dayOfWeek, 0, 6);
|
|
674
|
+
if (minutes === void 0 || hours === void 0 || monthDays === void 0 || months === void 0 || weekDays === void 0) return void 0;
|
|
675
|
+
const firstTime = (Math.min(...hours) * 60 + Math.min(...minutes)) * 6e4;
|
|
676
|
+
const starts = [];
|
|
677
|
+
for (let day = 0; day < days; day += 1) {
|
|
678
|
+
const time = from + day * DAY_MS$1;
|
|
679
|
+
const date = new Date(time);
|
|
680
|
+
if (!months.has(date.getUTCMonth() + 1)) continue;
|
|
681
|
+
const onMonthDay = monthDays.has(date.getUTCDate());
|
|
682
|
+
const onWeekDay = weekDays.has(date.getUTCDay());
|
|
683
|
+
if (dayOfMonth !== "*" && dayOfWeek !== "*" ? onMonthDay || onWeekDay : onMonthDay && onWeekDay) starts.push(time + firstTime);
|
|
684
|
+
}
|
|
685
|
+
return starts;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* This function gives each line `cron:` of a workflow. It is the one reader of these lines: the freshness gate and the rule `runner-budget` of conventions use it.
|
|
689
|
+
* It skips a comment line. It reads a quoted key, a list item, a quoted value and a comment at the end of the line.
|
|
690
|
+
*/
|
|
691
|
+
function cronLines(workflow) {
|
|
692
|
+
return workflow.split(/\r?\n/).flatMap((raw, index) => {
|
|
693
|
+
const text = raw.trim().replace(/^- */, "");
|
|
694
|
+
const key = [
|
|
695
|
+
"cron:",
|
|
696
|
+
"\"cron\":",
|
|
697
|
+
"'cron':"
|
|
698
|
+
].find((form) => text.startsWith(form));
|
|
699
|
+
if (key === void 0) return [];
|
|
700
|
+
const rest = text.slice(key.length);
|
|
701
|
+
const comment = rest.search(/\s#/);
|
|
702
|
+
const value = (comment >= 0 ? rest.slice(0, comment) : rest).trim();
|
|
703
|
+
const quote = value.charAt(0);
|
|
704
|
+
const quoted = value.length >= 2 && (quote === "\"" || quote === "'") && value.endsWith(quote);
|
|
705
|
+
return [{
|
|
706
|
+
line: index + 1,
|
|
707
|
+
cron: quoted ? value.slice(1, -1).trim() : value
|
|
708
|
+
}];
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* This function gives the largest gap between the scheduled starts of a workflow, in days. The gap counts from the first start of a day.
|
|
713
|
+
* It gives a text in place of the gap for a workflow with no schedule, and for a line that it cannot read. The text names the line, and the gate fails on it.
|
|
714
|
+
*/
|
|
715
|
+
function scheduleGapDays(workflow) {
|
|
716
|
+
const lines = cronLines(workflow).map((item) => item.cron);
|
|
717
|
+
if (lines.length === 0) return "the workflow has no line `cron:`";
|
|
718
|
+
const from = Date.UTC(2027, 0, 1);
|
|
719
|
+
const span = 731;
|
|
720
|
+
const starts = [];
|
|
721
|
+
for (const line of lines) {
|
|
722
|
+
const days = cronDays(line, from, span);
|
|
723
|
+
if (days === void 0) return `the gate cannot read the line \`cron: ${line}\``;
|
|
724
|
+
starts.push(...days);
|
|
725
|
+
}
|
|
726
|
+
if (starts.length < 2) return `the lines \`cron: ${lines.join("`, `cron: ")}\` give fewer than two starts in two years`;
|
|
727
|
+
starts.sort((a, b) => a - b);
|
|
728
|
+
let largest = 0;
|
|
729
|
+
for (let index = 1; index < starts.length; index += 1) largest = Math.max(largest, ((starts[index] ?? 0) - (starts[index - 1] ?? 0)) / DAY_MS$1);
|
|
730
|
+
return largest;
|
|
731
|
+
}
|
|
515
732
|
// src/check/freshness.ts
|
|
516
733
|
/**
|
|
517
734
|
* The freshness gate of a measured page. A site keeps a file of data stamps.
|
|
518
735
|
* Each stamp names the page, its runs, their dates and their engine versions.
|
|
519
736
|
* The gate fails on a page with no versions or no run date, and on old data with no newer run in flight.
|
|
520
|
-
* The gate also fails on a run
|
|
737
|
+
* The gate also fails on a run behind the engines on npm, or behind a package of the repository at the build commit.
|
|
738
|
+
*
|
|
739
|
+
* Old data before the start of its limit gives a warning, and the gate fails on it from that start.
|
|
521
740
|
* A study has an age limit and a scheduled workflow, or it says why it needs no limit. A page with a longer limit names the reason and the workflow.
|
|
522
|
-
* This file imports only Node.js
|
|
741
|
+
* This file imports only Node.js, the folder `data` and `schedule.ts`, so `reusable-pages.yml` starts it with no npm release of the package.
|
|
523
742
|
*/
|
|
524
743
|
/** The schema of a file of data stamps. */
|
|
525
744
|
const DATA_STAMP_SCHEMA = "data-stamp/1";
|
|
@@ -533,6 +752,10 @@ const MAX_LIMIT_DAYS_WITHOUT_RULING = 14;
|
|
|
533
752
|
const MAX_STUDY_LIMIT_DAYS = 30;
|
|
534
753
|
/** The last time at which a limit can start. A limit turns on at this time if its site did not turn it on before. */
|
|
535
754
|
const LAST_LIMIT_START = "2026-12-07T00:00:00Z";
|
|
755
|
+
/** The days after the commit that raised a package of the repository past the limit, before a fault. A rerun needs that time. */
|
|
756
|
+
const VERSION_GRACE_DAYS = 3;
|
|
757
|
+
/** The start of the version rule for an engine of the same repository. Before it, a break of that rule is a warning. */
|
|
758
|
+
const WORKSPACE_RULE_START = "2026-11-30T00:00:00Z";
|
|
536
759
|
const DAY_MS = 864e5;
|
|
537
760
|
/** The form of a full commit. */
|
|
538
761
|
const FULL_COMMIT = /^[0-9a-f]{40}$/;
|
|
@@ -655,88 +878,6 @@ function latestAt(times, name, date) {
|
|
|
655
878
|
return times.filter((t) => t.name === name && Date.parse(t.date) <= limit && parseVersion(t.version)?.prerelease.length === 0).map((t) => t.version).sort(compareVersions).at(-1);
|
|
656
879
|
}
|
|
657
880
|
const ageInDays = (date, now) => (now - Date.parse(date)) / DAY_MS;
|
|
658
|
-
/** This function gives the values of one field of a cron line, or undefined for a form that it cannot read. */
|
|
659
|
-
function cronValues(field, low, high) {
|
|
660
|
-
const values = /* @__PURE__ */ new Set();
|
|
661
|
-
for (const part of field.split(",")) {
|
|
662
|
-
const match = /^(\*|\d+(?:-\d+)?)(?:\/(\d+))?$/.exec(part);
|
|
663
|
-
if (match === null) return void 0;
|
|
664
|
-
const [, range = "", step = "1"] = match;
|
|
665
|
-
const [from = low, to = from] = range === "*" ? [low, high] : range.split("-").map(Number);
|
|
666
|
-
const by = Number(step);
|
|
667
|
-
if (by <= 0 || from < low || to > high || from > to) return void 0;
|
|
668
|
-
for (let value = from; value <= to; value += by) values.add(value);
|
|
669
|
-
}
|
|
670
|
-
return values;
|
|
671
|
-
}
|
|
672
|
-
/** This function gives the start of each day of a cron line, in a span of two years. It gives undefined for a line that it cannot read. */
|
|
673
|
-
function cronDays(line, from, days) {
|
|
674
|
-
const fields = line.trim().split(/\s+/);
|
|
675
|
-
if (fields.length !== 5) return void 0;
|
|
676
|
-
const [minute = "", hour = "", dayOfMonth = "", month = "", dayOfWeek = ""] = fields;
|
|
677
|
-
const minutes = cronValues(minute, 0, 59);
|
|
678
|
-
const hours = cronValues(hour, 0, 23);
|
|
679
|
-
const monthDays = cronValues(dayOfMonth, 1, 31);
|
|
680
|
-
const months = cronValues(month, 1, 12);
|
|
681
|
-
const weekDays = cronValues(dayOfWeek, 0, 6);
|
|
682
|
-
if (minutes === void 0 || hours === void 0 || monthDays === void 0 || months === void 0 || weekDays === void 0) return void 0;
|
|
683
|
-
const firstTime = (Math.min(...hours) * 60 + Math.min(...minutes)) * 6e4;
|
|
684
|
-
const starts = [];
|
|
685
|
-
for (let day = 0; day < days; day += 1) {
|
|
686
|
-
const time = from + day * DAY_MS;
|
|
687
|
-
const date = new Date(time);
|
|
688
|
-
if (!months.has(date.getUTCMonth() + 1)) continue;
|
|
689
|
-
const onMonthDay = monthDays.has(date.getUTCDate());
|
|
690
|
-
const onWeekDay = weekDays.has(date.getUTCDay());
|
|
691
|
-
if (dayOfMonth !== "*" && dayOfWeek !== "*" ? onMonthDay || onWeekDay : onMonthDay && onWeekDay) starts.push(time + firstTime);
|
|
692
|
-
}
|
|
693
|
-
return starts;
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* This function gives each line `cron:` of a workflow. It is the one reader of these lines: the freshness gate and the rule `runner-budget` of conventions use it.
|
|
697
|
-
* It skips a comment line. It reads a quoted key, a list item, a quoted value and a comment at the end of the line.
|
|
698
|
-
*/
|
|
699
|
-
function cronLines(workflow) {
|
|
700
|
-
return workflow.split(/\r?\n/).flatMap((raw, index) => {
|
|
701
|
-
const text = raw.trim().replace(/^- */, "");
|
|
702
|
-
const key = [
|
|
703
|
-
"cron:",
|
|
704
|
-
"\"cron\":",
|
|
705
|
-
"'cron':"
|
|
706
|
-
].find((form) => text.startsWith(form));
|
|
707
|
-
if (key === void 0) return [];
|
|
708
|
-
const rest = text.slice(key.length);
|
|
709
|
-
const comment = rest.search(/\s#/);
|
|
710
|
-
const value = (comment >= 0 ? rest.slice(0, comment) : rest).trim();
|
|
711
|
-
const quote = value.charAt(0);
|
|
712
|
-
const quoted = value.length >= 2 && (quote === "\"" || quote === "'") && value.endsWith(quote);
|
|
713
|
-
return [{
|
|
714
|
-
line: index + 1,
|
|
715
|
-
cron: quoted ? value.slice(1, -1).trim() : value
|
|
716
|
-
}];
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
/**
|
|
720
|
-
* This function gives the largest gap between the scheduled starts of a workflow, in days. The gap counts from the first start of a day.
|
|
721
|
-
* It gives a text in place of the gap for a workflow with no schedule, and for a line that it cannot read. The text names the line, and the gate fails on it.
|
|
722
|
-
*/
|
|
723
|
-
function scheduleGapDays(workflow) {
|
|
724
|
-
const lines = cronLines(workflow).map((item) => item.cron);
|
|
725
|
-
if (lines.length === 0) return "the workflow has no line `cron:`";
|
|
726
|
-
const from = Date.UTC(2027, 0, 1);
|
|
727
|
-
const span = 731;
|
|
728
|
-
const starts = [];
|
|
729
|
-
for (const line of lines) {
|
|
730
|
-
const days = cronDays(line, from, span);
|
|
731
|
-
if (days === void 0) return `the gate cannot read the line \`cron: ${line}\``;
|
|
732
|
-
starts.push(...days);
|
|
733
|
-
}
|
|
734
|
-
if (starts.length < 2) return `the lines \`cron: ${lines.join("`, `cron: ")}\` give fewer than two starts in two years`;
|
|
735
|
-
starts.sort((a, b) => a - b);
|
|
736
|
-
let largest = 0;
|
|
737
|
-
for (let index = 1; index < starts.length; index += 1) largest = Math.max(largest, ((starts[index] ?? 0) - (starts[index - 1] ?? 0)) / DAY_MS);
|
|
738
|
-
return largest;
|
|
739
|
-
}
|
|
740
881
|
/** This function tells if a run uses a newer version of an engine than another run. */
|
|
741
882
|
function hasNewerEngine(run, than) {
|
|
742
883
|
return Object.entries(run.engines).some(([name, version]) => {
|
|
@@ -744,28 +885,70 @@ function hasNewerEngine(run, than) {
|
|
|
744
885
|
return old !== void 0 && compareVersions(version, old) > 0;
|
|
745
886
|
});
|
|
746
887
|
}
|
|
888
|
+
/** This function gives the newest run of a stamp: the run in flight, or else the run with the latest date. */
|
|
889
|
+
function newestRun(stamp) {
|
|
890
|
+
return stamp.inFlight ?? [...stamp.runs].sort((a, b) => Date.parse(a.date) - Date.parse(b.date)).at(-1);
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* This function gives each engine of a run that is more than `maxMinorsBehind` behind its package in the repository. The
|
|
894
|
+
* gate fails on a break `graceDays` after the commit that raised the package past the limit, and not before `startsAt`.
|
|
895
|
+
*/
|
|
896
|
+
function ownBreaks(run, workspace, maxMinorsBehind, graceDays, startsAt) {
|
|
897
|
+
const breaks = [];
|
|
898
|
+
for (const [name, version] of Object.entries(run.engines)) {
|
|
899
|
+
const history = Object.hasOwn(workspace, name) ? workspace[name] ?? [] : [];
|
|
900
|
+
const own = history[0];
|
|
901
|
+
if (own === void 0 || minorsBehind(version, own.version) <= maxMinorsBehind) continue;
|
|
902
|
+
let raised;
|
|
903
|
+
for (const entry of history) {
|
|
904
|
+
if (minorsBehind(version, entry.version) <= maxMinorsBehind) break;
|
|
905
|
+
raised = entry.since;
|
|
906
|
+
if (raised === void 0) break;
|
|
907
|
+
}
|
|
908
|
+
const start = Date.parse(startsAt);
|
|
909
|
+
const failsAt = raised === void 0 ? start : Math.max(start, Date.parse(raised) + graceDays * DAY_MS);
|
|
910
|
+
breaks.push({
|
|
911
|
+
name,
|
|
912
|
+
version,
|
|
913
|
+
own: own.version,
|
|
914
|
+
failsAt,
|
|
915
|
+
known: raised !== void 0
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
return breaks;
|
|
919
|
+
}
|
|
747
920
|
/**
|
|
748
921
|
* This function applies the rules of the gate to the stamps.
|
|
749
922
|
*
|
|
750
923
|
* - The data of each page is at most `maxAgeDays` old, or a run on newer engines is in flight.
|
|
751
924
|
* - The engines of the newest run are at most `maxMinorsBehind` behind npm at the start of that run.
|
|
925
|
+
* - An engine that is a package of the repository is at most `maxMinorsBehind` behind its version at the build commit.
|
|
926
|
+
* The gate fails on a break `versionGraceDays` after the commit that raised the version, and not before `workspaceStartsAt`.
|
|
927
|
+
* Before that time, the break is a warning.
|
|
752
928
|
* - A run in flight has the same age limit, so an old stamp does not hold the gate open.
|
|
753
929
|
* - A page with its own limit uses that limit, and the schedule of its workflow meets the limit.
|
|
754
930
|
* - A study has no limit of the engines, because it tells about the versions that it names.
|
|
755
931
|
* - A study with a limit in force names the commit of each run. A study with no limit has no age rule.
|
|
756
|
-
* - A limit with `startsAt` applies the age rule and the commit rule from that time.
|
|
932
|
+
* - A limit with `startsAt` applies the age rule and the commit rule from that time. Before it, each break is a warning.
|
|
933
|
+
* The age is always the time of the check minus the date of the data. The schedule rule applies at once.
|
|
757
934
|
*/
|
|
758
935
|
function checkFreshness(stamps, options) {
|
|
759
|
-
const { times, maxAgeDays: defaultAge = 3, maxMinorsBehind = 1, schedules = {} } = options;
|
|
936
|
+
const { times, maxAgeDays: defaultAge = 3, maxMinorsBehind = 1, schedules = {}, workspace = {} } = options;
|
|
937
|
+
const { versionGraceDays = 3, workspaceStartsAt = WORKSPACE_RULE_START } = options;
|
|
760
938
|
const now = Date.parse(options.now);
|
|
761
939
|
const faults = [];
|
|
762
940
|
const notRun = [];
|
|
941
|
+
const warnings = [];
|
|
763
942
|
for (const stamp of stamps.pages) {
|
|
764
943
|
for (const run of [...stamp.runs, ...stamp.inFlight === void 0 ? [] : [stamp.inFlight]]) if (ageInDays(run.date, now) < 0) faults.push(`${stamp.page}: the run ${run.id} has a date after the check.`);
|
|
765
944
|
if (stamp.study === true && stamp.limit === void 0) continue;
|
|
766
945
|
const maxAgeDays = stamp.limit?.days ?? defaultAge;
|
|
767
946
|
const startsAt = stamp.limit?.startsAt;
|
|
768
947
|
const inForce = startsAt === void 0 || Date.parse(startsAt) <= now;
|
|
948
|
+
const atStart = (text) => {
|
|
949
|
+
if (inForce) faults.push(text);
|
|
950
|
+
else warnings.push(`${text} The gate fails on it from ${String(startsAt)}.`);
|
|
951
|
+
};
|
|
769
952
|
if (stamp.limit !== void 0) {
|
|
770
953
|
const gap = schedules[stamp.limit.workflow];
|
|
771
954
|
if (gap === void 0 || typeof gap === "string") faults.push(`${stamp.page}: the limit of ${maxAgeDays} days has no schedule that the gate can read in ${stamp.limit.workflow}: ${gap ?? "the check has no read of this workflow"}.`);
|
|
@@ -776,50 +959,71 @@ function checkFreshness(stamps, options) {
|
|
|
776
959
|
if (flight !== void 0 && !flying) faults.push(`${stamp.page}: the run ${flight.id} is in flight for more than ${maxAgeDays} days.`);
|
|
777
960
|
for (const run of stamp.runs) {
|
|
778
961
|
const age = ageInDays(run.date, now);
|
|
779
|
-
if (
|
|
962
|
+
if (age > maxAgeDays && !(flying && hasNewerEngine(flight, run))) atStart(`${stamp.page}: the run ${run.id} is ${age.toFixed(1)} days old, over the limit of ${maxAgeDays}, and no run on newer engines is in flight.`);
|
|
780
963
|
}
|
|
781
964
|
if (stamp.study === true) {
|
|
782
|
-
if (
|
|
783
|
-
for (const run of stamp.runs) if (run.commit === void 0) faults.push(`${stamp.page}: the run ${run.id} names no commit.`);
|
|
784
|
-
}
|
|
965
|
+
for (const run of stamp.runs) if (run.commit === void 0) atStart(`${stamp.page}: the run ${run.id} names no commit.`);
|
|
785
966
|
continue;
|
|
786
967
|
}
|
|
787
|
-
const newest =
|
|
968
|
+
const newest = newestRun(stamp);
|
|
788
969
|
if (newest === void 0) continue;
|
|
970
|
+
for (const own of ownBreaks(newest, workspace, maxMinorsBehind, versionGraceDays, workspaceStartsAt)) {
|
|
971
|
+
const text = `${stamp.page}: the run ${newest.id} used ${own.name} ${own.version}, and the repository has ${own.own} at the build commit. The limit is ${maxMinorsBehind} minor version behind.`;
|
|
972
|
+
if (now < own.failsAt) warnings.push(`${text} The gate fails on it from ${new Date(own.failsAt).toISOString()}.`);
|
|
973
|
+
else if (own.known) faults.push(text);
|
|
974
|
+
else faults.push(`${text} The clone has no commit that tells when the version passed the limit, so the page has no grace.`);
|
|
975
|
+
}
|
|
789
976
|
for (const [name, version] of Object.entries(newest.engines)) {
|
|
977
|
+
if (Object.hasOwn(workspace, name)) continue;
|
|
790
978
|
const latest = latestAt(times, name, newest.date);
|
|
791
|
-
if (latest === void 0) notRun.push(`${stamp.page}: npm gives no version of ${name} at the start of the run ${newest.id}.`);
|
|
979
|
+
if (latest === void 0) notRun.push(`${stamp.page}: npm gives no version of ${name} at the start of the run ${newest.id}, and no package of the repository has that name.`);
|
|
792
980
|
else if (minorsBehind(version, latest) > maxMinorsBehind) faults.push(`${stamp.page}: the run ${newest.id} used ${name} ${version}, and npm had ${latest} at its start. The limit is ${maxMinorsBehind} minor version behind.`);
|
|
793
981
|
}
|
|
794
982
|
}
|
|
795
983
|
return {
|
|
796
984
|
faults,
|
|
797
|
-
notRun
|
|
985
|
+
notRun,
|
|
986
|
+
warnings
|
|
798
987
|
};
|
|
799
988
|
}
|
|
800
989
|
/**
|
|
801
|
-
* This function gives one failing case for each page, from the stamps of the site itself.
|
|
802
|
-
*
|
|
803
|
-
*
|
|
990
|
+
* This function gives one failing case for each page, from the stamps of the site itself. The case is the first time at
|
|
991
|
+
* which the gate fails on the page. That time is one day after the limit of a run or of the run in flight. When the data is
|
|
992
|
+
* old at the start of the limit, the time is that start. The age always counts from the date of the data. For a version
|
|
993
|
+
* break of an engine of the same repository, the time is the end of its grace.
|
|
994
|
+
*
|
|
995
|
+
* A study with no limit must fail before the date of its run. Stamps that pass and give a case with no fault tell that the
|
|
996
|
+
* gate does not examine that page.
|
|
804
997
|
*/
|
|
805
998
|
function failingCases(stamps, options) {
|
|
806
999
|
return stamps.pages.map((stamp) => {
|
|
1000
|
+
const only = {
|
|
1001
|
+
schema: stamps.schema,
|
|
1002
|
+
pages: [stamp]
|
|
1003
|
+
};
|
|
807
1004
|
const dates = [...stamp.runs, ...stamp.inFlight === void 0 ? [] : [stamp.inFlight]].map((run) => Date.parse(run.date));
|
|
808
1005
|
const days = stamp.limit?.days ?? options.maxAgeDays ?? 3;
|
|
809
1006
|
const from = Math.max(Date.parse(options.now), Date.parse(stamp.limit?.startsAt ?? options.now));
|
|
810
|
-
const
|
|
811
|
-
const
|
|
812
|
-
const [
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
1007
|
+
const newest = newestRun(stamp);
|
|
1008
|
+
const graces = stamp.study === true || newest === void 0 ? [] : ownBreaks(newest, options.workspace ?? {}, options.maxMinorsBehind ?? 1, options.versionGraceDays ?? 3, options.workspaceStartsAt ?? "2026-11-30T00:00:00Z").map((one) => one.failsAt);
|
|
1009
|
+
const later = [...dates.map((date) => date + (days + 1) * DAY_MS), ...graces].filter((time) => time > from).sort((a, b) => a - b);
|
|
1010
|
+
const candidates = stamp.study === true && stamp.limit === void 0 ? [Math.min(...dates) - DAY_MS] : [from, ...later];
|
|
1011
|
+
let at = "";
|
|
1012
|
+
for (const time of candidates) {
|
|
1013
|
+
at = new Date(time).toISOString();
|
|
1014
|
+
const [fault] = checkFreshness(only, {
|
|
1015
|
+
...options,
|
|
1016
|
+
now: at
|
|
1017
|
+
}).faults;
|
|
1018
|
+
if (fault !== void 0) return {
|
|
1019
|
+
page: stamp.page,
|
|
1020
|
+
at,
|
|
1021
|
+
fault
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
819
1024
|
return {
|
|
820
1025
|
page: stamp.page,
|
|
821
|
-
at
|
|
822
|
-
...fault === void 0 ? {} : { fault }
|
|
1026
|
+
at
|
|
823
1027
|
};
|
|
824
1028
|
});
|
|
825
1029
|
}
|
|
@@ -834,6 +1038,10 @@ Examine the data stamps of the measured pages of a site.
|
|
|
834
1038
|
|
|
835
1039
|
The exit code is 0 when the stamps pass, 1 for a fault, and 2 for an incorrect command line.
|
|
836
1040
|
Stamps that pass also show one failing case for each page. A page with no failing case is a fault.
|
|
1041
|
+
An engine that is a package of the repository has its version from its package.json at the build commit, not from npm.
|
|
1042
|
+
A version break of such an engine warns until 3 days after the commit that raised the version.
|
|
1043
|
+
That rule starts at ${WORKSPACE_RULE_START}. Before it, each break of that rule is a warning.
|
|
1044
|
+
Old data before the start of its limit gives a warning, and the gate fails on it from that start.
|
|
837
1045
|
`;
|
|
838
1046
|
/** This function gives the largest gap of the schedule in a workflow file. It gives a text for a file that it cannot read. */
|
|
839
1047
|
function readSchedule(path) {
|
|
@@ -881,7 +1089,8 @@ async function runFreshnessCli(argv, io, fetcher) {
|
|
|
881
1089
|
for (const fault of parsed.faults) io.stderr(`${fault}\n`);
|
|
882
1090
|
return 1;
|
|
883
1091
|
}
|
|
884
|
-
const
|
|
1092
|
+
const workspace = workspaceVersions(io.cwd);
|
|
1093
|
+
const engines = parsed.stamps.pages.filter((p) => p.study !== true).flatMap((p) => [...p.runs, ...p.inFlight === void 0 ? [] : [p.inFlight]]).flatMap((r) => Object.keys(r.engines)).filter((name) => !Object.hasOwn(workspace, name));
|
|
885
1094
|
const schedules = {};
|
|
886
1095
|
for (const page of parsed.stamps.pages) if (page.limit !== void 0) schedules[page.limit.workflow] = readSchedule(join(io.cwd, page.limit.workflow));
|
|
887
1096
|
const npm = await npmPublishTimes({
|
|
@@ -891,10 +1100,13 @@ async function runFreshnessCli(argv, io, fetcher) {
|
|
|
891
1100
|
const options = {
|
|
892
1101
|
now: values.now ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
893
1102
|
times: npm.times,
|
|
894
|
-
schedules
|
|
1103
|
+
schedules,
|
|
1104
|
+
workspace
|
|
895
1105
|
};
|
|
896
1106
|
const result = checkFreshness(parsed.stamps, options);
|
|
897
1107
|
for (const problem of [...npm.problems, ...result.notRun]) io.stdout(`Not run: ${problem}\n`);
|
|
1108
|
+
const warning = io.env["GITHUB_ACTIONS"] === "true" ? "::warning::" : "Warning: ";
|
|
1109
|
+
for (const text of result.warnings) io.stdout(`${warning}${text}\n`);
|
|
898
1110
|
for (const fault of result.faults) io.stderr(`${fault}\n`);
|
|
899
1111
|
if (result.faults.length > 0) return 1;
|
|
900
1112
|
io.stdout(`The data stamps of ${parsed.stamps.pages.length} ${parsed.stamps.pages.length === 1 ? "page" : "pages"} pass.\n`);
|
|
@@ -905,6 +1117,6 @@ async function runFreshnessCli(argv, io, fetcher) {
|
|
|
905
1117
|
} else io.stdout(`Failing case at ${at}: ${fault}\n`);
|
|
906
1118
|
return held ? 0 : 1;
|
|
907
1119
|
}
|
|
908
|
-
export {
|
|
1120
|
+
export { kpiProblems as A, versionCommitTime as B, listText as C, KPI_FORMAT as D, KPI_FILE as E, gitTagDates as F, parseVersion as G, npmPublishTimes as H, headCommit as I, versionOfTag as K, headingDate as L, readKpi as M, writeKpi as N, KpiError as O, git as P, isShallow as R, link as S, safeUrl as T, compareVersions as U, NPM_REGISTRY as V, kindOf as W, SITE_ICON_SVG as _, MAX_MINORS_BEHIND as a, escapeHtml as b, WORKSPACE_RULE_START as c, latestAt as d, minorsBehind as f, SITE_ICON_HREF as g, cronLines as h, MAX_LIMIT_DAYS_WITHOUT_RULING as i, kpiText as j, kpiFile as k, checkFreshness as l, runFreshnessCli as m, LAST_LIMIT_START as n, MAX_STUDY_LIMIT_DAYS as o, parseDataStamps as p, MAX_DATA_AGE_DAYS as r, VERSION_GRACE_DAYS as s, DATA_STAMP_SCHEMA as t, failingCases as u, hasIconLink as v, plural as w, inlineMarkdown as x, iconLink as y, originRepository as z };
|
|
909
1121
|
|
|
910
1122
|
//# sourceMappingURL=freshness.js.map
|