Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .github/scripts/fork-follow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ schema_check "$base" "The series"
# and the next run (from the new base) would refuse it. So the series gets a commit that lowers each
# one (#325); a count that rose is still refused, as raising one is the owner's review.
seam_refusal="Fork changes to upstream files must stay within the seam lines"
# What a lowering commit changed, for the run's summary: written only once the plan has finished,
# as a later check can still stop it and then nothing is pushed.
lowered_summary=()
seam_run() { # seam_run BASE [--after-rebase]: the check's exit status; its output in seam-check.log
local status=0 lower=()
rm -f "$logs/seam-lowered.json"
Expand All @@ -213,17 +216,15 @@ seam_check() { # seam_check BASE WHAT [--after-rebase]
git add -- .github/fork-seams.json
as_fork commit -q -m "fork seams: lower counts after the rebase onto $target_tag" -m "$lowered"
printf '%s\n' "$2 lowered the seam list (.github/fork-seams.json) in a commit of its own:" "$lowered" >&2
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
printf '%s\n' "### Seam list lowered: $2" "" "$lowered" "" \
"Committed into the series; the fork lines or upstream lines these counted are gone." \
"" >> "$GITHUB_STEP_SUMMARY"
fi
lowered_summary=("### Seam list lowered: $2" "" "$lowered" "" \
"Committed on top of the rebased series (the candidate); the fork lines or upstream lines these counted are gone." "")
# The lowered list is judged again: it must pass and lower nothing more.
status=0
seam_run "$1" ${3:+"$3"} || status=$?
if ((status == 0)) && [[ -f "$logs/seam-lowered.json" ]]; then
fail "The seam list fork-follow lowered still lowers again, so it was not committed as checked:" \
"$(quoted "$(cat "$logs/seam-check.log")")" "" "The series was left as it is."
fail "$2 needed a lower seam list, and the list fork-follow lowered still lowers again, so the run stopped:" \
"$(quoted "$lowered")" "" "The check of the lowered list said:" \
"$(quoted "$(cat "$logs/seam-check.log")")" "" "The lowering commit was made in this run's checkout only; the series was left as it is."
fi
fi
if ((status == 0)); then
Expand Down Expand Up @@ -617,3 +618,7 @@ new_workflows "$base" "$target"
echo "own_workflows=$own_list"
echo "new_workflows=$new_list"
} >> "$OUTPUT"
# The plan has finished: the lowering commit is in the candidate it hands on.
if ((${#lowered_summary[@]})) && [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
printf '%s\n' "${lowered_summary[@]}" >> "$GITHUB_STEP_SUMMARY"
fi
79 changes: 79 additions & 0 deletions .github/scripts/fork-follow.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,85 @@ plan
check "plan: the next run from the new base passes the lowered list" \
eval 'action_is release && [[ ! -e "$root/report.md" ]] && hasnt "Note: " "$root/out"'

# #510: the same rebase again. An earlier run published the candidate with its lowering commit,
# then could not move the series: the next run lowers again (a new commit, the same files) and
# advances to that release instead of building another.
adopted() { # the fork's pending line in u2.txt, which upstream v0.1.11 adopts word for word
new_upstream
new_fork v0.1.10
amend_fork '{"files":{},"pending":{"u2.txt":1}}' 'echo "fork pending line" >> u2.txt'
up_release v0.1.11 'echo "fork pending line" >> u2.txt'
}
amend_fork() { # amend_fork LIST CMD: the fork's commit gets LIST as its seam list and the change CMD makes
(cd "$root/work" && printf '%s\n' "$1" > .github/fork-seams.json && eval "$2" \
&& git add -A && git commit -q --amend --no-edit && git push -q --force origin main) > /dev/null 2>&1
}
adopted
plan
released="$(out candidate)"
fork_tag v0.1.11-fork.1 "$released"
work git checkout -q main && work git reset -q --hard "$(series)"
plan
check "plan: re-run of a rebase that lowered the list -> the same files, advance to the earlier release" \
eval 'action_is advance && [[ "$(out candidate)" == "$released" ]] && grep -q "lowered the seam list" "$root/out"'

# The lowered list is checked again and must lower nothing more. A seam check that always lowers
# (in the fork's series, which the plan runs) stops the plan: the report says what was lowered, and
# the run's summary claims no commit, as nothing goes on from here.
adopted
fork_commit "fork: a seam check that always lowers" "cat > .github/scripts/fork-seam-check.cjs << 'JS'
const fs = require('node:fs');
const at = process.argv.indexOf('--lowered-list');
if (at !== -1) {
fs.writeFileSync(process.argv[at + 1], fs.readFileSync('.github/fork-seams.json', 'utf8') + ' ');
console.log('Lowered: u2.txt: always');
}
JS"
summary_before="earlier step line" plan
check "plan: a lowered list that still lowers again stops the plan, naming what was lowered" \
eval '[[ -z "$(out action)" ]] && has "still lowers again" "$root/report.md" && has "^ - u2.txt: always" "$root/report.md" \
&& has "in this run.s checkout only; the series was left as it is" "$root/report.md"'
check "plan: a plan stopped after the lowering puts no lowered list in the step summary" \
eval 'has "earlier step line" "$root/summary.md" && hasnt "Seam list lowered" "$root/summary.md"'

# One count lowered and another raised in the same run: refused, and nothing is lowered or
# committed. m.txt is pending (one fork line) with its "c" moved to the end ("lost" 1/0); upstream
# deletes its own "c", so the moved copy becomes a second fork line and the moved line is gone.
new_upstream
up_release v0.1.11 'printf "%s\n" a b c d e f g h i j k l > m.txt'
new_fork v0.1.11
amend_fork '{"files":{},"pending":{"m.txt":1},"lost":{"m.txt":{"lines":1,"gone":0}}}' \
'printf "%s\n" a b d e f g h i j k l c "fork line" > m.txt'
up_release v0.1.12 'sed -i "/^c$/d" m.txt'
before="$(work_head)"
plan
check "plan: a count lowered and one raised in one run is refused, committing and lowering nothing" \
eval '[[ -z "$(out action)" ]] && has "m.txt: \"pending\" with 2 fork lines, more than its ceiling of 1 after the rebase" "$root/report.md" \
&& hasnt "^Lowered: " "$root/out" && hasnt "Seam list lowered" "$root/summary.md" \
&& [[ "$(git -C "$root/work" log -1 --format=%s)" != "fork seams: lower counts"* && "$(series)" == "$before" ]]'

# A "lost" count lowered through fork-follow, and a pending file left with no fork line that "lost"
# still names: it moves to "files" with no seam line (#510), and the next run passes. The fork
# deletes "c" and "h" and adds one line; upstream deletes "c" too and adopts the fork's line.
new_upstream
up_release v0.1.11 'printf "%s\n" a b c d e f g h i j k l > m.txt'
new_fork v0.1.11
amend_fork '{"files":{},"pending":{"m.txt":1},"lost":{"m.txt":{"lines":2,"gone":2}}}' \
'printf "%s\n" a b d e f g i j k l "fork line" > m.txt'
up_release v0.1.12 'sed -i "/^c$/d" m.txt && echo "fork line" >> m.txt'
plan
check "plan: a lost count and a pending file with no fork line left are lowered in the lowering commit" \
eval 'action_is rebase \
&& grep -qx -- "- m.txt: \"lost\" 2/2 -> 1/1" <<< "$(git -C "$root/work" log -1 --format=%b "$(out candidate)")" \
&& grep -q -- "- m.txt: \"pending\" 1 moved to \"files\" with no seam line" <<< "$(git -C "$root/work" log -1 --format=%b "$(out candidate)")" \
&& [[ "$(node -e "const l = JSON.parse(process.argv[1]); console.log(JSON.stringify([l.pending, l.files[\"m.txt\"].added, l.lost]))" "$(lowered_list)")" == "[{},[],{\"m.txt\":{\"lines\":1,\"gone\":1}}]" ]] \
&& has "### Seam list lowered" "$root/summary.md"'
work git reset -q --hard "$(out candidate)"
work git push -q --force origin HEAD:main
plan
check "plan: the next run passes the list with the file moved to files" \
eval 'action_is release && [[ ! -e "$root/report.md" ]] && hasnt "Note: " "$root/out"'

in_candidate() { git -C "$root/work" cat-file -e "$(out candidate):.github/workflows/$1" 2> /dev/null; }

new_upstream
Expand Down
114 changes: 87 additions & 27 deletions .github/scripts/fork-seam-check.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ function findSeamBreaches(files, { atBase, atHead, atTip, upstream = false, toda
const allowance = counts.get(line) ?? 0;
return upstream ? allowance : Math.max(0, allowance - spent(line));
};
const adds = (copies, line) =>
// The hint only where the base branch's newer copies alone make these too many: judged from
// the merge-base (the copies the announcement allows in date), the branch would pass.
// `counts` is the allowance the copies are judged by: in date for `late`, else `allowed` (an
// expired announcement allows nothing from the merge-base either, so updating would not help).
const adds = (copies, line, added, counts) =>
`${file}: adds ${copies === 1 ? "" : `${copies}× `}\`${line}\`${
(tipCounts.get(line) ?? 0) > (baseCounts.get(line) ?? 0)
(tipCounts.get(line) ?? 0) > (baseCounts.get(line) ?? 0) &&
added <= (counts.get(line) ?? 0) - (baseCounts.get(line) ?? 0)
? " (the base branch has more copies than this branch's merge-base: update the branch from its base)"
: ""
}`;
Expand All @@ -206,10 +211,10 @@ function findSeamBreaches(files, { atBase, atHead, atTip, upstream = false, toda
? "is dated after"
: `is more than ${ANNOUNCED_DAYS} days before`;
lateReasons.push(
`${adds(lateCopies, line)} (its announcement of ${since} ${when} ${today}, the list's commit date: announce it again with a list-only pull request)`,
`${adds(lateCopies, line, added, inDate)} (its announcement of ${since} ${when} ${today}, the list's commit date: announce it again with a list-only pull request)`,
);
}
if (extra > lateCopies) reasons.push(adds(extra - lateCopies, line));
if (extra > lateCopies) reasons.push(adds(extra - lateCopies, line, added, allowed));
}
}
return reasons;
Expand Down Expand Up @@ -256,9 +261,9 @@ const AFTER_REBASE_RISE =

/**
* Changed files outside the seams. An unlisted upstream file may not change or go (unless `removed` names it).
* A "pending" one holds its ceiling from upstream (too high: `ceilings`, after a rebase `notes`; exceeded:
* `rises`); on a PR it may not grow, and a shrink lowers its ceiling in `ownPending` to match.
* `lowered.pending` gets the count each too-high ceiling from upstream lowers to.
* A "pending" one holds its ceiling from upstream (too high: `ceilings`, after a rebase `notes`; exceeded: `rises`;
* `lowered.pending` gets the lowered count). On a PR it may not grow, and a change sets its `ownPending` ceiling to
* exactly what is left, counting upstream lines put back from `ownLost` (none left: it moves to `ownFiles`).
*/
function findUnlistedChanges(
config,
Expand All @@ -271,6 +276,8 @@ function findUnlistedChanges(
removed = new Set(),
afterRebase = false,
ownPending,
ownFiles = {},
ownLost = {},
lowered,
},
) {
Expand Down Expand Up @@ -332,7 +339,7 @@ function findUnlistedChanges(
lowered?.pending.set(file, added);
(afterRebase ? notes : ceilings).push(
added === 0
? `${file}: "pending" with no fork lines left; remove it from the list.`
? `${file}: "pending" with no fork lines left; remove it from the list${Object.hasOwn(config.lost ?? {}, file) ? ' (to "files" with "added": [] while "lost" names it)' : ""}.`
: `${file}: "pending" with ${added} fork lines, fewer than its ceiling of ${ceiling}; lower it to ${added}.`,
);
}
Expand All @@ -343,21 +350,51 @@ function findUnlistedChanges(
reasons.push(
`${file}: "pending" (fork lines to move out), and this change adds ${grows} more line${grows === 1 ? "" : "s"} than it removes.`,
);
} else if (grows < 0 && ownPending !== undefined) {
// Main sits at its ceiling, so a change that moves fork lines out must lower it too, or the next
// run from upstream refuses main and the spare room could later admit a fork line. The change's
// own list is read only for a lower ceiling (never a wider gate). This run cannot tell fork lines
// from upstream's, so the text names both; the run from upstream holds "lost" counts exact.
const want = ceiling + grows;
const own = Object.hasOwn(ownPending, file) ? ownPending[file] : 0;
if (own > Math.max(want, 0)) {
const removes = `${-grows} more line${grows === -1 ? "" : "s"} than it adds (keep upstream's lines; if they are fork lines moved out)`;
continue;
}
if (ownPending === undefined) continue;
// A change sets the ceiling to exactly what is left (too high admits a fork line later; too low
// fails the run from upstream). Fork lines change by lines gained less the change in "gone" (an
// upstream line put back is a fork line fewer); that run holds both "gone" counts exact. The own
// list only refuses, never widens; a list-only change (text unchanged) is not held: it may fix main.
const goneOf = (lost) =>
lost !== undefined && Object.hasOwn(lost, file) ? lost[file].gone : 0;
const mainGone = goneOf(config.lost);
const ownGone = goneOf(ownLost);
const moved = Object.hasOwn(ownFiles, file) && !Object.hasOwn(ownPending, file);
const edited = base !== head;
if (!edited && !moved) continue;
const want = Math.max(edited ? ceiling + grows + ownGone - mainGone : ceiling, 0);
const parts = [];
if (grows < 0) {
parts.push(
`removes ${-grows} more line${grows === -1 ? "" : "s"} than it adds (keep upstream's lines; if they are fork lines moved out)`,
);
}
if (ownGone !== mainGone) {
parts.push(
`its own "lost" names ${ownGone} upstream line${ownGone === 1 ? "" : "s"} gone where main's names ${mainGone} (an upstream line put back is a fork line fewer)`,
);
}
const does = parts.length > 0 ? parts.join(", and ") : "changes its lines";
if (moved) {
// In "files" with "added": [] it may hold no fork line: only an empty file may move there.
if (want > 0) {
ceilings.push(
want > 0
? `${file}: "pending" with a ceiling of ${ceiling}, and this change removes ${removes}: lower it to ${want} in this change's ${CONFIG}.`
: `${file}: "pending" with a ceiling of ${ceiling}, and this change removes ${removes}: remove it from "pending" in this change's ${CONFIG}.`,
`${file}: "pending" with a ceiling of ${ceiling}, and this change ${does}, but moves it to "files" in this change's ${CONFIG} while ${want} fork line${want === 1 ? " is" : "s are"} left: keep it in "pending" with a ceiling of ${want} (only a file with no fork line left moves to "files").`,
);
}
continue;
}
const listed = Object.hasOwn(ownPending, file);
const own = listed ? ownPending[file] : 0;
if (own !== want) {
const has = listed ? `its list has ${own}` : "its list drops it";
ceilings.push(
want > 0
? `${file}: "pending" with a ceiling of ${ceiling}, and this change ${does}: set it to ${want} in this change's ${CONFIG} (${has}; main holds its ceiling exactly).`
: `${file}: "pending" with a ceiling of ${ceiling}, and this change ${does}: remove it from "pending" in this change's ${CONFIG} (${has}).`,
);
}
}
return { reasons, ceilings, rises, notes };
Expand Down Expand Up @@ -768,11 +805,15 @@ function ownListProblem(text) {
}
}

// The "why" of a pending file fork-follow moves to "files" (see lowerList).
const MOVED_WHY =
'Was "pending": fork-follow moved it here once it had no fork line left, as its "lost" entry still counts upstream lines it loses. No seam line: a fork line goes in a file of the fork\'s own.';

/**
* `text` with the counts in `lowered` ({ pending, lost }: Maps of file to count) lowered, as { text, changes },
* or undefined when nothing changes. Only lowers; a count at 0 removes the entry, except a "pending" one a
* "lost" entry still names (that would leave the list malformed). Two-space JSON, parsed again before it is
* returned, so a lowered list is never one the check refuses.
* or undefined when nothing changes. Only lowers; a count at 0 removes the entry. A "pending" file with no fork
* line left that "lost" still names moves to "files" with no seam line (no fork line may come back, no line may
* be lost). Two-space JSON, parsed again before it is returned, so a lowered list is never one the check refuses.
*/
function lowerList(text, lowered) {
const raw = JSON.parse(text);
Expand All @@ -797,12 +838,18 @@ function lowerList(text, lowered) {
});
if (raw.lost !== undefined) raw.lost = Object.fromEntries(lostAfter);
const stillLost = new Set(lostAfter.map(([file]) => file));
const moved = [];
if (raw.pending !== undefined) {
raw.pending = Object.fromEntries(
Object.entries(raw.pending).flatMap(([file, ceiling]) => {
const to = lowered.pending.get(file);
if (to === undefined || to >= ceiling || (to === 0 && stillLost.has(file))) {
return [[file, ceiling]];
if (to === undefined || to >= ceiling) return [[file, ceiling]];
if (to === 0 && stillLost.has(file)) {
changes.push(
`${file}: "pending" ${ceiling} moved to "files" with no seam line (no fork line left; "lost" still counts its upstream lines)`,
);
moved.push(file);
return [];
}
if (to === 0) {
changes.push(`${file}: "pending" ${ceiling} removed (no fork line left)`);
Expand All @@ -813,6 +860,15 @@ function lowerList(text, lowered) {
}),
);
}
// Appended through defineProperty: a file named `__proto__` stays an own key.
for (const file of moved) {
Object.defineProperty(raw.files, file, {
value: { why: MOVED_WHY, added: [] },
enumerable: true,
writable: true,
configurable: true,
});
}
if (changes.length === 0) return undefined;
const lowerText = `${JSON.stringify(raw, null, 2)}\n`;
parseConfig(lowerText);
Expand Down Expand Up @@ -905,9 +961,11 @@ function main(argv) {
// A pull request that moves fork lines out of a "pending" file lowers its ceiling in its own
// list (read only for that: a lower ceiling never widens the gate).
let ownPending;
let ownFiles;
let ownLost;
if (!upstream && listProblem === undefined && ownList !== undefined) {
try {
ownPending = parseConfig(ownList).pending ?? {};
({ pending: ownPending, files: ownFiles, lost: ownLost } = parseConfig(ownList));
} catch {
ownPending = undefined; // The list judged it is main's; a malformed own one is said below.
}
Expand All @@ -923,6 +981,8 @@ function main(argv) {
removed,
afterRebase: parsed.afterRebase,
ownPending,
ownFiles,
ownLost,
lowered,
});
const lost = findLostLines(config, {
Expand Down Expand Up @@ -1022,7 +1082,7 @@ function main(argv) {
}
if (ceilings.length > 0) {
console.error(
`Lower each "pending" ceiling and "lost" count named above (or remove the entry) in ${CONFIG}: in this change's list where the line says so, otherwise with a pull request to main.`,
`Lower each "pending" ceiling and "lost" count named above (or remove the entry, or set the value its line names) in ${CONFIG}: in this change's list where the line says so, otherwise with a pull request to main.`,
);
}
if (late.length > 0) {
Expand Down
Loading
Loading