@mark1russell7/site-pages 0.7.2 → 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 CHANGED
@@ -226,18 +226,20 @@ The gate has three rules. A fault of one rule gives the exit code 1.
226
226
 
227
227
  1. Each page names a run, and each run has an id, a link, a date and its engine versions.
228
228
  2. The data of a page is at most 3 days old (`MAX_DATA_AGE_DAYS`), or a run on newer engines is in flight. The stamp of that run is at most 3 days old, so an old stamp does not hold the gate open.
229
- 3. The engines of the newest run are at most 1 minor version behind npm at the start of the run (`MAX_MINORS_BEHIND`). A release during a long run does not fail the gate.
229
+ 3. The engines of the newest run are at most 1 minor version behind npm at the start of the run (`MAX_MINORS_BEHIND`). A release during a long run does not fail the gate. An engine that is a package of the same repository has its version from its `package.json` at the build commit, not from npm. The gate reads each `package.json` that git tracks.
230
230
 
231
- Stamps that pass also show one failing case for each page, in the log of each build. A measured page must fail one day after its limit, and after the start of its limit. A study with no limit must fail before the date of its run. A page with no failing case gives the exit code 1, so each site that uses the gate shows that the gate holds it.
231
+ For an engine of the same repository, a break of rule 3 is a warning for 3 days (`VERSION_GRACE_DAYS`). The 3 days start at the commit that raised the version past the limit. Then the break is a fault, and the failing case is the end of the grace. The rule starts on 2026-11-30 (`WORKSPACE_RULE_START`). Before that start, each break is a warning. In a shallow clone, the gate cannot find the commit, so a break has no grace.
232
+
233
+ Stamps that pass also show one failing case for each page, in the log of each build. The case is the first time at which the gate fails on the page. A measured page must fail one day after the limit of its data. When the data is old at the start of the limit, it fails at that start. A study with no limit must fail before the date of its run. A page with no failing case gives the exit code 1, so each site that uses the gate shows that the gate holds it.
232
234
 
233
235
  Two fields of a stamp change the age rule:
234
236
 
235
237
  - `"study": true` marks a study of the versions of its runs. The rule 3 does not apply. A study has a `limit`, or it has the field `noLimit`. Each other study fails the gate.
236
238
  - `"noLimit"` is for a study that no scheduled run can refresh: `{ "reproduce": "The code of the study is gone.", "today": "The page tells of one day." }`. The first text tells why no run of the current code can reproduce the numbers. It names the subject of the study, pinned to an exact version. The second text tells why the page claims nothing about today. The stamp line shows both, and tells that the page is a fixed study of that version.
237
239
  - `"limit"` sets a longer age limit: `{ "days": 7, "reason": "The scan is weekly.", "workflow": ".github/workflows/scan.yml" }`. The stamp line shows the limit and the reason. The schedule of that workflow must meet the limit, or the gate fails. A limit with no schedule fails. A limit over 14 days (`MAX_LIMIT_DAYS_WITHOUT_RULING`) also needs a `ruling`, a public https link for that site. A study has the same line, and its limit is at most 30 days (`MAX_STUDY_LIMIT_DAYS`), also with a ruling. Each run of the study names the full `commit` of the code that ran. A monthly line has a gap of 31 days, so it fails a limit of 30.
238
- - `"startsAt"` in a limit is the time at which the age rule and the commit rule start. The schedule rule applies at once. A site removes the field at the first green read of its workflow. The gate refuses a time after 2026-12-07 (`LAST_LIMIT_START`), so each limit turns on by that date.
240
+ - `"startsAt"` in a limit is the time at which the age rule and the commit rule start. Before it, a break of these rules is a warning: `::warning::` in GitHub Actions. The start does not change the age, which is always the time of the check minus the date of the data. The schedule rule applies at once. A site removes the field at the first green read of its workflow. The gate refuses a time after 2026-12-07 (`LAST_LIMIT_START`), so each limit turns on by that date.
239
241
 
240
- When npm does not answer, the gate prints the rule 3 under `Not run` and does not fail. A workflow turns the gate on with the input `data-stamps` of `reusable-pages.yml`. A site with its own Pages workflow uses the action `data-stamps` of the template. The gate then runs from the template commit, so it needs no install.
242
+ When npm does not answer for an engine that is not a package of the repository, the gate prints the rule 3 under `Not run`. It does not fail. A workflow turns the gate on with the input `data-stamps` of `reusable-pages.yml`. A site with its own Pages workflow uses the action `data-stamps` of the template. The gate then runs from the template commit, so it needs no install.
241
243
 
242
244
  `renderDataStamp(stamp)` gives the line that the page shows with its data: the run, its date, its engine versions and the run in flight. The line also shows the age of the oldest run at the build.
243
245
 
@@ -633,7 +635,7 @@ Two functions read a measure from GitHub at the build. Each result has the `at`
633
635
  | Function | Measure |
634
636
  | --- | --- |
635
637
  | `githubGreenRun({ owner, repo, token, workflow })` | The scheduled runs of a workflow that passed in a row, from the newest run |
636
- | `githubReleaseLag({ owner, repo, token, tagPrefix, branch })` | The age in days of the oldest commit of the first-parent line of the branch that is not in the newest release of the tag prefix. A merge commit counts at its own date. Drafts and pre-releases do not count. |
638
+ | `githubReleaseLag({ owner, repo, token, tagPrefix, branch, paths })` | The age in days of the oldest commit of the first-parent line of the branch that is not in the newest release of the tag prefix. A merge commit counts at its own date. Drafts and pre-releases do not count. With `paths` (for example `["packages/", "!packages/site/"]`), only a commit that changes a file in the paths counts. The last entry that matches a file decides. |
637
639
 
638
640
  ## The shell of a site
639
641
 
@@ -1,4 +1,4 @@
1
- import { A as readKpi, B as npmPublishTimes, E as KpiError, F as headingDate, H as kindOf, I as isShallow, L as originRepository, N as gitTagDates, P as headCommit, S as plural, U as parseVersion, V as compareVersions, W as versionOfTag, _ as iconLink, b as link, v as escapeHtml, w as KPI_FILE, x as listText, y as inlineMarkdown } from "./freshness.js";
1
+ import { C as listText, E as KPI_FILE, F as gitTagDates, G as parseVersion, H as npmPublishTimes, I as headCommit, K as versionOfTag, L as headingDate, M as readKpi, O as KpiError, R as isShallow, S as link, U as compareVersions, W as kindOf, b as escapeHtml, w as plural, x as inlineMarkdown, y as iconLink, z as originRepository } from "./freshness.js";
2
2
  import { stripTypeScriptTypes } from "node:module";
3
3
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
4
4
  import { basename, dirname, isAbsolute, join, posix, resolve } from "node:path";
@@ -576,22 +576,42 @@ function compareCommit(value) {
576
576
  }
577
577
  /**
578
578
  * This function follows the first-parent line of `commits` from its tip. `commits` are the commits of a branch that a tag does
579
- * not contain. The function gives the commit date and the first parent of the oldest commit of that line. The tip is the one
580
- * commit that is not a parent of another commit of the list. The function gives undefined for no commit, and null when the list
581
- * has no single tip.
579
+ * not contain. The function gives the commits of that line, the tip first and the oldest last. The tip is the one commit that is
580
+ * not a parent of another commit of the list. The function gives an empty list for no commit, and null when the list has no
581
+ * single tip.
582
582
  */
583
- function oldestFirstParent(commits) {
584
- if (commits.length === 0) return void 0;
583
+ function firstParentLine(commits) {
584
+ if (commits.length === 0) return [];
585
585
  const bySha = new Map(commits.map((commit) => [commit.sha, commit]));
586
586
  const parents = new Set(commits.flatMap((commit) => commit.parents));
587
587
  const tips = commits.filter((commit) => !parents.has(commit.sha));
588
588
  if (tips.length !== 1 || tips[0] === void 0) return null;
589
- let line = tips[0];
590
- for (let next = bySha.get(line.parents[0] ?? ""); next !== void 0; next = bySha.get(next.parents[0] ?? "")) line = next;
591
- return {
592
- date: line.date,
593
- parent: line.parents[0] ?? ""
594
- };
589
+ const line = [tips[0]];
590
+ for (let next = bySha.get(tips[0].parents[0] ?? ""); next !== void 0; next = bySha.get(next.parents[0] ?? "")) line.push(next);
591
+ return line;
592
+ }
593
+ /** GitHub lists at most this many files of one comparison. A list of this length can be cut. */
594
+ const COMPARE_FILES = 300;
595
+ /** The most commits of the first-parent line that `githubReleaseLag` reads one at a time for the option `paths`. */
596
+ const COMMIT_READS = 100;
597
+ /** This function gives the paths of the files of a comparison of GitHub. A renamed file gives its new path and its old path. */
598
+ function filePaths(files) {
599
+ return files.flatMap((file) => [text(object(file)["filename"]), text(object(file)["previous_filename"])].filter((path) => path !== ""));
600
+ }
601
+ /**
602
+ * This function tells if a file is in the entries of the option `paths` of `githubReleaseLag`. An entry is a file or a folder of
603
+ * the repository, and an entry that starts with `!` takes its files out. The last entry that matches a file decides, as in a
604
+ * `.gitignore` file. A file that no entry matches is not in the paths.
605
+ */
606
+ function inPaths(paths, file) {
607
+ let found = false;
608
+ for (const entry of paths) {
609
+ const out = entry.startsWith("!");
610
+ const raw = (out ? entry.slice(1) : entry).replace(/^(?:\.\/|\/)+/, "").replace(/\/+$/, "");
611
+ const path = raw === "." ? "" : raw;
612
+ if (path === "" || file === path || file.startsWith(`${path}/`)) found = !out;
613
+ }
614
+ return found;
595
615
  }
596
616
  /**
597
617
  * This function reads how many days a branch is ahead of its newest release. That is the age of the oldest commit of the
@@ -607,9 +627,22 @@ function oldestFirstParent(commits) {
607
627
  * that is not on that line gives `{ available: false, reason }`. So a merge commit counts at the time of the merge, not at the older
608
628
  * dates of the commits that it brings. A commit that lands after the tag and before the release is published counts, because it
609
629
  * is not in the release. The time of the release does not decide.
630
+ *
631
+ * The option `paths` counts only the commits that change a file in the paths, for example the folders of the packages that a
632
+ * release publishes. An entry is a file or a folder, and an entry that starts with `!` takes its files out. The last entry that
633
+ * matches a file decides. Then the age is that of the oldest commit of the line that changes such a file. When no file of the
634
+ * comparison is in the paths, the age is 0, with no more requests. Else the function reads the commits of the line one at a
635
+ * time, the oldest first, at most 100. It stops at the first commit that changes a file in the paths. A commit that a later
636
+ * commit reverts still counts while the branch has another change in the paths. Paths with no entry that adds files give
637
+ * `{ available: false, reason }`. So does a commit that changes 300 files or more with no file in the paths, because GitHub
638
+ * lists only 300 files of a comparison.
610
639
  */
611
640
  async function githubReleaseLag(options) {
612
- const { owner, repo, token = "", tagPrefix, branch = "main", endpoint = GITHUB_API, timeoutMs = 15e3 } = options;
641
+ const { owner, repo, token = "", tagPrefix, branch = "main", endpoint = GITHUB_API, timeoutMs = 15e3, paths } = options;
642
+ if (paths !== void 0 && !paths.some((entry) => !entry.startsWith("!"))) return {
643
+ available: false,
644
+ reason: "the option paths has no entry that adds files"
645
+ };
613
646
  const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d+Z$/, "Z");
614
647
  const wanted = (release) => !release.prerelease && release.tag.startsWith(tagPrefix);
615
648
  const releases = await readReleasePages(options, wanted);
@@ -633,6 +666,7 @@ async function githubReleaseLag(options) {
633
666
  const commits = [];
634
667
  let ahead = 0;
635
668
  let base = "";
669
+ let range;
636
670
  for (let page = 0; url !== null; page++) {
637
671
  if (page === COMPARE_PAGES) return {
638
672
  available: false,
@@ -661,6 +695,7 @@ async function githubReleaseLag(options) {
661
695
  };
662
696
  ahead = typeof body["ahead_by"] === "number" ? body["ahead_by"] : 0;
663
697
  base = text(object(body["merge_base_commit"])["sha"]);
698
+ range = body["files"];
664
699
  }
665
700
  for (const value of listed) commits.push(compareCommit(value));
666
701
  url = linkedPage(response.headers.get("link"), "next");
@@ -669,15 +704,29 @@ async function githubReleaseLag(options) {
669
704
  available: false,
670
705
  reason: `GitHub listed ${commits.length} of the ${ahead} commits after ${release.tag}`
671
706
  };
672
- const oldest = oldestFirstParent(commits);
673
- if (oldest === null) return {
707
+ const line = firstParentLine(commits);
708
+ if (line === null) return {
674
709
  available: false,
675
710
  reason: `the commits after ${release.tag} have no single tip`
676
711
  };
677
- if (oldest !== void 0 && oldest.parent !== base) return {
712
+ const last = line.at(-1);
713
+ if (last !== void 0 && (last.parents[0] ?? "") !== base) return {
678
714
  available: false,
679
715
  reason: `the tag ${release.tag} is not on the first-parent line of ${branch}`
680
716
  };
717
+ let oldest = last;
718
+ if (paths !== void 0) {
719
+ const found = await oldestInPaths(line, range, paths, release.tag, async (from, to) => {
720
+ const response = await read(`${endpoint}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/compare/${encodeURIComponent(from)}...${encodeURIComponent(to)}?per_page=1`);
721
+ if (!response.ok) return { reason: `GitHub answered with HTTP ${response.status} for the commit ${to.slice(0, 7)}` };
722
+ return { files: object(await response.json())["files"] };
723
+ });
724
+ if (found !== void 0 && "reason" in found) return {
725
+ available: false,
726
+ reason: found.reason
727
+ };
728
+ oldest = found;
729
+ }
681
730
  if (oldest?.date === "") return {
682
731
  available: false,
683
732
  reason: "the oldest commit has no date"
@@ -698,6 +747,23 @@ async function githubReleaseLag(options) {
698
747
  }
699
748
  }
700
749
  /**
750
+ * This function gives the oldest commit of a first-parent line that changes a file in `paths`. It gives undefined when no commit
751
+ * of the line changes one. `line` has the tip first, and `range` is the list of files of the comparison of the tag with the tip.
752
+ * `files` reads the list of files of one commit against its first parent. The function gives a reason when it cannot tell.
753
+ */
754
+ async function oldestInPaths(line, range, paths, tag, files) {
755
+ if (Array.isArray(range) && range.length < COMPARE_FILES && !filePaths(range).some((file) => inPaths(paths, file))) return void 0;
756
+ const oldestFirst = [...line].reverse();
757
+ for (const [index, commit] of oldestFirst.entries()) {
758
+ if (index === COMMIT_READS) return { reason: `the first ${COMMIT_READS} commits after ${tag} change no file in the paths` };
759
+ const read = await files(commit.parents[0] ?? "", commit.sha);
760
+ if ("reason" in read) return read;
761
+ if (!Array.isArray(read.files)) return { reason: `GitHub gave no list of files for the commit ${commit.sha.slice(0, 7)}` };
762
+ if (filePaths(read.files).some((file) => inPaths(paths, file))) return commit;
763
+ if (read.files.length >= COMPARE_FILES) return { reason: `the commit ${commit.sha.slice(0, 7)} changes ${COMPARE_FILES} files or more, and GitHub lists only ${COMPARE_FILES}` };
764
+ }
765
+ }
766
+ /**
701
767
  * This function counts the runs that passed in a row, from the newest run. A run that has not ended does not count and does not break the row.
702
768
  * Each other conclusion breaks the row, a cancelled run too. It gives null when no run ended.
703
769
  *