From bc07ebbaa27f1fc69c9a5337e373192cce54ac12 Mon Sep 17 00:00:00 2001 From: Vishnu Ajith <86302373+Vishnu2707@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:47:24 +0000 Subject: [PATCH] fix(ci): resolve historical DCO sign-off failures Signed-off-by: Vishnu Ajith <86302373+Vishnu2707@users.noreply.github.com> --- .github/workflows/dco.yml | 4 ++++ docs/dco.md | 23 ++++++++++++++++++++ scripts/check_dco.py | 46 ++++++++++++++++++++++++++++++++++++--- tests/test_dco_check.py | 38 ++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dco.yml b/.github/workflows/dco.yml index f79a14d1..b22bc59c 100644 --- a/.github/workflows/dco.yml +++ b/.github/workflows/dco.yml @@ -28,4 +28,8 @@ jobs: # whose event payload can still reference an obsolete base commit. test "$(git rev-parse HEAD^2)" = "$HEAD_SHA" BASE_SHA="$(git rev-parse HEAD^1)" + # Fetch original PR history. The checker pins the source commit IDs. + if [ "$GITHUB_BASE_REF" = main ]; then + git fetch --no-tags origin refs/pull/321/head refs/pull/347/head refs/pull/362/head + fi python scripts/check_dco.py "$BASE_SHA" "$HEAD_SHA" "$DCO_BASELINE_SHA" diff --git a/docs/dco.md b/docs/dco.md index e2a80686..d7c56f51 100644 --- a/docs/dco.md +++ b/docs/dco.md @@ -38,3 +38,26 @@ git push --force-with-lease For multiple commits, use an interactive rebase and add a sign-off to each commit. Do not add another person's sign-off without their authorization. + +## Preserving sign-offs when merging + +Prefer a merge commit to retain the original signed-off commits. If you squash, +edit the squash message before merging. Preserve the exact `Signed-off-by` +trailers from the signed source commits for every contributor whose work +the squash contains. Verify the final commit message includes those trailers. +If conflict resolution introduces new work, the person who made those changes +must also sign off. Use a merge commit if you cannot preserve the certifications +in the squash message. + +## Historical squash certification + +The checker binds three historical squash commits to the exact signed source +heads of PRs #321, #347, and #362. It requires a clean replay onto the landed +commit's parent, an exact match with the landed tree, and an author-matching +sign-off on every source commit outside the landed parent's history. +Missing objects, replay conflicts, tree differences, and missing or mismatched +source sign-offs fail the check. + +Any change to these mappings requires independent maintainer review of the +official PR's source head, contributor identities, source trailers, and tree +replay. Use the merge procedure above for future contributions. diff --git a/scripts/check_dco.py b/scripts/check_dco.py index e77162d0..c20dd41f 100644 --- a/scripts/check_dco.py +++ b/scripts/check_dco.py @@ -9,6 +9,41 @@ SIGNOFF = re.compile(r"^Signed-off-by:\s+.+\s+<[^<>@\s]+@[^<>\s]+>$", re.IGNORECASE | re.MULTILINE) +# Historical squash commits whose original author certifications can be +# verified against the exact landed tree. The workflow fetches these PR heads. +CERTIFIED_SQUASHES = { + # PR #321 + "90f3fa291be3bfb1ef29e0a599e43dd053cafe80": "101d47a15337d0ee8242420c33b13e8cbda58994", + # PR #347 + "8371ed6907d3eade7fa836938d1c882f4c8b24c8": "2af0b33f786be171132c3bfe3b9313f53fb93bda", + # PR #362 + "5eec78a24c86e5d68da12cb2ad797fd3f4124c95": "23d6dfb69ab395700267a4fabb73a49f75092588", +} + + +def verify_squash(landed: str, source: str) -> bool: + """Verify the original authors certified the exact changes that landed.""" + + def git(*args: str) -> str: + return subprocess.check_output(["git", *args], text=True, stderr=subprocess.DEVNULL).strip() + + try: + (parent,) = git("show", "-s", "--format=%P", landed).split() + if git("merge-tree", "--write-tree", parent, source) != git("rev-parse", f"{landed}^{{tree}}"): + return False + commits = git("rev-list", f"{parent}..{source}").splitlines() + if not commits: + return False + for commit in commits: + author = git("show", "-s", "--format=%an <%ae>", commit).casefold() + signoffs = git("show", "-s", "--format=%(trailers:key=Signed-off-by,valueonly)", commit) + if author not in {line.strip().casefold() for line in signoffs.splitlines()}: + return False + return True + except (subprocess.CalledProcessError, ValueError): + return False + + def has_signoff(message: str) -> bool: """Return whether a commit message contains a well-formed DCO trailer.""" return SIGNOFF.search(message) is not None @@ -54,8 +89,13 @@ def commit_message(commit: str) -> str: def unsigned_commits(commits: Iterable[str]) -> list[str]: - """Return commit IDs that lack a valid Signed-off-by trailer.""" - return [commit for commit in commits if not has_signoff(commit_message(commit))] + """Return commit IDs without a sign-off or verified historical certification.""" + return [ + commit + for commit in commits + if not has_signoff(commit_message(commit)) + and not (commit in CERTIFIED_SQUASHES and verify_squash(commit, CERTIFIED_SQUASHES[commit])) + ] def main() -> int: @@ -70,7 +110,7 @@ def main() -> int: missing = unsigned_commits(commits) if missing: - print("The following commits lack a valid DCO Signed-off-by trailer:", file=sys.stderr) + print("The following commits lack a valid DCO sign-off or verified historical certification:", file=sys.stderr) for commit in missing: print(f" {commit}", file=sys.stderr) print("Recreate or amend them with: git commit -s", file=sys.stderr) diff --git a/tests/test_dco_check.py b/tests/test_dco_check.py index 2c4745fd..9a74aee7 100644 --- a/tests/test_dco_check.py +++ b/tests/test_dco_check.py @@ -3,6 +3,8 @@ import subprocess from unittest.mock import patch +import pytest + from scripts.check_dco import commit_timestamp, commits_between, has_signoff, main, unsigned_commits @@ -97,3 +99,39 @@ def test_baseline_exempts_history_but_checks_new_work_from_old_branch(tmp_path, side_effect={baseline: 100, new_commit: 101}.get, ): assert commits_between(baseline, new_commit, baseline) == [new_commit] + + +@pytest.mark.parametrize( + ("trailer", "evidence"), + [ + ("Signed-off-by: Test User ", "matching"), + ("Signed-off-by: Test User ", "different-tree"), + ("Signed-off-by: Test User ", "missing-source"), + ("Signed-off-by: Other User ", "matching"), + ("Signed-off-by: Test User ", "matching"), + ("", "matching"), + ], +) +def test_historical_squash_requires_exact_signed_source(tmp_path, monkeypatch, trailer, evidence): + _git(tmp_path, "init") + _git(tmp_path, "config", "user.name", "Test User") + _git(tmp_path, "config", "user.email", "test@example.com") + parent = _commit(tmp_path, "parent") + source = _commit(tmp_path, f"source\n\n{trailer}") + _git(tmp_path, "switch", "--detach", parent) + _git(tmp_path, "checkout", source, "--", "history.txt") + if evidence == "different-tree": + (tmp_path / "history.txt").write_text("changed patch", encoding="utf-8") + _git(tmp_path, "add", "history.txt") + _git(tmp_path, "commit", "-m", "unsigned squash") + landed = _git(tmp_path, "rev-parse", "HEAD") + unsigned = _commit(tmp_path, "new unsigned contribution") + + if evidence == "missing-source": + source = "0" * 40 + monkeypatch.chdir(tmp_path) + with patch.dict("scripts.check_dco.CERTIFIED_SQUASHES", {landed: source}, clear=True): + expected = [unsigned] + if evidence != "matching" or trailer != "Signed-off-by: Test User ": + expected.insert(0, landed) + assert unsigned_commits([landed, unsigned]) == expected