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
2 changes: 1 addition & 1 deletion .github/scripts/integration-governance.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) =>
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/dco-post-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions changelog.d/fixed-18203-squash-signoff.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/pkg/github/automerge/automerge_contributor_lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/pkg/github/automerge/automerge_current_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"}})
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/pkg/github/automerge/automerge_human_paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
}
}

Expand Down
30 changes: 21 additions & 9 deletions src/pkg/github/automerge/automerge_merge_credit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
23 changes: 15 additions & 8 deletions src/pkg/github/automerge/automerge_merge_credit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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] <hive@example.com>\nCo-authored-by: Dana Thar <12345+Danathar@users.noreply.github.com>"},
want: "Signed-off-by: hive[bot] <hive@example.com>\nCo-authored-by: Dana Thar <12345+Danathar@users.noreply.github.com>",
},
{
name: "branch lacks the trailer",
Expand Down
5 changes: 4 additions & 1 deletion src/pkg/github/automerge/automerge_sweep_queued.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading