Skip to content

Commit bbd61d3

Browse files
dmitshurgopherbot
authored andcommitted
internal/task: add detection for repeated task runs
The expected happy path is that the "between freeze start and RC 1" workflow is run once to completion and not again. Still, it might happen that we run it more than once, intentionally or accidentally. Add logic, within reason, to detect repeated runs and avoid taking inappropriate actions. For golang/go#70655. Change-Id: Ifb4bcc4e5aea0087784337fc3e84a90e54a1af18 Reviewed-on: https://go-review.googlesource.com/c/build/+/633755 Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent de88bf6 commit bbd61d3

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

internal/task/releasecycle.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package task
66

77
import (
88
"bytes"
9+
"errors"
910
"fmt"
1011
"io/fs"
1112
"path"
@@ -55,6 +56,18 @@ func (t ReleaseCycleTasks) PromoteNextAPI(ctx *wf.TaskContext, version int, revi
5556
}
5657
ctx.Printf("Using commit %q as the branch head.", commit)
5758

59+
// Confirm that "api/go1.{version}.txt" hasn't already been made.
60+
promotedAPIFile := path.Join("api", fmt.Sprintf("go1.%d.txt", version))
61+
_, err = t.Gerrit.ReadFile(ctx, "go", commit, promotedAPIFile)
62+
if err == nil {
63+
ctx.Printf("The %s file is already created, so refusing to run this task (and tasks that depend on it).", promotedAPIFile)
64+
return PromotedAPI{}, fmt.Errorf("%s already exists; the scope of this task is to create that file only", promotedAPIFile)
65+
} else if errors.Is(err, gerrit.ErrResourceNotExist) {
66+
// OK. We'll be creating it below.
67+
} else if err != nil {
68+
return PromotedAPI{}, err
69+
}
70+
5871
// Read api/next files at commit.
5972
var files = make(map[string]string)
6073
des, err := t.Gerrit.ReadDir(ctx, "go", commit, "api/next")
@@ -89,7 +102,7 @@ func (t ReleaseCycleTasks) PromoteNextAPI(ctx *wf.TaskContext, version int, revi
89102
for _, api := range promoted.APIs {
90103
fmt.Fprintln(&buf, api)
91104
}
92-
files[path.Join("api", fmt.Sprintf("go1.%d.txt", version))] = buf.String()
105+
files[promotedAPIFile] = buf.String()
93106

94107
// Beyond this point we want retries to be done manually, not automatically.
95108
ctx.DisableRetries()
@@ -238,6 +251,24 @@ func (t ReleaseCycleTasks) MergeNextRelnoteAndAddToWebsite(ctx *wf.TaskContext,
238251
}
239252
ctx.Printf("Using commit %q as the branch head.", commit)
240253

254+
// Confirm that fragments haven't been merged into "_content/doc/go1.{version}.md" yet.
255+
const (
256+
// knownSubstringForPlaceholder is a substring used to identify when go1.N.md is still
257+
// just a placeholder template like in CL 600179, without release note fragments merged in.
258+
// We need some way of detecting whether the merge happened, and this will have to do.
259+
knownSubstringForPlaceholder = "Eventually the release note fragments in doc/next will be merged"
260+
)
261+
mergedRelnoteFile := fmt.Sprintf("_content/doc/go1.%d.md", version)
262+
b, err := t.Gerrit.ReadFile(ctx, "website", commit.String(), mergedRelnoteFile)
263+
if err == nil && !bytes.Contains(b, []byte(knownSubstringForPlaceholder)) {
264+
ctx.Printf("Release note fragments seem to be merged into %s in x/website, so refusing to run this task (and tasks that depend on it).", mergedRelnoteFile)
265+
return NextRelnote{}, fmt.Errorf("%s already has merged fragments; the scope of this task is to merge fragments into that file only", mergedRelnoteFile)
266+
} else if errors.Is(err, gerrit.ErrResourceNotExist) {
267+
// OK. We'll be creating it below.
268+
} else if err != nil {
269+
return NextRelnote{}, err
270+
}
271+
241272
// Collect all doc/next files to merge.
242273
root, err := goRepo.CloneHash(commit)
243274
if err != nil {
@@ -251,7 +282,7 @@ func (t ReleaseCycleTasks) MergeNextRelnoteAndAddToWebsite(ctx *wf.TaskContext,
251282
if err != nil {
252283
return NextRelnote{}, fmt.Errorf("relnote.Merge: %v", err)
253284
}
254-
mergedRelnote := fmt.Sprintf(`---
285+
mergedRelnoteContent := fmt.Sprintf(`---
255286
title: Go 1.%d Release Notes
256287
template: false
257288
---
@@ -269,9 +300,7 @@ template: false
269300
Using doc/next content as of %s (commit %s).
270301
271302
For golang/go#%d.`, version, time.Now().Format(time.DateOnly), commit, releaseNotesIssue),
272-
}, reviewers, map[string]string{
273-
fmt.Sprintf("_content/doc/go1.%d.md", version): mergedRelnote,
274-
})
303+
}, reviewers, map[string]string{mergedRelnoteFile: mergedRelnoteContent})
275304
if err != nil {
276305
return NextRelnote{}, err
277306
}

0 commit comments

Comments
 (0)