diff --git a/.github/scripts/integration-governance.cjs b/.github/scripts/integration-governance.cjs index 27e5a5c64b..8cb60d4461 100644 --- a/.github/scripts/integration-governance.cjs +++ b/.github/scripts/integration-governance.cjs @@ -9,7 +9,7 @@ const MAX_COMMITS = 1000; const MAX_AUTHOR_BATCH = 50; // This literal is inside the enrolled .github closure. A caller-supplied // preparedBy.sourceSHA must never choose a new executable verifier tree. -const TRUSTED_SCRIPTS_TREE = '08802cd3162cd8a179514afe3ddb5e088c90d5f0'; +const TRUSTED_SCRIPTS_TREE = '630082873462479b5777ebc7d5dc255bae6f8df2'; const SOURCE = 'https://github.com/kubernetes-sigs/kubebuilder-release-tools/tree/012269a88fa4c034a0acf1ba84c26b195c0dbab4'; const sha = value => crypto.createHash('sha256').update(value).digest('hex'); const git = (args, cwd = process.cwd()) => diff --git a/.github/workflows/dco-post-merge.yml b/.github/workflows/dco-post-merge.yml index 33c45342e7..4f3011b91f 100644 --- a/.github/workflows/dco-post-merge.yml +++ b/.github/workflows/dco-post-merge.yml @@ -360,6 +360,11 @@ env: # commits and release metadata, not bot-authored commits. Skip bots here so # release automation is not paged for bracketed bot-address edge cases that # the separate pre-merge DCO/probot checks already cover. + # + # The skip is the identity MATCH only: a bot-authored commit with no + # Signed-off-by at all is still reported as missing-signoff. Skipping those + # too is how f33758f5a (the hive's squash of #18079, trailer dropped by the + # squash body) sat unseen on v5 until a forward merge failed DCO (#18203). DCO_SKIP_BOT_AUTHORS: 'true' jobs: diff --git a/changelog.d/fixed-18203-squash-signoff.md b/changelog.d/fixed-18203-squash-signoff.md new file mode 100644 index 0000000000..07ae8f2cf6 --- /dev/null +++ b/changelog.d/fixed-18203-squash-signoff.md @@ -0,0 +1 @@ +- **The hive's squash merges keep the branch's `Signed-off-by` (#18203).** When the hive squash-merged with an empty commit message, GitHub wrote its own default body, and for #18079 that body held only `Co-authored-by` lines: `f33758f5a` landed on v5 with no sign-off, and every branch that later merged v5 forward failed DCO on it. Every hive squash (relay `MergePR` and all auto-merge sweep lanes) now rebuilds the body from the branch commits, adds any branch sign-off the body lacks, and refuses to squash (sweep reason `squash-unsigned`) when no branch commit carries one. It never signs off on anyone's behalf. The post-merge and push-delta DCO checks still skip the sign-off identity match for bot authors, but now report a bot-authored commit with no `Signed-off-by` as `missing-signoff`, so the next one shows up within the hour. diff --git a/src/pkg/github/automerge/automerge_base_preparation_test.go b/src/pkg/github/automerge/automerge_base_preparation_test.go index cd88d21ba4..39c0d00e7a 100644 --- a/src/pkg/github/automerge/automerge_base_preparation_test.go +++ b/src/pkg/github/automerge/automerge_base_preparation_test.go @@ -104,7 +104,7 @@ func newPreparationAPI(t *testing.T) (*preparationAPI, *httptest.Server) { api.updates[n]++ w.WriteHeader(http.StatusAccepted) write(map[string]string{"message": "Updating pull request branch"}) - case "reviews": + case "reviews", "commits": write([]any{}) case "files": if api.onFiles != nil { diff --git a/src/pkg/github/automerge/automerge_contributor_lane.go b/src/pkg/github/automerge/automerge_contributor_lane.go index 39c13f7048..81cc1f9ed3 100644 --- a/src/pkg/github/automerge/automerge_contributor_lane.go +++ b/src/pkg/github/automerge/automerge_contributor_lane.go @@ -1571,7 +1571,10 @@ func (c *Engine) trySweepContributorLanePR(ctx context.Context, displayRepo, own return AutoMergeSweepEvent{}, refused, nil } - mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, eval.pr, headSHA, method) + mergeMessage, mergeOpts, refused := c.mergeOptions(ctx, owner, repo, eval.pr, headSHA, method) + if refused != "" { + return AutoMergeSweepEvent{}, refused, nil + } var mergeResult *gh.PullRequestMergeResult mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, headSHA, func(ctx context.Context) (effects.Result, error) { var apiErr error diff --git a/src/pkg/github/automerge/automerge_current_base_test.go b/src/pkg/github/automerge/automerge_current_base_test.go index 5920edc6e5..c02d0819cf 100644 --- a/src/pkg/github/automerge/automerge_current_base_test.go +++ b/src/pkg/github/automerge/automerge_current_base_test.go @@ -40,6 +40,9 @@ func TestCurrentBaseGate(t *testing.T) { var mu sync.Mutex compares, updates := 0, 0 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } mu.Lock() defer mu.Unlock() switch { @@ -120,6 +123,9 @@ func TestCurrentBaseGateUpdateUnavailableFallback(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/pulls/7": _ = json.NewEncoder(w).Encode(map[string]any{"number": 7, "state": "open", "head": map[string]string{"sha": head}, "base": map[string]string{"ref": "main", "sha": "base1"}}) @@ -203,6 +209,9 @@ func TestCurrentBaseGateLeavesDependencyBotBranchToTheBot(t *testing.T) { var mu sync.Mutex updates := 0 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } mu.Lock() defer mu.Unlock() switch { @@ -264,6 +273,9 @@ func TestUpdateBranchAndSkipLeavesDependencyBotBranchToTheBot(t *testing.T) { var mu sync.Mutex updates := 0 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } mu.Lock() defer mu.Unlock() switch { @@ -327,6 +339,9 @@ func newCurrentBaseLaneServer(t *testing.T, a *currentBaseLaneAPI) *httptest.Ser t.Helper() const head = "sha7" return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } a.mu.Lock() defer a.mu.Unlock() switch { diff --git a/src/pkg/github/automerge/automerge_human_paths_test.go b/src/pkg/github/automerge/automerge_human_paths_test.go index 748c05b4e9..31a4e08ea8 100644 --- a/src/pkg/github/automerge/automerge_human_paths_test.go +++ b/src/pkg/github/automerge/automerge_human_paths_test.go @@ -57,7 +57,10 @@ func testPinCommitBy(sha, author, committer string, verified bool) map[string]an "sha": sha, "author": map[string]any{"login": author}, "committer": map[string]any{"login": committer}, - "commit": map[string]any{"verification": map[string]any{"verified": verified}}, + "commit": map[string]any{ + "message": "Bump upstream/action\n\nSigned-off-by: " + author + " <" + author + "@example.com>", + "verification": map[string]any{"verified": verified}, + }, } } diff --git a/src/pkg/github/automerge/automerge_merge_credit.go b/src/pkg/github/automerge/automerge_merge_credit.go index ad1b057519..b168676e47 100644 --- a/src/pkg/github/automerge/automerge_merge_credit.go +++ b/src/pkg/github/automerge/automerge_merge_credit.go @@ -21,18 +21,30 @@ type mergeCreditTransport interface { // mergeOptions returns the commit message and options for merging pr's // head at headSHA with method. The message is "" (GitHub's default) unless -// the repo credits issue authors and the PR has one to credit. -func (c *Engine) mergeOptions(ctx context.Context, owner, repo string, pr *gh.PullRequest, headSHA, method string) (string, *gh.PullRequestOptions) { - opts := &gh.PullRequestOptions{SHA: headSHA, MergeMethod: method} +// the repo credits issue authors and the PR has one to credit, or a squash +// needs the body rebuilt to keep the branch's Signed-off-by trailers +// (hivecommons/hive#18203). A non-empty refused is the skip reason when the +// squash would land with no sign-off at all; the caller must not merge. +func (c *Engine) mergeOptions(ctx context.Context, owner, repo string, pr *gh.PullRequest, headSHA, method string) (message string, opts *gh.PullRequestOptions, refused string) { + opts = &gh.PullRequestOptions{SHA: headSHA, MergeMethod: method} mt, ok := c.transport.(mergeCreditTransport) if !ok || pr == nil { - return "", opts + return "", opts, "" } creditor := mt.MergeCreditor() - if !creditor.Enabled(owner + "/" + repo) { - return "", opts + if creditor.Enabled(owner + "/" + repo) { + credit := creditor.Prepare(ctx, owner, repo, pr, method) + mt.NoteMergeCredit(owner+"/"+repo, pr.GetNumber(), credit) + message = credit.CommitMessage } - credit := creditor.Prepare(ctx, owner, repo, pr, method) - mt.NoteMergeCredit(owner+"/"+repo, pr.GetNumber(), credit) - return credit.CommitMessage, opts + message, err := creditor.SquashSignoff(ctx, owner, repo, pr.GetNumber(), method, message) + if err != nil { + c.warn("automerge refused squash without Signed-off-by", "repo", owner+"/"+repo, "pr", pr.GetNumber(), "error", err) + return "", opts, autoMergeReasonSquashUnsigned + } + return message, opts, "" } + +// autoMergeReasonSquashUnsigned is the skip reason when no branch commit +// carries a Signed-off-by, so the squash would land a commit that fails DCO. +const autoMergeReasonSquashUnsigned = "squash-unsigned" diff --git a/src/pkg/github/automerge/automerge_merge_credit_test.go b/src/pkg/github/automerge/automerge_merge_credit_test.go index b26eaa6238..2b17c4ae6c 100644 --- a/src/pkg/github/automerge/automerge_merge_credit_test.go +++ b/src/pkg/github/automerge/automerge_merge_credit_test.go @@ -63,16 +63,20 @@ func TestContributorLaneMergeCreditOff(t *testing.T) { if _, reason, err := engine.trySweepContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy); err != nil || reason != "" { t.Fatalf("reason=%q err=%v, want merge", reason, err) } - if _, has := fx.mergeBody["commit_message"]; has || fx.merges != 1 { - t.Fatalf("credit off: merge body %+v (merges %d), want GitHub's default message", fx.mergeBody, fx.merges) + // Credit off still rebuilds the squash body from the branch commits so + // the sign-off lands (hivecommons/hive#18203), but reads no issue. + signoff := "Signed-off-by: " + contributorLaneTestAuthor + " <" + contributorLaneTestAuthor + "@example.com>" + if got, _ := fx.mergeBody["commit_message"].(string); got != signoff || fx.merges != 1 { + t.Fatalf("credit off: merge body %+v (merges %d), want only the branch sign-off", fx.mergeBody, fx.merges) } - if fx.issueGets != 0 || fx.commitLists != 0 { - t.Fatalf("credit off still read issue (%d) / commits (%d)", fx.issueGets, fx.commitLists) + if fx.issueGets != 0 || fx.commitLists != 1 { + t.Fatalf("credit off read issue (%d) / commits (%d), want 0 / 1", fx.issueGets, fx.commitLists) } } -// A PR author who filed their own issue is not their own co-author, and the -// merge then sends no message at all (no commit read either). +// A PR author who filed their own issue is not their own co-author: the +// merge credits nobody and sends only the branch sign-off +// (hivecommons/hive#18203). func TestContributorLaneMergeCreditSkipsSelf(t *testing.T) { fx := validContributorFixture() fx.issueAuthor = contributorLaneTestAuthor @@ -84,13 +88,15 @@ func TestContributorLaneMergeCreditSkipsSelf(t *testing.T) { if _, reason, err := engine.trySweepContributorLanePR(context.Background(), "widget", "acme", "widget", 7, policy); err != nil || reason != "" { t.Fatalf("reason=%q err=%v, want merge", reason, err) } - if _, has := fx.mergeBody["commit_message"]; has || fx.commitLists != 0 { + signoff := "Signed-off-by: " + contributorLaneTestAuthor + " <" + contributorLaneTestAuthor + "@example.com>" + if got, _ := fx.mergeBody["commit_message"].(string); got != signoff || fx.commitLists != 1 { t.Fatalf("self-filed issue: merge body %+v (commit lists %d)", fx.mergeBody, fx.commitLists) } } // The self-authored lane: a hive-opened PR already carries the trailer from -// issue-coauthor.sh, so the merge adds nothing; a hive PR whose branch lacks +// issue-coauthor.sh, so the merge adds no credit (the rebuilt body keeps the +// branch trailers); a hive PR whose branch lacks // it gains it. func TestSelfAuthoredSweepMergeCredit(t *testing.T) { for _, tc := range []struct { @@ -101,6 +107,7 @@ func TestSelfAuthoredSweepMergeCredit(t *testing.T) { { name: "branch already credits the issue author", commits: []string{"Fix\n\nSigned-off-by: hive[bot] \nCo-authored-by: Dana Thar <12345+Danathar@users.noreply.github.com>"}, + want: "Signed-off-by: hive[bot] \nCo-authored-by: Dana Thar <12345+Danathar@users.noreply.github.com>", }, { name: "branch lacks the trailer", diff --git a/src/pkg/github/automerge/automerge_sweep_queued.go b/src/pkg/github/automerge/automerge_sweep_queued.go index 45e4ea39b9..459521214b 100644 --- a/src/pkg/github/automerge/automerge_sweep_queued.go +++ b/src/pkg/github/automerge/automerge_sweep_queued.go @@ -173,7 +173,10 @@ func (c *Engine) trySweepQueuedPR(ctx context.Context, displayRepo, owner, repo return AutoMergeSweepEvent{}, refused, nil } - mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, pr, headSHA, method) + mergeMessage, mergeOpts, refused := c.mergeOptions(ctx, owner, repo, pr, headSHA, method) + if refused != "" { + return AutoMergeSweepEvent{}, refused, nil + } var mergeResult *gh.PullRequestMergeResult mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, headSHA, func(ctx context.Context) (effects.Result, error) { var apiErr error diff --git a/src/pkg/github/automerge/automerge_sweep_test.go b/src/pkg/github/automerge/automerge_sweep_test.go index a139bcc2f9..eebfeeebbd 100644 --- a/src/pkg/github/automerge/automerge_sweep_test.go +++ b/src/pkg/github/automerge/automerge_sweep_test.go @@ -325,6 +325,9 @@ func TestPrefilterTrustedAuthorPR(t *testing.T) { func TestTrustedAuthorGitHubSignals(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/collaborators/alice/permission": json.NewEncoder(w).Encode(map[string]string{"permission": "write", "role_name": "maintain"}) @@ -408,6 +411,9 @@ func (b *recordingBoundary) Execute(ctx context.Context, claim effects.Claim, ef func TestExecuteMergeEffectReconcilesUnknownOpenPRBeforeRetry(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } if r.Method != http.MethodGet || r.URL.Path != "/repos/acme/widget/pulls/7" { t.Fatalf("unexpected request: %s %s", r.Method, r.URL.String()) } @@ -700,6 +706,9 @@ func TestSweepQueuedAutoMergesRechecksSelfMergeBan(t *testing.T) { func TestSweepQueuedAutoMergesSkipsHeldIssueWithoutPRFetch(t *testing.T) { var pullsGet int api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/issues": json.NewEncoder(w).Encode([]map[string]any{{ @@ -737,6 +746,9 @@ func TestSweepQueuedAutoMergesSkipsHeldIssueWithoutPRFetch(t *testing.T) { func TestSweepQueuedAutoMergesSkipsHivePauseHeldIssueWithoutPRFetch(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/issues": json.NewEncoder(w).Encode([]map[string]any{{ @@ -821,6 +833,9 @@ func TestCommitGreenStatusAndCheckBranches(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/commits/sha/status": statuses := []map[string]string{} @@ -882,6 +897,9 @@ func TestCommitGreenKnownEmptyRequiredChecksBlocksCompletedFailures(t *testing.T for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": json.NewEncoder(w).Encode(map[string]any{"strict": true, "contexts": []string{}}) @@ -936,6 +954,9 @@ func TestTrySweepQueuedPRSkipBranches(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } if serveUnprotectedSweepBase(w, r) { return } @@ -991,6 +1012,9 @@ func TestTrySweepQueuedPRMissingHeadAndMergeNotApplied(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } if serveUnprotectedSweepBase(w, r) { return } @@ -1033,6 +1057,9 @@ func TestTrySweepQueuedPRMissingHeadAndMergeNotApplied(t *testing.T) { func TestTrySweepQueuedPRMergeError(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } if serveUnprotectedSweepBase(w, r) { return } @@ -1068,6 +1095,9 @@ func TestTrySweepQueuedPRMergeError(t *testing.T) { func TestTrySweepQueuedPRRequiredChecksExpectedIsRemembered(t *testing.T) { var merges int api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } if serveUnprotectedSweepBase(w, r) { return } @@ -1121,6 +1151,9 @@ func TestTrySweepQueuedPRRequiredChecksExpectedIsRemembered(t *testing.T) { func TestLatestHiveQueueApprovalDoesNotTrustBodyWhenReviewerIsNotApp(t *testing.T) { var logs bytes.Buffer api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } if r.Method != http.MethodGet || r.URL.Path != "/repos/acme/widget/pulls/7/reviews" { t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path) } @@ -1150,6 +1183,9 @@ func TestLatestHiveQueueApprovalDoesNotTrustBodyWhenReviewerIsNotApp(t *testing. func TestLatestHiveQueueApprovalKeepsLatestCommitID(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } if r.Method != http.MethodGet || r.URL.Path != "/repos/acme/widget/pulls/7/reviews" { t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path) } @@ -1174,6 +1210,9 @@ func TestLatestHiveQueueApprovalKeepsLatestCommitID(t *testing.T) { func TestInvalidateQueuedAutoMergeIgnoresMissingLabelAndComments(t *testing.T) { var commented bool api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodDelete && r.URL.Path == "/repos/acme/widget/issues/7/labels/"+hgithub.AutoMergeQueuedLabel: http.NotFound(w, r) @@ -1207,6 +1246,9 @@ func TestInvalidateQueuedAutoMergeReportsAPIErrors(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodDelete && r.URL.Path == "/repos/acme/widget/issues/7/labels/"+hgithub.AutoMergeQueuedLabel: w.WriteHeader(tt.deleteCode) @@ -1242,6 +1284,9 @@ func TestCommitGreenAPIErrors(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/commits/sha/status": if tt.statusCode != http.StatusOK { @@ -1356,6 +1401,9 @@ func TestCommitGreenRequiredChecksOnly(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": json.NewEncoder(w).Encode(map[string]any{ @@ -1448,6 +1496,9 @@ func TestCommitGreenRequiredChecksUnavailableFallsBack(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": if tt.protectionCode == 0 { @@ -1515,6 +1566,9 @@ func TestCommitGreenUnprotectedBaseIgnoresMetaWithEvidence(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": w.WriteHeader(http.StatusNotFound) @@ -1585,6 +1639,9 @@ func TestCommitGreenConfigRequiredChecksFallback(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": http.Error(w, "forbidden", http.StatusForbidden) @@ -1626,6 +1683,9 @@ func TestCommitGreenConfigRequiredChecksFallback(t *testing.T) { // enforcement. func TestCommitGreenNoConfigRequiredChecksFallsBackToServerEnforcement(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": w.WriteHeader(http.StatusInternalServerError) @@ -1663,6 +1723,9 @@ func TestCommitGreenUnknownRequiredChecksSkipsExpectedReferenceChecks(t *testing var referenceFetches int var mergedPRFetches int api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": http.Error(w, "forbidden", http.StatusForbidden) @@ -1716,6 +1779,9 @@ func TestCommitGreenUnknownRequiredChecksSkipsExpectedReferenceChecks(t *testing func TestCommitGreenUnknownRequiredChecksSkipsPreviousEvaluatedHead(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": http.Error(w, "forbidden", http.StatusForbidden) @@ -1771,6 +1837,9 @@ func TestSetRequiredChecksEmptyMapIsNotDeclared(t *testing.T) { func TestListQueuedPullRequestIssuesPaginates(t *testing.T) { var base string api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch r.URL.Query().Get("page") { case "": w.Header().Set("Link", `<`+base+`/repos/acme/widget/issues?page=2>; rel="next"`) @@ -1848,6 +1917,9 @@ func newSelfAuthoredAutoMergeAPI(t *testing.T, prs []selfAuthoredPR, merged *[]i byNumber[prs[i].number] = &prs[i] } return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/pulls": var out []map[string]any @@ -2153,6 +2225,9 @@ func TestTrySweepSelfAuthoredPRRequiredChecksDecision(t *testing.T) { func TestSweepSelfAuthoredAutoMergesSkipsRepoWhenAutoMergeDisabled(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } t.Fatalf("disabled auto-merge repo should be skipped before API calls; got %s %s", r.Method, r.URL.Path) })) defer api.Close() @@ -2967,6 +3042,9 @@ func newAutoMergeSweepAPI(t *testing.T, expectedLabel string, prs []sweepPR, mer byNumber[pr.number] = pr } return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/issues": if got := r.URL.Query().Get("labels"); got != expectedLabel { @@ -3253,6 +3331,9 @@ func TestSweepSelfAuthoredAutoMergesRecordsPRMergedAuditTrail(t *testing.T) { func TestCommitGreenKnownEmptyRequiredChecksRequiresEvidence(t *testing.T) { api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.Method == http.MethodGet && r.URL.Path == "/repos/acme/widget/branches/main/protection/required_status_checks": w.WriteHeader(http.StatusNotFound) @@ -3453,3 +3534,19 @@ func TestSweepSelfAuthoredNeedsRebaseLabelAsksSupersededCloser(t *testing.T) { t.Fatalf("reason=%q err=%v, want %s", reason, err, autoMergeReasonLabelNeedsRebase) } } + +// servePRCommitsSigned answers GET /repos/{o}/{r}/pulls/{n}/commits with one +// signed-off branch commit, so a fixture's squash merge keeps a +// Signed-off-by instead of being refused as unsigned (hivecommons/hive#18203). +// It reports whether it served the request. +func servePRCommitsSigned(w http.ResponseWriter, r *http.Request) bool { + if r.Method != http.MethodGet || !strings.Contains(r.URL.Path, "/pulls/") || !strings.HasSuffix(r.URL.Path, "/commits") { + return false + } + json.NewEncoder(w).Encode([]map[string]any{{ + "sha": "c0", + "commit": map[string]any{"message": "Fix\n\nSigned-off-by: hive[bot] "}, + "parents": []map[string]any{{"sha": "p"}}, + }}) + return true +} diff --git a/src/pkg/github/automerge/automerge_sweep_trusted.go b/src/pkg/github/automerge/automerge_sweep_trusted.go index 2bbb550238..45b2146d6f 100644 --- a/src/pkg/github/automerge/automerge_sweep_trusted.go +++ b/src/pkg/github/automerge/automerge_sweep_trusted.go @@ -294,7 +294,10 @@ func (c *Engine) trySweepSelfAuthoredPR(ctx context.Context, displayRepo, owner, return AutoMergeSweepEvent{}, refused, nil } - mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, current, evaluatedHeadSHA, method) + mergeMessage, mergeOpts, refused := c.mergeOptions(ctx, owner, repo, current, evaluatedHeadSHA, method) + if refused != "" { + return AutoMergeSweepEvent{}, refused, nil + } var mergeResult *gh.PullRequestMergeResult mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, evaluatedHeadSHA, func(ctx context.Context) (effects.Result, error) { var apiErr error @@ -757,7 +760,10 @@ func (c *Engine) trySweepTrustedAuthorPR(ctx context.Context, displayRepo, owner return AutoMergeSweepEvent{}, refused, nil } - mergeMessage, mergeOpts := c.mergeOptions(ctx, owner, repo, current, headSHA, method) + mergeMessage, mergeOpts, refused := c.mergeOptions(ctx, owner, repo, current, headSHA, method) + if refused != "" { + return AutoMergeSweepEvent{}, refused, nil + } var mergeResult *gh.PullRequestMergeResult mergeOut, err := c.executeMergeEffect(ctx, mergeClaim, owner, repo, number, headSHA, func(ctx context.Context) (effects.Result, error) { var apiErr error diff --git a/src/pkg/github/automerge/automerge_sweep_trusted_author_test.go b/src/pkg/github/automerge/automerge_sweep_trusted_author_test.go index 51ab9fe4ed..2dcdc8d301 100644 --- a/src/pkg/github/automerge/automerge_sweep_trusted_author_test.go +++ b/src/pkg/github/automerge/automerge_sweep_trusted_author_test.go @@ -46,6 +46,9 @@ func newTrustedSweepAPI(t *testing.T, fx *trustedSweepFixture) *httptest.Server t.Helper() fetches := 0 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } if serveUnprotectedSweepBase(w, r) { return } @@ -416,6 +419,9 @@ func TestPrefilterTrustedAuthorPRIgnoresSentinelExcludedLabel(t *testing.T) { func TestTrustedAuthorGitHubSignalErrorsAndEdges(t *testing.T) { page := 0 api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if servePRCommitsSigned(w, r) { + return + } switch { case r.URL.Path == "/repos/acme/widget/collaborators/ghost/permission": http.Error(w, "boom", http.StatusInternalServerError) diff --git a/src/pkg/github/human_merge_paths_test.go b/src/pkg/github/human_merge_paths_test.go index 28c614e65e..5667a88c61 100644 --- a/src/pkg/github/human_merge_paths_test.go +++ b/src/pkg/github/human_merge_paths_test.go @@ -277,7 +277,10 @@ func pinOnlyTestCommit(sha, author, committer string, verified bool) map[string] "sha": sha, "author": map[string]any{"login": author}, "committer": map[string]any{"login": committer}, - "commit": map[string]any{"verification": map[string]any{"verified": verified}}, + "commit": map[string]any{ + "message": "Bump upstream/action\n\nSigned-off-by: " + author + " <" + author + "@example.com>", + "verification": map[string]any{"verified": verified}, + }, } } diff --git a/src/pkg/github/merge_credit.go b/src/pkg/github/merge_credit.go index d2e4825b00..0603fe26cd 100644 --- a/src/pkg/github/merge_credit.go +++ b/src/pkg/github/merge_credit.go @@ -354,7 +354,10 @@ func squashCreditMessage(commits []*gh.RepositoryCommit, added []IssueAuthorCred parts = append(parts, para) } } - return strings.Join(append(parts, creditTrailers(added)), "\n\n") + if trailers := creditTrailers(added); trailers != "" { + parts = append(parts, trailers) + } + return strings.Join(parts, "\n\n") } // mergeCommitCreditMessage is the merge commit body: GitHub's default (the diff --git a/src/pkg/github/merge_credit_test.go b/src/pkg/github/merge_credit_test.go index 4c5aeb3a64..bde38583f6 100644 --- a/src/pkg/github/merge_credit_test.go +++ b/src/pkg/github/merge_credit_test.go @@ -379,7 +379,9 @@ func TestMergePRViaSendsIssueAuthorCredit(t *testing.T) { } msg, _ := mergeBody["commit_message"].(string) if !tc.enabled { - if msg != "" || issueGets != 0 { + // Credit off still rebuilds the squash body so the branch + // sign-off lands (hivecommons/hive#18203). + if msg != "Signed-off-by: K " || issueGets != 0 { t.Fatalf("credit off: commit_message=%q issueGets=%d", msg, issueGets) } if len(details) != 1 || strings.Contains(details[0], "issue_authors") { diff --git a/src/pkg/github/merge_signoff.go b/src/pkg/github/merge_signoff.go new file mode 100644 index 0000000000..75a4cfecf2 --- /dev/null +++ b/src/pkg/github/merge_signoff.go @@ -0,0 +1,113 @@ +package github + +import ( + "context" + "errors" + "log/slog" + "regexp" + "strings" + + gh "github.com/google/go-github/v72/github" +) + +// Signed-off-by through the hive's squash merges (hivecommons/hive#18203). +// +// When the hive sent an empty commit message, GitHub wrote its own default +// squash body, and for #18079 that body was only Co-authored-by lines: the +// branch commit's Signed-off-by never reached v5 (f33758f5a), and every +// branch that later merged v5 forward failed DCO on it. A squash is the one +// place the trailer can be lost after the PR-time DCO check passed, so the +// hive no longer leaves the body to GitHub: it rebuilds it from the branch +// commits, makes sure every branch sign-off is in it, and refuses to squash +// when the branch carries none at all. It never signs off on anyone's behalf. + +// ErrSquashUnsigned is returned when a squash merge would land a commit with +// no Signed-off-by: none of the branch commits carries one. +var ErrSquashUnsigned = errors.New("squash refused: no branch commit carries a Signed-off-by trailer, the landing commit would fail DCO") + +// signedOffByRE matches one Signed-off-by trailer line anywhere in a body +// (the post-merge DCO check scans every line, not only the last paragraph). +var signedOffByRE = regexp.MustCompile(`(?mi)^Signed-off-by:\s*(\S.*?)\s*$`) + +// SquashSignoff returns the commit message to send with merging number by +// method so a squash keeps the branch's Signed-off-by trailers. message is +// what the merge would otherwise send ("" for GitHub's default). A merge +// commit or rebase lands the branch commits themselves and is returned +// unchanged. A message that already carries a sign-off was rebuilt from the +// branch commits (squashCreditMessage keeps every line) and costs no request. +// +// It applies whether or not issue-author credit is on for the repo. If the +// branch commits cannot be read the message is returned unchanged (the +// PR-time DCO gate already ran); a branch read with no sign-off at all +// returns ErrSquashUnsigned and the caller must not merge. +func (m *MergeCreditor) SquashSignoff(ctx context.Context, owner, repo string, number int, method, message string) (string, error) { + if m == nil || m.gh == nil || number <= 0 { + return message, nil + } + method = strings.ToLower(strings.TrimSpace(method)) + if method != "" && method != "squash" { + return message, nil + } + if signedOffByRE.MatchString(message) { + return message, nil + } + commits, err := m.listCommits(WithRESTCaller(ctx, mergeCreditCaller), owner, repo, number) + if err != nil { + m.logger.Warn("squash sign-off: could not read PR commits, merging with the message as built", + slog.String("repo", owner+"/"+repo), slog.Int("number", number), slog.String("error", err.Error())) + return message, nil + } + return squashSignoffMessage(commits, message) +} + +// squashSignoffMessage is SquashSignoff's decision over commits already read: +// an empty message becomes the rebuilt default squash body, and any branch +// sign-off the message lacks is appended as a trailer. +func squashSignoffMessage(commits []*gh.RepositoryCommit, message string) (string, error) { + signoffs := branchSignoffs(commits) + if len(signoffs) == 0 { + return "", ErrSquashUnsigned + } + if strings.TrimSpace(message) == "" { + message = squashCreditMessage(commits, nil) + } + present := map[string]bool{} + for _, m := range signedOffByRE.FindAllStringSubmatch(message, -1) { + present[strings.ToLower(m[1])] = true + } + var missing []string + for _, s := range signoffs { + if !present[strings.ToLower(s)] { + missing = append(missing, "Signed-off-by: "+s) + } + } + if len(missing) == 0 { + return message, nil + } + if message = strings.TrimSpace(message); message == "" { + return strings.Join(missing, "\n"), nil + } + return message + "\n\n" + strings.Join(missing, "\n"), nil +} + +// branchSignoffs returns the distinct Signed-off-by identities on the +// branch's own commits, in order; merge-from-base commits are left out, as +// the squash body leaves them out. +func branchSignoffs(commits []*gh.RepositoryCommit) []string { + seen := map[string]bool{} + var out []string + for _, rc := range commits { + if rc == nil || len(rc.Parents) > 1 { + continue + } + for _, m := range signedOffByRE.FindAllStringSubmatch(rc.GetCommit().GetMessage(), -1) { + key := strings.ToLower(m[1]) + if seen[key] { + continue + } + seen[key] = true + out = append(out, m[1]) + } + } + return out +} diff --git a/src/pkg/github/merge_signoff_test.go b/src/pkg/github/merge_signoff_test.go new file mode 100644 index 0000000000..18617d45d4 --- /dev/null +++ b/src/pkg/github/merge_signoff_test.go @@ -0,0 +1,158 @@ +package github + +import ( + "context" + "encoding/json" + "errors" + "io" + "net/http" + "net/http/httptest" + "strings" + "testing" + + gh "github.com/google/go-github/v72/github" +) + +// Signed-off-by through the hive's squash merges (hivecommons/hive#18203). + +func TestSquashSignoffMessage(t *testing.T) { + // The #18079 shape: one signed branch commit whose GitHub default squash + // body came out as Co-authored-by lines only (f33758f5a). + scanner := "[scanner] fix: de-flake two tests\n\n" + + "Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>\n\n" + + "Co-Authored-By: Claude Opus 5.5 " + t.Run("empty message is rebuilt from the branch and keeps the sign-off", func(t *testing.T) { + got, err := squashSignoffMessage([]*gh.RepositoryCommit{commitWithMessage(scanner)}, "") + if err != nil { + t.Fatalf("squashSignoffMessage: %v", err) + } + want := "Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>\n\n" + + "Co-Authored-By: Claude Opus 5.5 " + if got != want { + t.Fatalf("message =\n%s\nwant\n%s", got, want) + } + }) + t.Run("a message without the sign-off gains it as a trailer", func(t *testing.T) { + got, err := squashSignoffMessage([]*gh.RepositoryCommit{commitWithMessage(scanner)}, "Co-authored-by: dana <4+dana@users.noreply.github.com>") + if err != nil { + t.Fatalf("squashSignoffMessage: %v", err) + } + want := "Co-authored-by: dana <4+dana@users.noreply.github.com>\n\n" + + "Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>" + if got != want { + t.Fatalf("message =\n%s\nwant\n%s", got, want) + } + }) + t.Run("every distinct branch sign-off is kept once", func(t *testing.T) { + commits := []*gh.RepositoryCommit{ + commitWithMessage("One\n\nSigned-off-by: A "), + commitWithMessage("Two\n\nsigned-off-by: a \nSigned-off-by: B "), + } + got, err := squashSignoffMessage(commits, "Squash body") + if err != nil { + t.Fatalf("squashSignoffMessage: %v", err) + } + want := "Squash body\n\nSigned-off-by: A \nSigned-off-by: B " + if got != want { + t.Fatalf("message =\n%s\nwant\n%s", got, want) + } + }) + t.Run("merge-from-base commits do not count", func(t *testing.T) { + mergeFromBase := &gh.RepositoryCommit{ + Commit: &gh.Commit{Message: gh.Ptr("Merge v5\n\nSigned-off-by: M ")}, + Parents: []*gh.Commit{{SHA: gh.Ptr("p1")}, {SHA: gh.Ptr("p2")}}, + } + _, err := squashSignoffMessage([]*gh.RepositoryCommit{commitWithMessage("Fix"), mergeFromBase}, "") + if !errors.Is(err, ErrSquashUnsigned) { + t.Fatalf("err = %v, want ErrSquashUnsigned", err) + } + }) + t.Run("no sign-off on the branch refuses the squash", func(t *testing.T) { + _, err := squashSignoffMessage([]*gh.RepositoryCommit{commitWithMessage("Fix\n\nCo-authored-by: x ")}, "Co-authored-by: x ") + if !errors.Is(err, ErrSquashUnsigned) { + t.Fatalf("err = %v, want ErrSquashUnsigned", err) + } + }) +} + +func TestMergeCreditorSquashSignoff(t *testing.T) { + ctx := context.Background() + off := func(string) bool { return false } + t.Run("applies with issue-author credit off", func(t *testing.T) { + api := &mergeCreditAPI{commits: []string{"Fix\n\nSigned-off-by: K "}} + m, _ := newMergeCreditorForTest(t, api, off) + got, err := m.SquashSignoff(ctx, "acme", "widget", 7, "squash", "") + if err != nil || got != "Signed-off-by: K " { + t.Fatalf("SquashSignoff = %q, %v", got, err) + } + }) + t.Run("a signed message costs no request", func(t *testing.T) { + api := &mergeCreditAPI{} + m, _ := newMergeCreditorForTest(t, api, off) + msg := "Body\n\nSigned-off-by: K " + if got, err := m.SquashSignoff(ctx, "acme", "widget", 7, "squash", msg); err != nil || got != msg || api.listGets.Load() != 0 { + t.Fatalf("SquashSignoff = %q, %v after %d commit lists", got, err, api.listGets.Load()) + } + }) + t.Run("merge and rebase are untouched", func(t *testing.T) { + api := &mergeCreditAPI{} + m, _ := newMergeCreditorForTest(t, api, off) + for _, method := range []string{"merge", "rebase"} { + if got, err := m.SquashSignoff(ctx, "acme", "widget", 7, method, ""); err != nil || got != "" { + t.Fatalf("%s: SquashSignoff = %q, %v", method, got, err) + } + } + if api.listGets.Load() != 0 { + t.Fatalf("merge/rebase read the commits %d times", api.listGets.Load()) + } + }) + t.Run("unsigned branch is refused", func(t *testing.T) { + api := &mergeCreditAPI{commits: []string{"Fix"}} + m, _ := newMergeCreditorForTest(t, api, off) + if _, err := m.SquashSignoff(ctx, "acme", "widget", 7, "squash", ""); !errors.Is(err, ErrSquashUnsigned) { + t.Fatalf("err = %v, want ErrSquashUnsigned", err) + } + }) + t.Run("nil creditor passes the message through", func(t *testing.T) { + var m *MergeCreditor + if got, err := m.SquashSignoff(ctx, "acme", "widget", 7, "squash", "x"); err != nil || got != "x" { + t.Fatalf("nil: %q, %v", got, err) + } + }) +} + +// MergePRVia refuses to squash a branch with no sign-off and sends no merge. +func TestMergePRViaRefusesUnsignedSquash(t *testing.T) { + green := greenFixture() + merges := 0 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch { + case r.Method == http.MethodGet && r.URL.Path == "/repos/o/r/pulls/42": + json.NewEncoder(w).Encode(map[string]any{ + "number": 42, "state": "open", "title": "Fix the widget", "body": "", + "user": map[string]any{"login": "karibhou"}, + "head": map[string]any{"sha": "abc123", "ref": "fix/widget"}, + "base": map[string]any{"ref": "v5"}, + }) + case r.Method == http.MethodGet && r.URL.Path == "/repos/o/r/pulls/42/commits": + json.NewEncoder(w).Encode([]map[string]any{{"sha": "c0", "commit": map[string]any{"message": "Fix the widget"}, "parents": []map[string]any{{"sha": "p"}}}}) + case r.Method == http.MethodPut && r.URL.Path == "/repos/o/r/pulls/42/merge": + merges++ + _, _ = io.WriteString(w, `{"sha":"deadbeef","merged":true}`) + default: + if green.serveCI(w, r) { + return + } + w.WriteHeader(http.StatusNotFound) + } + })) + defer srv.Close() + c := testMergeClient(t, srv.URL) + _, err := c.MergePRVia(context.Background(), "o/r", 42, "squash", "", PRAuditPathForge) + if !errors.Is(err, ErrSquashUnsigned) || !strings.Contains(err.Error(), "o/r#42") { + t.Fatalf("MergePRVia err = %v, want ErrSquashUnsigned for o/r#42", err) + } + if merges != 0 { + t.Fatalf("merges = %d, want 0", merges) + } +} diff --git a/src/pkg/github/pullrequest.go b/src/pkg/github/pullrequest.go index 87e9364543..5eb444f3af 100644 --- a/src/pkg/github/pullrequest.go +++ b/src/pkg/github/pullrequest.go @@ -464,6 +464,12 @@ func (c *Client) MergePRVia(ctx context.Context, repo string, number int, mergeM commitMessage = credit.CommitMessage c.NoteMergeCredit(owner+"/"+repo, number, credit) } + // A squash carries the branch's Signed-off-by trailers into the landing + // commit, or does not happen (hivecommons/hive#18203). + commitMessage, err = c.MergeCreditor().SquashSignoff(ctx, owner, repo, number, mergeMethod, commitMessage) + if err != nil { + return MergePRResult{}, fmt.Errorf("merging PR %s/%s#%d (%s): %w", owner, repo, number, mergeMethod, err) + } var res *gh.PullRequestMergeResult boundary := c.mutationBoundary() claim := effects.Claim{ diff --git a/src/scripts/check-dco-trailers.sh b/src/scripts/check-dco-trailers.sh index c13b3ada08..7e0a469df0 100755 --- a/src/scripts/check-dco-trailers.sh +++ b/src/scripts/check-dco-trailers.sh @@ -67,7 +67,9 @@ Environment: SHAs with a recorded maintainer DCO disposition. A waived commit is reported as WAIVED instead of FAIL and does not fail the run. Abbreviated SHAs are rejected. Empty by default. - DCO_SKIP_BOT_AUTHORS true/false; skip bot-authored commits by default. + DCO_SKIP_BOT_AUTHORS true/false; skip the sign-off identity match for bot-authored + commits by default. A bot commit with NO Signed-off-by is + still reported as missing-signoff. DCO_GITHUB_REPOSITORY Optional owner/repo used for GitHub noreply author lookups. Defaults to GITHUB_REPOSITORY or origin. DCO_AUTHOR_LOGIN_MAP Optional comma/space/newline-separated SHA=login map @@ -334,6 +336,15 @@ while IFS= read -r sha; do author_name=$(git log -1 --format=%an "$sha") author_email=$(git log -1 --format=%ae "$sha") if [ "$skip_bots" = "true" ] && is_bot_author "$author_name" "$author_email"; then + # The skip covers the bot-address MATCHING edge cases only. A bot commit + # with no Signed-off-by at all is still a hole in the DCO trail: the + # hive's squash of #18079 landed f33758f5a on v5 that way and nothing + # saw it until a forward merge failed DCO (#18203). + if [ -z "$(extract_signoff_emails "$sha")" ]; then + checked=$((checked + 1)) + record_failure "$sha" "missing-signoff bot-author=${author_name} <${author_email}>" + continue + fi skipped_bots=$((skipped_bots + 1)) continue fi diff --git a/src/scripts/test-check-dco-trailers.sh b/src/scripts/test-check-dco-trailers.sh index 49dd93e029..7b26811555 100755 --- a/src/scripts/test-check-dco-trailers.sh +++ b/src/scripts/test-check-dco-trailers.sh @@ -530,6 +530,40 @@ else fi cd "$repo" || exit 1 +# Bot authors (#18203): DCO_SKIP_BOT_AUTHORS skips the sign-off identity match +# for a bot, never the missing-trailer check. A bot commit with no +# Signed-off-by (the shape of f33758f5a) fails; a signed bot commit is skipped. +bot_repo="$TMP/bot-repo" +mkdir -p "$bot_repo" +cd "$bot_repo" || exit 1 +git init -q +git config user.name 'hivecommons-hive[bot]' +git config user.email '280983584+hivecommons-hive[bot]@users.noreply.github.com' +echo signed > file.txt +git add file.txt +git commit -q -m $'bot signed commit\n\nSigned-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>' +bot_signed_sha=$(git rev-parse HEAD) +echo unsigned >> file.txt +git add file.txt +git commit -q -m $'bot squash without a sign-off\n\nCo-authored-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>' +bot_unsigned_sha=$(git rev-parse HEAD) +set +e +output=$(DCO_SKIP_BOT_AUTHORS=true bash "$CHECKER" 10 HEAD 2>&1); rc=$? +set -e +if [ "$rc" -eq 1 ] && out_grep -q "^FAIL ${bot_unsigned_sha} missing-signoff bot-author="; then + pass "a bot-authored commit with no sign-off is reported even when bots are skipped" +else + bad "unsigned bot commit ${bot_unsigned_sha} was not reported (rc=${rc})" + echo "$output" | sed 's/^/ | /' +fi +if out_grep -q "^FAIL ${bot_signed_sha}"; then + bad "a signed bot-authored commit should still be skipped" + echo "$output" | sed 's/^/ | /' +else + pass "a signed bot-authored commit is still skipped" +fi +cd "$repo" || exit 1 + if [ "$fail" -ne 0 ]; then echo "test-check-dco-trailers FAILED" exit 1