fix(workflow): publish a baseline repair as a PR before the task continues (#1844)
Dependents now wait for the baseline gate to pass on the base branch instead of a specific branch merging.
This commit is contained in:
7 files changed
+79
-6
No files matched your search
@@ -16,7 +16,7 @@ type BaselineClaim struct {
|
||||
// Task is the task that owns the repair when Lead is false.
|
||||
Task int64
|
||||
// Done is true once that task has finished; Failure is its failure, empty
|
||||
// when it repaired the baseline on its own branch.
|
||||
// when it repaired the baseline in a pull request.
|
||||
Done bool
|
||||
Failure string
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestRedBaselineIsRepairedByOneTask(t *testing.T) {
|
||||
{
|
||||
name: "a task reuses a repair made on another branch",
|
||||
claims: []BaselineClaim{{Task: 7, Done: true}},
|
||||
wantInErr: "task 7 repaired it on its own branch",
|
||||
wantInErr: "task 7 repaired it in a pull request",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
)
|
||||
|
||||
type prRecorder struct {
|
||||
Forger
|
||||
created int
|
||||
}
|
||||
|
||||
func (f *prRecorder) CreatePR(context.Context, string, string, string, string, string, string) (int, error) {
|
||||
f.created++
|
||||
return 42, nil
|
||||
}
|
||||
|
||||
// A baseline repair is published as a PR before the task continues, and the
|
||||
// task's own PR joins it instead of opening a second.
|
||||
func TestBaselineRepairPRIsReusedByTheTaskPR(t *testing.T) {
|
||||
forge := &prRecorder{}
|
||||
trees := &noChangesTrees{}
|
||||
tc := &TaskContext{
|
||||
Task: &task.Task{ID: 1, Owner: "acme", Repo: "widgets", Source: task.SourceTest},
|
||||
Repo: config.Repo{Owner: "acme", Name: "widgets"},
|
||||
Forge: forge,
|
||||
Trees: trees,
|
||||
Branch: "archie/1",
|
||||
}
|
||||
if err := publishBaselineRepair(t.Context(), tc, []string{"task", "check"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !trees.pushed || tc.BaselinePR != 42 || forge.created != 1 {
|
||||
t.Fatalf("pushed=%v pr=%d created=%d, want pushed, 42, 1", trees.pushed, tc.BaselinePR, forge.created)
|
||||
}
|
||||
if err := OpenPR(t.Context(), tc, "body"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if forge.created != 1 {
|
||||
t.Fatalf("OpenPR created a second PR (%d)", forge.created)
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func baselineEnvironmentError(argv []string, out, cause string) error {
|
||||
// baselineSharedError is the park reason for a task that did not repair the
|
||||
// baseline because another task owns that repair.
|
||||
func baselineSharedError(argv []string, out string, claim BaselineClaim) error {
|
||||
verdict := fmt.Sprintf("task %d repaired it on its own branch; retry once that change is merged", claim.Task)
|
||||
verdict := fmt.Sprintf("task %d repaired it in a pull request; retry once the baseline gate passes on the base branch", claim.Task)
|
||||
if claim.Failure != "" {
|
||||
verdict = fmt.Sprintf("task %d could not repair it: %s", claim.Task, claim.Failure)
|
||||
}
|
||||
|
||||
@@ -126,6 +126,28 @@ func runBaselineFix(ctx context.Context, tc *TaskContext, argv []string, out []b
|
||||
tc.BuildSummary = res.Summary
|
||||
tc.BaselineFixed = true
|
||||
tc.captureChanges(ctx, capturedAfterBaselineFix)
|
||||
if err := publishBaselineRepair(ctx, tc, argv); err != nil {
|
||||
return baselineFixFailedError(argv, string(out), fmt.Sprintf("the repair could not be published: %v", err))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// publishBaselineRepair pushes the repair and opens its PR before the task
|
||||
// goes on, so the repair survives this task parking or being deleted. The
|
||||
// task's own PR later reuses this one.
|
||||
func publishBaselineRepair(ctx context.Context, tc *TaskContext, argv []string) error {
|
||||
if err := tc.Trees.Push(ctx, tc.Dir, tc.Branch); err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := strings.Join(argv, " ")
|
||||
body := fmt.Sprintf("The baseline gate `%s` failed on %s before any feature work; this repairs it.",
|
||||
cmd, tc.Repo.BaseBranch())
|
||||
num, err := tc.Forge.CreatePR(ctx, tc.Task.Owner, tc.Task.Repo,
|
||||
fmt.Sprintf("fix: baseline gate repair (%s)", cmd), tc.Branch, tc.Repo.BaseBranch(), body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tc.BaselinePR = num
|
||||
return nil
|
||||
}
|
||||
@@ -154,9 +154,12 @@ func OpenPR(ctx context.Context, tc *TaskContext, body string) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
num, err := tc.Forge.CreatePR(ctx, t.Owner, t.Repo, title, tc.Branch, tc.Repo.BaseBranch(), body)
|
||||
if err != nil {
|
||||
return err
|
||||
num := tc.BaselinePR
|
||||
if num == 0 {
|
||||
var err error
|
||||
if num, err = tc.Forge.CreatePR(ctx, t.Owner, t.Repo, title, tc.Branch, tc.Repo.BaseBranch(), body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if t.IsTestRun() {
|
||||
// No PR exists to watch, so the run ends here rather than as pr_open.
|
||||
|
||||
@@ -168,6 +168,9 @@ type TaskContext struct {
|
||||
// BaselineFixed is set when StageBaselineGate committed a fix, so
|
||||
// StageCommitPush pushes it even when the build changed nothing.
|
||||
BaselineFixed bool
|
||||
// BaselinePR is the PR StageBaselineGate opened for its fix; the task's
|
||||
// own change joins it rather than opening a second.
|
||||
BaselinePR int
|
||||
// ReproProof is the captured failing-test output from a TDD repro
|
||||
// stage, posted on the PR as evidence the bug was reproduced.
|
||||
ReproProof string
|
||||
|
||||
Reference in new issue
Block a user