Skip to content

Commit

Permalink
gopls/release: remove unused functionality from release script
Browse files Browse the repository at this point in the history
Narrow the scope of the release script to simply verifying that the
release is ready. Remove:

- checks for the release branch; the current branch doesn't matter for
  tagging
- the -release and -remote flags, since we won't be using this script
  for performing the release

Updates golang/go#57643

Change-Id: I80a5e367ad5b7df1d85f3af023dc10ccef242702
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462815
Reviewed-by: Dylan Le <dungtuanle@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
  • Loading branch information
findleyr committed Jan 19, 2023
1 parent 46b6958 commit 7d4ba2f
Showing 1 changed file with 3 additions and 64 deletions.
67 changes: 3 additions & 64 deletions gopls/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"io/ioutil"
"log"
"os"
"os/user"
"path/filepath"
"strconv"
"strings"
Expand All @@ -30,11 +29,7 @@ import (
"golang.org/x/tools/go/packages"
)

var (
versionFlag = flag.String("version", "", "version to tag")
remoteFlag = flag.String("remote", "", "remote to which to push the tag")
releaseFlag = flag.Bool("release", false, "release is true if you intend to tag and push a release")
)
var versionFlag = flag.String("version", "", "version to tag")

func main() {
flag.Parse()
Expand All @@ -51,13 +46,6 @@ func main() {
if semver.Build(*versionFlag) != "" {
log.Fatalf("unexpected build suffix: %s", *versionFlag)
}
if *releaseFlag && *remoteFlag == "" {
log.Fatalf("must provide -remote flag if releasing")
}
user, err := user.Current()
if err != nil {
log.Fatal(err)
}
// Validate that the user is running the program from the gopls module.
wd, err := os.Getwd()
if err != nil {
Expand All @@ -66,11 +54,6 @@ func main() {
if filepath.Base(wd) != "gopls" {
log.Fatalf("must run from the gopls module")
}
// Confirm that they are running on a branch with a name following the
// format of "gopls-release-branch.<major>.<minor>".
if err := validateBranchName(*versionFlag); err != nil {
log.Fatal(err)
}
// Confirm that they have updated the hardcoded version.
if err := validateHardcodedVersion(*versionFlag); err != nil {
log.Fatal(err)
Expand All @@ -79,52 +62,8 @@ func main() {
if err := validateGoModFile(wd); err != nil {
log.Fatal(err)
}
earlyExitMsg := "Validated that the release is ready. Exiting without tagging and publishing."
if !*releaseFlag {
fmt.Println(earlyExitMsg)
os.Exit(0)
}
fmt.Println(`Proceeding to tagging and publishing the release...
Please enter Y if you wish to proceed or anything else if you wish to exit.`)
// Accept and process user input.
var input string
fmt.Scanln(&input)
switch input {
case "Y":
fmt.Println("Proceeding to tagging and publishing the release.")
default:
fmt.Println(earlyExitMsg)
os.Exit(0)
}
// To tag the release:
// $ git -c user.email=username@google.com tag -a -m “<message>” gopls/v<major>.<minor>.<patch>-<pre-release>
goplsVersion := fmt.Sprintf("gopls/%s", *versionFlag)
cmd := exec.Command("git", "-c", fmt.Sprintf("user.email=%s@google.com", user.Username), "tag", "-a", "-m", fmt.Sprintf("%q", goplsVersion), goplsVersion)
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
// Push the tag to the remote:
// $ git push <remote> gopls/v<major>.<minor>.<patch>-pre.1
cmd = exec.Command("git", "push", *remoteFlag, goplsVersion)
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}

// validateBranchName reports whether the user's current branch name is of the
// form "gopls-release-branch.<major>.<minor>". It reports an error if not.
func validateBranchName(version string) error {
cmd := exec.Command("git", "branch", "--show-current")
stdout, err := cmd.Output()
if err != nil {
return err
}
branch := strings.TrimSpace(string(stdout))
expectedBranch := fmt.Sprintf("gopls-release-branch.%s", strings.TrimPrefix(semver.MajorMinor(version), "v"))
if branch != expectedBranch {
return fmt.Errorf("expected release branch %s, got %s", expectedBranch, branch)
}
return nil
fmt.Println("Validated that the release is ready.")
os.Exit(0)
}

// validateHardcodedVersion reports whether the version hardcoded in the gopls
Expand Down

0 comments on commit 7d4ba2f

Please sign in to comment.