Skip to content

Commit

Permalink
internal/task: allow release blockers with approval
Browse files Browse the repository at this point in the history
For security releases we expect there to be release blockers that will
be resolved only after the release is published. Allow the coordinator
to approve that situation.

For golang/go#53799.

Change-Id: I94cd4c0b3c7b3af22557ca19be19ac923add9b86
Reviewed-on: https://go-review.googlesource.com/c/build/+/426799
Run-TryBot: Heschi Kreinick <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Auto-Submit: Heschi Kreinick <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
heschi authored and gopherbot committed Aug 31, 2022
1 parent f08b7e7 commit d7b416f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
5 changes: 3 additions & 2 deletions cmd/relui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ func main() {
V3: github.NewClient(githubHTTPClient),
V4: githubv4.NewClient(githubHTTPClient),
},
RepoOwner: "golang",
RepoName: "go",
RepoOwner: "golang",
RepoName: "go",
ApproveAction: relui.ApproveActionDep(dbPool),
}
if err := relui.RegisterReleaseWorkflows(ctx, dh, buildTasks, milestoneTasks, versionTasks, commTasks); err != nil {
log.Fatalf("RegisterReleaseWorkflows: %v", err)
Expand Down
5 changes: 4 additions & 1 deletion internal/relui/buildrelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func newReleaseTestDeps(t *testing.T, wantVersion string) *releaseTestDeps {
Client: &fakeGitHub{},
RepoOwner: "golang",
RepoName: "go",
ApproveAction: func(ctx *workflow.TaskContext) error {
return fmt.Errorf("unexpected approval request for %q", ctx.TaskName)
},
}

snapshotServer := httptest.NewServer(http.HandlerFunc(serveSnapshot))
Expand All @@ -147,7 +150,7 @@ func newReleaseTestDeps(t *testing.T, wantVersion string) *releaseTestDeps {
if strings.Contains(ctx.TaskName, "Release Coordinator Approval") {
return nil
}
return fmt.Errorf("unexpected approval for %q", ctx.TaskName)
return fmt.Errorf("unexpected approval request for %q", ctx.TaskName)
},
}
// Cleanups are called in reverse order, and we need to cancel the context
Expand Down
19 changes: 11 additions & 8 deletions internal/task/milestones.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (

"github.com/google/go-github/github"
"github.com/shurcooL/githubv4"
"golang.org/x/build/internal/workflow"
wf "golang.org/x/build/internal/workflow"
goversion "golang.org/x/build/maintner/maintnerd/maintapi/version"
)

// MilestoneTasks contains the tasks used to check and modify GitHub issues' milestones.
type MilestoneTasks struct {
Client GitHubClientInterface
RepoOwner, RepoName string
ApproveAction func(*wf.TaskContext) error
}

// ReleaseKind is the type of release being run.
Expand All @@ -38,7 +39,7 @@ type ReleaseMilestones struct {
// released, and the next version that outstanding issues should be moved to.
// If this is a major release, it also creates its first minor release
// milestone.
func (m *MilestoneTasks) FetchMilestones(ctx *workflow.TaskContext, currentVersion string, kind ReleaseKind) (ReleaseMilestones, error) {
func (m *MilestoneTasks) FetchMilestones(ctx *wf.TaskContext, currentVersion string, kind ReleaseKind) (ReleaseMilestones, error) {
x, ok := goversion.Go1PointX(currentVersion)
if !ok {
return ReleaseMilestones{}, fmt.Errorf("could not parse %q as a Go version", currentVersion)
Expand Down Expand Up @@ -82,7 +83,7 @@ func uppercaseVersion(version string) string {

// CheckBlockers returns an error if there are open release blockers in
// the current milestone.
func (m *MilestoneTasks) CheckBlockers(ctx *workflow.TaskContext, milestones ReleaseMilestones, version string, kind ReleaseKind) error {
func (m *MilestoneTasks) CheckBlockers(ctx *wf.TaskContext, milestones ReleaseMilestones, version string, kind ReleaseKind) error {
if kind == KindRC {
// We don't check blockers for release candidates; they're expected to
// at least have recurring blockers, and we don't have an okay-after
Expand All @@ -104,15 +105,17 @@ func (m *MilestoneTasks) CheckBlockers(ctx *workflow.TaskContext, milestones Rel
}
}
sort.Strings(blockers)
if len(blockers) != 0 {
return fmt.Errorf("open release blockers:\n%v", strings.Join(blockers, "\n"))
if len(blockers) == 0 {
return nil
}
return nil
ctx.Printf("There are open release blockers in https://github.com/golang/go/milestone/%d. Check that they're expected and approve this task:\n%v",
milestones.Current, strings.Join(blockers, "\n"))
return m.ApproveAction(ctx)
}

// loadMilestoneIssues returns all the open issues in the specified milestone
// and their labels.
func (m *MilestoneTasks) loadMilestoneIssues(ctx *workflow.TaskContext, milestoneID int, kind ReleaseKind) (map[int]map[string]bool, error) {
func (m *MilestoneTasks) loadMilestoneIssues(ctx *wf.TaskContext, milestoneID int, kind ReleaseKind) (map[int]map[string]bool, error) {
issues := map[int]map[string]bool{}
var query struct {
Repository struct {
Expand Down Expand Up @@ -168,7 +171,7 @@ more:
// PushIssues updates issues to reflect a finished release. For beta1 releases,
// it removes the okay-after-beta1 label. For major and minor releases,
// it moves them to the next milestone and closes the current one.
func (m *MilestoneTasks) PushIssues(ctx *workflow.TaskContext, milestones ReleaseMilestones, version string, kind ReleaseKind) error {
func (m *MilestoneTasks) PushIssues(ctx *wf.TaskContext, milestones ReleaseMilestones, version string, kind ReleaseKind) error {
// For RCs we don't change issues at all.
if kind == KindRC {
return nil
Expand Down
3 changes: 3 additions & 0 deletions internal/task/milestones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func TestMilestones(t *testing.T) {
},
RepoOwner: *flagOwner,
RepoName: *flagRepo,
ApproveAction: func(*workflow.TaskContext) error {
return fmt.Errorf("not approved")
},
}
milestones, err := tasks.FetchMilestones(ctx, "go1.20", KindMajor)
if err != nil {
Expand Down

0 comments on commit d7b416f

Please sign in to comment.