Remove new-branch commands
These have been replaced by the `sk` tool.
Change-Id: I07448eb5e5854c67651e12dda629d42f0f988471
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/434456
Commit-Queue: Eric Boren <borenet@google.com>
Reviewed-by: Ravi Mistry <rmistry@google.com>
diff --git a/go/cq/cmd/new-branch-cq/BUILD.bazel b/go/cq/cmd/new-branch-cq/BUILD.bazel
deleted file mode 100644
index 152beb8..0000000
--- a/go/cq/cmd/new-branch-cq/BUILD.bazel
+++ /dev/null
@@ -1,21 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
-
-go_library(
- name = "new-branch-cq_lib",
- srcs = ["main.go"],
- importpath = "go.skia.org/infra/go/cq/cmd/new-branch-cq",
- visibility = ["//visibility:private"],
- deps = [
- "//go/common",
- "//go/cq",
- "//go/git",
- "//go/sklog",
- "@com_github_bazelbuild_buildtools//build:go_default_library",
- ],
-)
-
-go_binary(
- name = "new-branch-cq",
- embed = [":new-branch-cq_lib"],
- visibility = ["//visibility:public"],
-)
diff --git a/go/cq/cmd/new-branch-cq/main.go b/go/cq/cmd/new-branch-cq/main.go
deleted file mode 100644
index c34315c..0000000
--- a/go/cq/cmd/new-branch-cq/main.go
+++ /dev/null
@@ -1,50 +0,0 @@
-package main
-
-import (
- "context"
- "flag"
- "path/filepath"
- "regexp"
-
- "github.com/bazelbuild/buildtools/build"
- "go.skia.org/infra/go/common"
- "go.skia.org/infra/go/cq"
- "go.skia.org/infra/go/git"
- "go.skia.org/infra/go/sklog"
-)
-
-var (
- configFile = flag.String("cfg-file", "", "commit-queue.cfg file to edit.")
- newBranch = flag.String("new-branch", "", "Short name of the new branch.")
- oldBranch = flag.String("old-branch", git.MasterBranch, "Short name of the existing branch whose config to copy.")
- excludeTrybots = common.NewMultiStringFlag("exclude-trybots", nil, "Regular expressions for trybot names to exclude.")
- includeExperimental = flag.Bool("include-experimental", false, "If true, include experimental trybots.")
- includeTreeCheck = flag.Bool("include-tree-check", false, "If true, include tree open check.")
-)
-
-func main() {
- common.Init()
-
- if *configFile == "" {
- sklog.Fatal("--cfg-file is required.")
- }
- if *newBranch == "" {
- sklog.Fatal("--new-branch is required.")
- }
- excludeTrybotRegexp := make([]*regexp.Regexp, 0, len(*excludeTrybots))
- for _, excludeTrybot := range *excludeTrybots {
- re, err := regexp.Compile(excludeTrybot)
- if err != nil {
- sklog.Fatalf("Failed to compile regular expression from %q; %s", excludeTrybot, err)
- }
- excludeTrybotRegexp = append(excludeTrybotRegexp, re)
- }
-
- ctx := context.Background()
- generatedDir := filepath.Join(filepath.Dir(*configFile), "generated")
- if err := cq.WithUpdateCQConfig(ctx, *configFile, generatedDir, func(f *build.File) error {
- return cq.CloneBranch(f, *oldBranch, *newBranch, *includeExperimental, *includeTreeCheck, excludeTrybotRegexp)
- }); err != nil {
- sklog.Fatal(err)
- }
-}
diff --git a/go/supported_branches/cmd/new-branch/BUILD.bazel b/go/supported_branches/cmd/new-branch/BUILD.bazel
deleted file mode 100644
index f5aae7c..0000000
--- a/go/supported_branches/cmd/new-branch/BUILD.bazel
+++ /dev/null
@@ -1,19 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
-
-go_library(
- name = "new-branch_lib",
- srcs = ["main.go"],
- importpath = "go.skia.org/infra/go/supported_branches/cmd/new-branch",
- visibility = ["//visibility:private"],
- deps = [
- "//go/common",
- "//go/sklog",
- "//go/supported_branches/cmd/new-branch/helper",
- ],
-)
-
-go_binary(
- name = "new-branch",
- embed = [":new-branch_lib"],
- visibility = ["//visibility:public"],
-)
diff --git a/go/supported_branches/cmd/new-branch/helper/BUILD.bazel b/go/supported_branches/cmd/new-branch/helper/BUILD.bazel
deleted file mode 100644
index c285300..0000000
--- a/go/supported_branches/cmd/new-branch/helper/BUILD.bazel
+++ /dev/null
@@ -1,20 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_library")
-
-go_library(
- name = "helper",
- srcs = ["helper.go"],
- importpath = "go.skia.org/infra/go/supported_branches/cmd/new-branch/helper",
- visibility = ["//visibility:public"],
- deps = [
- "//go/auth",
- "//go/cq",
- "//go/gerrit",
- "//go/git",
- "//go/gitiles",
- "//go/httputils",
- "//go/skerr",
- "//go/supported_branches",
- "//go/util",
- "@com_github_bazelbuild_buildtools//build:go_default_library",
- ],
-)
diff --git a/go/supported_branches/cmd/new-branch/helper/helper.go b/go/supported_branches/cmd/new-branch/helper/helper.go
deleted file mode 100644
index 690b770..0000000
--- a/go/supported_branches/cmd/new-branch/helper/helper.go
+++ /dev/null
@@ -1,172 +0,0 @@
-package helper
-
-import (
- "bytes"
- "context"
- "fmt"
- "io/fs"
- "io/ioutil"
- "os"
- "path/filepath"
- "regexp"
- "strings"
-
- "github.com/bazelbuild/buildtools/build"
-
- "go.skia.org/infra/go/auth"
- "go.skia.org/infra/go/cq"
- "go.skia.org/infra/go/gerrit"
- "go.skia.org/infra/go/git"
- "go.skia.org/infra/go/gitiles"
- "go.skia.org/infra/go/httputils"
- "go.skia.org/infra/go/skerr"
- "go.skia.org/infra/go/supported_branches"
- "go.skia.org/infra/go/util"
-)
-
-const DefaultMainStarFile = "main.star"
-
-// AddSupportedBranch adds a new supported branch, optionally deleting an old
-// supported branch.
-func AddSupportedBranch(repoUrl, branch, owner, deleteBranch string, excludeTrybots []string, submit bool) error {
- newRef := git.FullyQualifiedBranchName(branch)
- excludeTrybotRegexp := make([]*regexp.Regexp, 0, len(excludeTrybots))
- for _, excludeTrybot := range excludeTrybots {
- re, err := regexp.Compile(excludeTrybot)
- if err != nil {
- return skerr.Wrapf(err, "failed to compile regular expression from %q", excludeTrybot)
- }
- excludeTrybotRegexp = append(excludeTrybotRegexp, re)
- }
-
- // Setup.
- wd, err := ioutil.TempDir("", "new-branch")
- if err != nil {
- return skerr.Wrap(err)
- }
- defer util.RemoveAll(wd)
-
- ts, err := auth.NewDefaultTokenSource(true, auth.SCOPE_GERRIT)
- if err != nil {
- return skerr.Wrap(err)
- }
- client := httputils.DefaultClientConfig().WithTokenSource(ts).Client()
- gUrl := strings.Split(repoUrl, ".googlesource.com")[0] + "-review.googlesource.com"
- g, err := gerrit.NewGerrit(gUrl, client)
- if err != nil {
- return skerr.Wrap(err)
- }
- repo := gitiles.NewRepo(repoUrl, client)
- ctx := context.Background()
- baseCommitInfo, err := repo.Details(ctx, cq.CQ_CFG_REF)
- if err != nil {
- return skerr.Wrap(err)
- }
- baseCommit := baseCommitInfo.Hash
- tmp, err := ioutil.TempDir("", "")
- if err != nil {
- return skerr.Wrap(err)
- }
- defer util.RemoveAll(tmp)
-
- // Download the CQ config file and modify it.
- mainStarFile := filepath.Join(tmp, DefaultMainStarFile)
- if err := repo.DownloadFileAtRef(ctx, DefaultMainStarFile, baseCommit, mainStarFile); err != nil {
- return skerr.Wrapf(err, "failed to download %q", DefaultMainStarFile)
- }
- if err := cq.WithUpdateCQConfig(ctx, mainStarFile, filepath.Join(tmp, "generated"), func(f *build.File) error {
- _, _, err := cq.FindExprForBranch(f, branch)
- if err == nil {
- _, _ = fmt.Fprintf(os.Stderr, "Already have %s in %s; not adding a duplicate.\n", newRef, cq.CQ_CFG_FILE)
- } else {
- if err := cq.CloneBranch(f, git.MainBranch, git.BranchBaseName(branch), false, false, excludeTrybotRegexp); err != nil {
- return skerr.Wrap(err)
- }
- }
- if deleteBranch != "" {
- if _, _, err := cq.FindExprForBranch(f, deleteBranch); err == nil {
- if err := cq.DeleteBranch(f, deleteBranch); err != nil {
- return skerr.Wrap(err)
- }
- }
- }
- return nil
- }); err != nil {
- return skerr.Wrap(err)
- }
-
- // Download and modify the supported-branches.json file.
- branchesContents, err := repo.ReadFileAtRef(ctx, supported_branches.SUPPORTED_BRANCHES_FILE, baseCommit)
- if err != nil {
- return skerr.Wrap(err)
- }
- sbc, err := supported_branches.DecodeConfig(bytes.NewReader(branchesContents))
- if err != nil {
- return skerr.Wrap(err)
- }
- deleteRef := ""
- if deleteBranch != "" {
- deleteRef = git.FullyQualifiedBranchName(deleteBranch)
- }
- foundNewRef := false
- newBranches := make([]*supported_branches.SupportedBranch, 0, len(sbc.Branches)+1)
- for _, sb := range sbc.Branches {
- if deleteRef == "" || deleteRef != sb.Ref {
- newBranches = append(newBranches, sb)
- }
- if sb.Ref == newRef {
- foundNewRef = true
- }
- }
- if foundNewRef {
- _, _ = fmt.Fprintf(os.Stderr, "Already have %s in %s; not adding a duplicate.\n", newRef, supported_branches.SUPPORTED_BRANCHES_FILE)
- } else {
- newBranches = append(newBranches, &supported_branches.SupportedBranch{
- Ref: newRef,
- Owner: owner,
- })
- }
- sbc.Branches = newBranches
- buf := bytes.Buffer{}
- if err := supported_branches.EncodeConfig(&buf, sbc); err != nil {
- return skerr.Wrap(err)
- }
-
- // Create the Gerrit CL.
- commitMsg := fmt.Sprintf("Add supported branch %s", branch)
- if deleteBranch != "" {
- commitMsg += fmt.Sprintf(", remove %s", deleteBranch)
- }
- repoSplit := strings.Split(repoUrl, "/")
- project := strings.TrimSuffix(repoSplit[len(repoSplit)-1], ".git")
- changes := map[string]string{
- supported_branches.SUPPORTED_BRANCHES_FILE: string(buf.Bytes()),
- }
- if err := filepath.Walk(tmp, func(path string, info fs.FileInfo, err error) error {
- if !info.IsDir() {
- relpath, err := filepath.Rel(tmp, path)
- if err != nil {
- return skerr.Wrap(err)
- }
- contents, err := ioutil.ReadFile(path)
- if err != nil {
- return skerr.Wrap(err)
- }
- remoteContents, err := repo.ReadFileAtRef(ctx, relpath, cq.CQ_CFG_REF)
- if err != nil {
- return skerr.Wrapf(err, "failed to retrieve %q", relpath)
- }
- if string(contents) != string(remoteContents) {
- changes[relpath] = string(contents)
- }
- }
- return nil
- }); err != nil {
- return skerr.Wrap(err)
- }
- ci, err := gerrit.CreateCLWithChanges(ctx, g, project, cq.CQ_CFG_REF, commitMsg, baseCommit, changes, submit)
- if ci != nil {
- fmt.Println(fmt.Sprintf("Uploaded change %s", g.Url(ci.Issue)))
- }
- return skerr.Wrap(err)
-}
diff --git a/go/supported_branches/cmd/new-branch/main.go b/go/supported_branches/cmd/new-branch/main.go
deleted file mode 100644
index 781e0db..0000000
--- a/go/supported_branches/cmd/new-branch/main.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package main
-
-import (
- "flag"
-
- "go.skia.org/infra/go/common"
- "go.skia.org/infra/go/sklog"
- "go.skia.org/infra/go/supported_branches/cmd/new-branch/helper"
-)
-
-var (
- // Flags.
- branch = flag.String("branch", "", "Name of the new branch, without refs/heads prefix.")
- deleteBranch = flag.String("delete", "", "Name of an existing branch to delete, without refs/heads prefix.")
- excludeTrybots = common.NewMultiStringFlag("exclude-trybots", nil, "Regular expressions for trybot names to exclude.")
- owner = flag.String("owner", "", "Owner of the new branch.")
- repoUrl = flag.String("repo", common.REPO_SKIA, "URL of the git repository.")
- submit = flag.Bool("submit", false, "If set, automatically submit the CL to update the CQ and supported branches.")
-)
-
-func main() {
- common.Init()
-
- if *branch == "" {
- sklog.Fatal("--branch is required.")
- }
- if *owner == "" {
- sklog.Fatal("--owner is required.")
- }
- if err := helper.AddSupportedBranch(*repoUrl, *branch, *owner, *deleteBranch, *excludeTrybots, *submit); err != nil {
- sklog.Fatal(err)
- }
-}