GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fork-checks: refuse fork changes to upstream's Orchestrator.ts and ag… · scuttletoby/t3code@71f2b8c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github
    • fork-ci-tests.txt
    • scripts
      • fork-schema-check.cjs
      • fork-schema-check.test.cjs
      • fork-upstream-files-check.cjs
      • fork-upstream-files-check.test.cjs
    • workflows
      • fork-checks.yml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/fork-ci-tests.txt‎

Copy file name to clipboardExpand all lines: .github/fork-ci-tests.txt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
.github/scripts/fork-secret-scan.test.sh
2222
.github/scripts/fork-test-shards.test.cjs
2323
.github/scripts/fork-tests-drift.test.cjs
24+
.github/scripts/fork-upstream-files-check.test.cjs
2425
.github/scripts/fork-workflow-triggers.test.cjs
2526
fork-ci/actions/docs-scope/docs-scope.test.py
2627
fork-ci/actions/fleet-route/fleet_route.test.py
Collapse file

‎.github/scripts/fork-schema-check.cjs‎

Copy file name to clipboardExpand all lines: .github/scripts/fork-schema-check.cjs
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const CHECK_FILES = [
2020
CHECK_SCRIPT,
2121
".github/scripts/fork-schema-check.test.cjs",
2222
".github/workflows/fork-checks.yml",
23+
".github/scripts/fork-upstream-files-check.cjs",
24+
".github/scripts/fork-upstream-files-check.test.cjs",
2325
];
2426
const GITATTRIBUTES = /(^|\/)\.gitattributes$/;
2527

Collapse file

‎.github/scripts/fork-schema-check.test.cjs‎

Copy file name to clipboardExpand all lines: .github/scripts/fork-schema-check.test.cjs
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ test("refuses changes to the check itself and to .gitattributes once the base ha
158158
changed(file, "a", "b"),
159159
);
160160
const reasons = findSchemaChanges(changes, noClosure);
161-
assert.equal(reasons.length, 5);
162-
for (const reason of reasons.slice(0, 3)) assert.match(reason, /Only the owner may do that/);
161+
assert.equal(reasons.length, CHECK_FILES.length + 2);
162+
for (const reason of reasons.slice(0, CHECK_FILES.length)) {
163+
assert.match(reason, /Only the owner may do that/);
164+
}
163165
// The series that first adds the check (base is an upstream tag) may add its files.
164166
assert.equal(findSchemaChanges(changes, { closure: new Set(), baseHasCheck: false }).length, 2);
165167
});
Collapse file

‎.github/scripts/fork-upstream-files-check.cjs‎

Copy file name to clipboard
+105Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Refuses fork changes to listed upstream files, so every upstream sync applies to them cleanly.
2+
// Usage: fork-upstream-files-check.cjs <base> <head> <files>. Judged like fork-schema-check.cjs: the
3+
// diff from the merge-base of <base> and <head>, so upstream changes that reach <base> through
4+
// fork-follow's rebase are never the branch's. Files are read as git tree entries; nothing runs.
5+
6+
const { execFileSync } = require("node:child_process");
7+
const { parseRawDiff } = require("./fork-schema-check.cjs");
8+
9+
function git(args) {
10+
return execFileSync("git", ["-c", "core.quotePath=false", ...args], {
11+
encoding: "utf8",
12+
maxBuffer: 512 * 1024 * 1024,
13+
});
14+
}
15+
16+
/** The tree entry of `file` in `rev` ("<mode> <type> <sha>"), or undefined when absent. */
17+
function entryAt(rev, file) {
18+
const record = git(["ls-tree", "-z", "--full-tree", rev, "--", file]).split("\0")[0];
19+
const match = record.match(/^(\d+ \w+ [0-9a-f]+)\t(.+)$/s);
20+
return match && match[2] === file ? match[1] : undefined;
21+
}
22+
23+
/** The list from the config line(s): paths separated by whitespace, each once. */
24+
const parseList = (args) => [...new Set(args.join(" ").split(/\s+/).filter(Boolean))];
25+
26+
/**
27+
* One reason per refused file. `listed`: the guarded paths. `changed`: paths the branch changes
28+
* (merge-base to head). `atBase`/`atHead`: a path's tree entry there (undefined when absent).
29+
*/
30+
function findUpstreamFileChanges(listed, changed, { atBase, atHead }) {
31+
const reasons = [];
32+
const touched = new Set(changed);
33+
for (const file of listed) {
34+
const base = atBase(file);
35+
// A listed file main does not have guards nothing: the list is out of date (upstream moved or
36+
// removed it). Fail closed, so the guard is never silently empty.
37+
if (base === undefined) {
38+
reasons.push(
39+
`${file}: listed, but main does not have it (upstream moved or removed it?). Update the ` +
40+
"list in .github/workflows/fork-checks.yml; only the owner may do that.",
41+
);
42+
continue;
43+
}
44+
// A directory (or submodule) never shows up as one changed path, so edits inside it would pass.
45+
if (base.split(" ")[1] !== "blob") {
46+
reasons.push(
47+
`${file}: listed, but on main it is not a file. List files only, in ` +
48+
".github/workflows/fork-checks.yml; only the owner may do that.",
49+
);
50+
continue;
51+
}
52+
if (!touched.has(file)) continue;
53+
const head = atHead(file);
54+
// The branch carries main's copy (e.g. it sits on the same upstream as main, reached another
55+
// way): it changes nothing main does not already have.
56+
if (head === base) continue;
57+
const what =
58+
head === undefined
59+
? "deletes or renames it"
60+
: head.split(" ")[2] === base.split(" ")[2]
61+
? "changes its file mode"
62+
: "changes it";
63+
reasons.push(`${file}: this branch ${what}`);
64+
}
65+
return reasons;
66+
}
67+
68+
function main(argv) {
69+
const [base, head, ...rest] = argv;
70+
const listed = parseList(rest);
71+
if (!base || !head || listed.length === 0) {
72+
console.error(
73+
"Usage: fork-upstream-files-check.cjs <base> <head> <files (whitespace-separated)>",
74+
);
75+
return 2;
76+
}
77+
const mergeBase = git(["merge-base", base, head]).trim();
78+
const changed = parseRawDiff(
79+
git(["diff", "--raw", "-z", "--no-abbrev", "--no-renames", "--no-ext-diff", mergeBase, head]),
80+
).map((entry) => entry.path);
81+
const reasons = findUpstreamFileChanges(listed, changed, {
82+
atBase: (file) => entryAt(base, file),
83+
atHead: (file) => entryAt(head, file),
84+
});
85+
if (reasons.length === 0) {
86+
console.log(
87+
`No upstream file changes (${listed.length} listed files, ${changed.length} changed files checked).`,
88+
);
89+
return 0;
90+
}
91+
console.error("Fork changes must leave these upstream files exactly as upstream has them:");
92+
for (const reason of reasons) console.error(`- ${reason}`);
93+
console.error(
94+
"Put the change in a file of the fork's own (its own layer, toolkit or budget file). If this " +
95+
"branch sits on an older main, rebase it onto main first. Only the owner may change these " +
96+
"files: the check stays red, and the owner merges past it.",
97+
);
98+
return 1;
99+
}
100+
101+
module.exports = { findUpstreamFileChanges, parseList };
102+
103+
if (require.main === module) {
104+
process.exitCode = main(process.argv.slice(2));
105+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.