Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .github/release-lines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ pinned:
# v5-topup.yml's exclusions: it is not the branch this workflow watches (v4
# reaches v6 through v5), and v6 is the merge TARGET, not a trigger.
v6-topup.yml: [-v4, -v6]
# Tests the resolver v6-topup.yml runs; it lives on the same one line.
v6-topup-autoresolve-tests.yml: [-v4, -v6]
# Publishes src/crux to hivecommons/crux (#14138). It watches the ONE line
# the published module is cut from — v5, where the nested module lives and
# where `crux/vX.Y.Z` tags are made. v4 is feature-frozen and has no
Expand Down
23 changes: 20 additions & 3 deletions .github/scripts/native-queue-policy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ class ProviderUnavailable extends Error {
}
}

// A provider that completed red on this exact head is that PR's own verdict
// (a missing sign-off, a missing changelog fragment, a failed verifier), never
// a broken admission workflow. Name it as such: four PRs each red on their own
// provider read like one shared incident and got filed as one (#18280). It is
// a hard failure, deliberately not PendingEvidence: waiting cannot change a
// completed verdict, and only a new push to the PR re-runs the providers.
const PROVIDER_VERDICT_NOTE =
'per-PR provider verdict, not a shared CI incident: fix it on this PR; the next push re-evaluates';

class ProviderVerdict extends Error {
constructor(provider, conclusion, head) {
super(`${provider}: ${conclusion} on ${head} (${PROVIDER_VERDICT_NOTE})`);
this.provider = provider;
this.conclusion = conclusion;
}
}

function dcoEnumerationUnavailable(run) {
// This text only classifies a diagnostic, never supplies passing evidence.
// Call only after validating provider, head and completed status.
Expand Down Expand Up @@ -134,7 +151,7 @@ function evidenceForHead(runs, head, checks) {
// Existing PR path scoping legitimately skips technical jobs only. Policy
// proofs, especially external DCO, must have actually succeeded.
const scopedSkip = Object.hasOwn(BUILD_CHECKS, name) && run.conclusion === 'skipped';
if (run.conclusion !== 'success' && !scopedSkip) throw new Error(`${name}: ${run.conclusion}`);
if (run.conclusion !== 'success' && !scopedSkip) throw new ProviderVerdict(name, run.conclusion, head);
return { run, source };
});
}
Expand Down Expand Up @@ -229,7 +246,7 @@ async function assertProwDCO(github, repo, head) {
.sort((a, b) => b.id - a.id)[0];
if (!status) throw new PendingEvidence(`Missing prow ${PROW.context} on ${head}`);
if (status.state === 'pending') throw new PendingEvidence(`prow ${PROW.context} is pending`);
if (status.state !== 'success') throw new Error(`prow ${PROW.context}: ${status.state}`);
if (status.state !== 'success') throw new ProviderVerdict(`prow ${PROW.context}`, status.state, head);
}

async function assertEvidence(github, repo, number, head, checks, pr) {
Expand Down Expand Up @@ -427,7 +444,7 @@ module.exports = {
ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS,
PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate,
isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict, BLOCKED_LABEL,
ProviderUnavailable, FORWARD_MERGE, PROW,
ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, PROW,
DCO_ENUMERATION_SUMMARY_PREFIX, DCO_ENUMERATION_SUMMARY_FALLBACK,
DCO_PROVIDER_UNAVAILABLE_TEXT, DCO_PROVIDER_RUNBOOK,
};
34 changes: 29 additions & 5 deletions .github/scripts/native-queue-policy.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS,
PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate,
isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict,
ProviderUnavailable, FORWARD_MERGE, PROW,
ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, PROW,
DCO_ENUMERATION_SUMMARY_PREFIX,
DCO_ENUMERATION_SUMMARY_FALLBACK,
DCO_PROVIDER_UNAVAILABLE_TEXT,
Expand Down Expand Up @@ -203,7 +203,30 @@ test('UNKNOWN reporting requires trusted exact-head completed DCO and the specif
error => !(error instanceof ProviderUnavailable));
}
assert.throws(() => evidenceForHead([{ ...dco, conclusion: 'failure' }], sha(11), { DCO: null }),
error => !(error instanceof ProviderUnavailable) && error.message === 'DCO: failure');
error => !(error instanceof ProviderUnavailable) && error instanceof ProviderVerdict &&
error.message.startsWith(`DCO: failure on ${sha(11)} `));
});

test('a red provider is named as a per-PR verdict, not a shared CI incident (#18280)', async () => {
for (const [name, conclusion] of [
['DCO', 'action_required'], ['changelog-fragment-guard', 'failure'],
['verify PR contents', 'cancelled'], ['Sign-off survives the squash', 'timed_out'],
]) {
const f = fixture('pull_request_target');
f.state.runs.get(sha(11)).find(r => r.name === name).conclusion = conclusion;
await assert.rejects(evaluate(f), error => {
assert.ok(error instanceof ProviderVerdict, `${name} must be a ProviderVerdict`);
assert.ok(!(error instanceof PendingEvidence), 'a completed verdict is not worth waiting on');
assert.equal(error.provider, name);
assert.equal(error.conclusion, conclusion);
assert.ok(error.message.startsWith(`${name}: ${conclusion} on ${sha(11)} (`), error.message);
assert.ok(error.message.includes(PROVIDER_VERDICT_NOTE), error.message);
return true;
});
}
// A path-scoped skip of a technical job is still not a verdict.
const runs = checks(sha(11), BUILD_CHECKS).map(r => ({ ...r, conclusion: 'skipped' }));
assert.doesNotThrow(() => evidenceForHead(runs, sha(11), BUILD_CHECKS));
});

// #17030: v6-topup.yml's PR whose probot DCO rejects a commit already on v5.
Expand Down Expand Up @@ -277,19 +300,20 @@ test('another head branch, base, fork or author keeps requiring probot DCO', asy
]) {
const f = forwardMergeFixture();
change(f.state.prs[0]);
await assert.rejects(evaluate(f), error => error.message === 'DCO: action_required');
await assert.rejects(evaluate(f), error => error.message === `DCO: action_required on ${sha(11)} (${PROVIDER_VERDICT_NOTE})`);
assert.equal(f.state.seen.length, 0);
}
const v5 = forwardMergeFixture();
v5.state.prs[0].base.ref = 'v5';
v5.context.payload.pull_request.base.ref = 'v5';
await assert.rejects(evaluate(v5), error => error.message === 'DCO: action_required');
await assert.rejects(evaluate(v5), error => error.message === `DCO: action_required on ${sha(11)} (${PROVIDER_VERDICT_NOTE})`);
});

test('forward-merge path fails without a successful prow-created dco status', async () => {
const failed = forwardMergeFixture();
failed.state.statuses.push({ id: 2, context: 'dco', state: 'failure', creator: { login: PROW.login, id: PROW.id } });
await assert.rejects(evaluate(failed), /prow dco: failure.*DCO path: prow dco/);
await assert.rejects(evaluate(failed), error => error instanceof ProviderVerdict &&
/prow dco: failure on .*per-PR provider verdict.*DCO path: prow dco/.test(error.message));
// Any workflow token can post a `dco` status; it never stands in for prow.
const forged = forwardMergeFixture();
forged.state.statuses = [{ id: 3, context: 'dco', state: 'success', creator: { login: 'github-actions[bot]', id: 41898282 } }];
Expand Down
12 changes: 12 additions & 0 deletions .github/scripts/test-native-queue-workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ def test_cosmetic_label_flips_skip_the_evidence_wait(self):
self.assertIn("steps.label-flip.outputs.cosmetic != 'true'", wait["if"])
self.assertLess(steps.index(gate), steps.index(wait))

def test_red_provider_is_reported_not_thrown(self):
# A PR's own red provider must surface as a named per-PR verdict, not
# an "Unhandled error" stack trace that reads like a broken shared
# workflow and gets filed as an incident (#18280).
steps = workflow("native-queue-policy.yml")["jobs"]["policy"]["steps"]
wait = next(s for s in steps if s.get("name", "").startswith("Validate exact-head evidence"))
script = wait["with"]["script"]
self.assertIn("error instanceof ProviderVerdict", script)
verdict = script[script.index("error instanceof ProviderVerdict"):]
self.assertLess(verdict.index("core.setFailed(error.message)"),
verdict.index("instanceof PendingEvidence"))

def test_dependabot_runs_the_same_trusted_pr_verifier(self):
verifier = workflow("pr-verifier.yml")
events = verifier.get("on", verifier.get(True))
Expand Down
113 changes: 113 additions & 0 deletions .github/scripts/test-v6-topup-autoresolve.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env bash
# test-v6-topup-autoresolve.sh — exercises .github/scripts/v6-topup-autoresolve.sh
# against throwaway repositories that reproduce each known v5 -> v6 conflict
# pattern, plus the cases that must still fail for a human.
set -euo pipefail

RESOLVER="$(cd "$(dirname "$0")" && pwd)/v6-topup-autoresolve.sh"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
fail=0

pin_line() { printf "const TRUSTED_SCRIPTS_TREE = '%s';\n" "$1"; }
zeros=0000000000000000000000000000000000000000

# new_repo DIR: a base commit on v5 with the files every pattern touches,
# then a v6 branch. Leaves the repo on v5.
new_repo() {
local d="$1"
git init -q -b v5 "$d"
cd "$d"
git config user.name test
git config user.email test@example.com
mkdir -p .github/scripts src/scripts src/pkg/config src/pkg/dashboard/static-src src/pkg/dashboard/static discord
printf '# Changelog\n\n## Unreleased\n\n## 1.0.0\n\n- base\n' > CHANGELOG.md
{ echo "'use strict';"; pin_line "$zeros"; echo "const OTHER = 1;"; } > .github/scripts/integration-governance.cjs
echo base > src/scripts/a.sh
echo 'package config // base' > src/pkg/config/config.go
printf 'a.html\n# comment\n\nb.html\n' > src/pkg/dashboard/static-src/manifest.txt
echo A > src/pkg/dashboard/static-src/a.html
echo B > src/pkg/dashboard/static-src/b.html
printf 'A\nB\n' > src/pkg/dashboard/static/index.html
echo bot > discord/bot.go
echo other > other.txt
git add -A && git commit -qm base
git checkout -qb v6
git rm -q -r discord && git commit -qm "v6 drops discord"
git checkout -q v5
}

finish_pin() {
# Re-pin both sides honestly so each branch is self-consistent.
local tree
tree="$(git rev-parse HEAD:src/scripts)"
{ echo "'use strict';"; pin_line "$tree"; echo "const OTHER = 1;"; } > .github/scripts/integration-governance.cjs
git add -A && git commit -qm "$1 re-pin"
}

expect() {
local name="$1" want="$2"
shift 2
local rc=0
( "$@" ) >"$WORK/$name.log" 2>&1 || rc=$?
if { [ "$want" = ok ] && [ "$rc" -ne 0 ]; } || { [ "$want" = fail ] && [ "$rc" -eq 0 ]; }; then
echo "FAIL $name (want $want, rc=$rc)"; sed 's/^/ /' "$WORK/$name.log"; fail=1
else
echo "ok $name"
fi
}

case_all_known() {
new_repo "$WORK/known" && cd "$WORK/known"
# v5 side
echo v5bot > discord/bot.go
printf '# Changelog\n\n## Unreleased\n\n## 1.1.0 (v5)\n\n- v5 entry\n\n## 1.0.0\n\n- base\n' > CHANGELOG.md
echo v5 > src/scripts/b.sh
echo 'package config // v5 monolith edit' > src/pkg/config/config.go
echo A5 > src/pkg/dashboard/static-src/a.html
printf 'A5\nB\n' > src/pkg/dashboard/static/index.html
git add -A && git commit -qm v5 && finish_pin v5
# v6 side
git checkout -q v6
printf '# Changelog\n\n## Unreleased\n\n## 6.1.0 (v6)\n\n- v6 entry\n\n## 1.0.0\n\n- base\n' > CHANGELOG.md
echo v6 > src/scripts/c.sh
echo 'package config // v6 slim' > src/pkg/config/config.go
echo B6 > src/pkg/dashboard/static-src/b.html
printf 'A\nB6\n' > src/pkg/dashboard/static/index.html
git add -A && git commit -qm v6 && finish_pin v6
git merge --no-ff -q v5 -m merge >/dev/null 2>&1 && { echo "expected conflicts"; return 1; }
bash "$RESOLVER"
git commit -q --no-edit
[ ! -e discord/bot.go ] || { echo "discord not deleted"; return 1; }
grep -q 'v6 slim' src/pkg/config/config.go || { echo "config.go not v6"; return 1; }
grep -q '6.1.0 (v6)' CHANGELOG.md && grep -q '1.1.0 (v5)' CHANGELOG.md || { echo "changelog lost a side"; return 1; }
! grep -qE '^(<<<<<<<|=======|>>>>>>>)' CHANGELOG.md .github/scripts/integration-governance.cjs || { echo "markers left"; return 1; }
[ "$(cat src/pkg/dashboard/static/index.html)" = "$(printf 'A5\nB6')" ] || { echo "index not regenerated"; return 1; }
grep -qF "$(pin_line "$(git rev-parse HEAD:src/scripts)")" .github/scripts/integration-governance.cjs || { echo "pin not merged tree"; return 1; }
grep -q 'const OTHER = 1;' .github/scripts/integration-governance.cjs || { echo "pin file lost lines"; return 1; }
}

case_unknown_conflict() {
new_repo "$WORK/unknown" && cd "$WORK/unknown"
echo v5 > other.txt && git commit -qam v5
git checkout -q v6 && echo v6 > other.txt && git commit -qam v6
git merge --no-ff -q v5 -m merge >/dev/null 2>&1 || true
bash "$RESOLVER"
}

case_pin_file_real_edit() {
new_repo "$WORK/pinedit" && cd "$WORK/pinedit"
sed -i.bak 's/const OTHER = 1;/const OTHER = 5;/' .github/scripts/integration-governance.cjs && rm -f .github/scripts/integration-governance.cjs.bak
git commit -qam v5
git checkout -q v6
sed -i.bak 's/const OTHER = 1;/const OTHER = 6;/' .github/scripts/integration-governance.cjs && rm -f .github/scripts/integration-governance.cjs.bak
git commit -qam v6
git merge --no-ff -q v5 -m merge >/dev/null 2>&1 || true
bash "$RESOLVER"
}

expect all-known-patterns-resolve ok case_all_known
expect unknown-conflict-refused fail case_unknown_conflict
expect pin-file-real-edit-refused fail case_pin_file_real_edit

exit "$fail"
141 changes: 141 additions & 0 deletions .github/scripts/v6-topup-autoresolve.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env bash
# v6-topup-autoresolve.sh — finish a conflicted v5 -> v6 forward-merge when
# every conflict is one of the known, mechanically resolvable patterns
# (.github/workflows/v6-topup.yml). Run it from the repo root with the merge
# still in progress. Exit 0: every conflict was resolved and staged (the caller
# commits). Exit 1: at least one conflict is not a known pattern, or a known
# file conflicts in a way this script does not recognize; nothing is staged
# that the caller needs to keep (it aborts the merge and reports).
#
# Known patterns:
# - DU discord/** and DU/UD .github/workflows/discord-syntax.yml: v6 removed
# discord/ (#9277) while v5 still develops it. Keep v6's deletion.
# - UU src/pkg/config/config.go: v6 split the monolith into topical files
# (#9386, #9956). Keep v6's side.
# - UU CHANGELOG.md: both lines prepend their own release sections under
# "## Unreleased" on every release, so the top of the file conflicts on
# almost every top-up. Keep both sides' lines (v6's block first, then
# v5's), which is the layout v6's CHANGELOG already has.
# - UU .github/scripts/integration-governance.cjs, when every conflict hunk
# is the TRUSTED_SCRIPTS_TREE literal on both sides: the literal pins
# `git rev-parse HEAD:src/scripts`, so whenever both lines touched
# src/scripts the two pins differ. Re-pin it to the merged src/scripts
# tree (the merge of two already-reviewed trees; the top-up PR shows it).
# - UU src/pkg/dashboard/static/index.html: a generated artifact. Regenerate
# it as the byte-exact concatenation of static-src/manifest.txt (what
# webstatic.ConcatIndex and TestIndexHTMLIsGenerated do), provided no
# static-src file is itself conflicted.
set -euo pipefail

PIN_FILE=.github/scripts/integration-governance.cjs
INDEX_FILE=src/pkg/dashboard/static/index.html
STATIC_SRC=src/pkg/dashboard/static-src
PIN_RE="^const TRUSTED_SCRIPTS_TREE = '[0-9a-f]{40}';\$"

unmerged="$(git status --porcelain | grep -E '^(DD|AU|UD|UA|DU|AA|UU) ' || true)"
[ -n "$unmerged" ] || { echo "v6-topup-autoresolve: no conflicts to resolve"; exit 1; }

known='^DU discord/|^(DU|UD) \.github/workflows/discord-syntax\.yml$|^UU src/pkg/config/config\.go$|^UU CHANGELOG\.md$|^UU \.github/scripts/integration-governance\.cjs$|^UU src/pkg/dashboard/static/index\.html$'
if unknown="$(printf '%s\n' "$unmerged" | grep -vE "$known")"; then
echo "v6-topup-autoresolve: conflicts outside the known patterns:"
printf '%s\n' "$unknown"
exit 1
fi

# Every hunk of the pin file must be exactly one TRUSTED_SCRIPTS_TREE line per
# side; anything else is a real edit and goes to a human.
pin_hunks_only() {
awk -v re="$PIN_RE" '
/^<<<<<<< / { side = 1; n1 = 0; n2 = 0; hunks++; next }
/^\|\|\|\|\|\|\| / && side == 1 { side = 3; next }
/^=======$/ && (side == 1 || side == 3) { side = 2; next }
/^>>>>>>> / && side == 2 {
if (n1 != 1 || n2 != 1) bad = 1
side = 0; next
}
side == 1 { n1++; if ($0 !~ re) bad = 1 }
side == 2 { n2++; if ($0 !~ re) bad = 1 }
END { exit (bad || hunks == 0 || side != 0) ? 1 : 0 }
' "$1"
}

regen_index=0
repin=0
resolved=0
while IFS= read -r entry; do
[ -n "$entry" ] || continue
status="${entry%% *}"
file="${entry#* }"
case "$status $file" in
"DU "*|"UD "*)
git rm -q -- "$file"
;;
"UU src/pkg/config/config.go")
git checkout --ours -- "$file"
git add -- "$file"
;;
"UU CHANGELOG.md")
tmp="$(mktemp -d)"
git show ":1:$file" > "$tmp/base"
git show ":2:$file" > "$tmp/ours"
git show ":3:$file" > "$tmp/theirs"
git merge-file --union "$tmp/ours" "$tmp/base" "$tmp/theirs"
cp "$tmp/ours" "$file"
rm -rf "$tmp"
git add -- "$file"
;;
"UU $PIN_FILE")
if ! pin_hunks_only "$file"; then
echo "v6-topup-autoresolve: $file conflicts outside the TRUSTED_SCRIPTS_TREE literal"
exit 1
fi
repin=1
;;
"UU $INDEX_FILE")
regen_index=1
;;
*)
echo "v6-topup-autoresolve: unhandled entry: $entry"
exit 1
;;
esac
resolved=$((resolved + 1))
done <<<"$unmerged"

if [ "$regen_index" = 1 ]; then
: > "$INDEX_FILE"
while IFS= read -r line || [ -n "$line" ]; do
line="$(printf '%s' "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
case "$line" in ''|'#'*) continue ;; esac
case "$line" in /*|..*) echo "v6-topup-autoresolve: unsafe manifest path $line"; exit 1 ;; esac
cat "$STATIC_SRC/$line" >> "$INDEX_FILE"
done < "$STATIC_SRC/manifest.txt"
git add -- "$INDEX_FILE"
fi

if [ "$repin" = 1 ]; then
# Stage a placeholder so the index has no unmerged entries, then read the
# merged src/scripts tree from it (the pin file is outside src/scripts).
# Keep v6's side of each (pin-only) hunk; the literal is rewritten below.
awk '
/^<<<<<<< / { side = 1; next }
/^\|\|\|\|\|\|\| / && side == 1 { side = 3; next }
/^=======$/ && (side == 1 || side == 3) { side = 2; next }
/^>>>>>>> / && side == 2 { side = 0; next }
side == 0 || side == 1 { print }
' "$PIN_FILE" > "$PIN_FILE.tmp"
mv "$PIN_FILE.tmp" "$PIN_FILE"
git add -- "$PIN_FILE"
tree="$(git write-tree)"
scripts_tree="$(git rev-parse "${tree}:src/scripts")"
sed -E -i.bak "s/^const TRUSTED_SCRIPTS_TREE = '[0-9a-f]{40}';\$/const TRUSTED_SCRIPTS_TREE = '${scripts_tree}';/" "$PIN_FILE"
rm -f "$PIN_FILE.bak"
git add -- "$PIN_FILE"
echo "v6-topup-autoresolve: re-pinned TRUSTED_SCRIPTS_TREE to ${scripts_tree}"
fi

if git status --porcelain | grep -qE '^(DD|AU|UD|UA|DU|AA|UU) '; then
echo "v6-topup-autoresolve: conflicts remain after resolution"
exit 1
fi
echo "v6-topup-autoresolve: resolved ${resolved} known conflict(s)"
Loading
Loading