-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/task: start x repo tagging tasks
First step: list all our projects/repositories, and select those that have a go.mod labeling them as golang.org/x as candidates to release as the next version, or v0.1.0 for untagged repositories. For golang/go#48523. Change-Id: Ice92319a0726daf3bf5f94581582d8802640dffc Reviewed-on: https://go-review.googlesource.com/c/build/+/425088 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Heschi Kreinick <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
Showing
7 changed files
with
219 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package task | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"golang.org/x/build/gerrit" | ||
wf "golang.org/x/build/internal/workflow" | ||
"golang.org/x/mod/modfile" | ||
"golang.org/x/mod/semver" | ||
) | ||
|
||
type TagXReposTasks struct { | ||
Gerrit GerritClient | ||
} | ||
|
||
type TagRepo struct { | ||
Name string | ||
Next string | ||
Deps []string | ||
} | ||
|
||
func (x *TagXReposTasks) SelectRepos(ctx *wf.TaskContext) ([]*TagRepo, error) { | ||
projects, err := x.Gerrit.ListProjects(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ctx.Printf("Examining repositories %v", projects) | ||
var repos []*TagRepo | ||
for _, p := range projects { | ||
repo, err := x.readRepo(ctx, p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if repo != nil { | ||
repos = append(repos, repo) | ||
} | ||
} | ||
return repos, nil | ||
} | ||
|
||
func (x *TagXReposTasks) readRepo(ctx *wf.TaskContext, project string) (*TagRepo, error) { | ||
head, err := x.Gerrit.ReadBranchHead(ctx, project, "master") | ||
if errors.Is(err, gerrit.ErrResourceNotExist) { | ||
ctx.Printf("ignoring %v: no master branch: %v", project, err) | ||
return nil, nil | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
gomod, err := x.Gerrit.ReadFile(ctx, project, head, "go.mod") | ||
if errors.Is(err, gerrit.ErrResourceNotExist) { | ||
ctx.Printf("ignoring %v: no go.mod: %v", project, err) | ||
return nil, nil | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
mf, err := modfile.ParseLax("go.mod", gomod, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !strings.HasPrefix(mf.Module.Mod.Path, "golang.org/x") { | ||
ctx.Printf("ignoring %v: not golang.org/x", project) | ||
return nil, nil | ||
} | ||
|
||
tags, err := x.Gerrit.ListTags(ctx, project) | ||
if err != nil { | ||
return nil, err | ||
} | ||
highestRelease := "" | ||
for _, tag := range tags { | ||
if semver.IsValid(tag) && semver.Prerelease(tag) == "" && | ||
(highestRelease == "" || semver.Compare(highestRelease, tag) < 0) { | ||
highestRelease = tag | ||
} | ||
} | ||
nextTag := "v0.1.0" | ||
if highestRelease != "" { | ||
var err error | ||
nextTag, err = nextVersion(highestRelease) | ||
if err != nil { | ||
return nil, fmt.Errorf("couldn't pick next version for %v: %v", project, err) | ||
} | ||
} | ||
|
||
result := &TagRepo{ | ||
Name: project, | ||
Next: nextTag, | ||
} | ||
for _, req := range mf.Require { | ||
if strings.HasPrefix(req.Mod.Path, "golang.org/x") { | ||
result.Deps = append(result.Deps, req.Mod.Path) | ||
} | ||
} | ||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package task | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"testing" | ||
|
||
"golang.org/x/build/gerrit" | ||
"golang.org/x/build/internal/workflow" | ||
) | ||
|
||
var flagRunTagXTest = flag.Bool("run-tagx-test", false, "run tag x/ repo test, which is read-only and safe. Must have a Gerrit cookie in gitcookies.") | ||
|
||
func TestSelectReposLive(t *testing.T) { | ||
if !*flagRunTagXTest { | ||
t.Skip("Not enabled by flags") | ||
} | ||
|
||
tasks := &TagXReposTasks{ | ||
Gerrit: &RealGerritClient{ | ||
Client: gerrit.NewClient("https://go-review.googlesource.com", gerrit.GitCookiesAuth()), | ||
}, | ||
} | ||
ctx := &workflow.TaskContext{ | ||
Context: context.Background(), | ||
Logger: &testLogger{t}, | ||
} | ||
repos, err := tasks.SelectRepos(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, r := range repos { | ||
t.Logf("%#v", r) | ||
} | ||
} |