Skip to content

Commit

Permalink
prepare rules_go release 0.51.0-rc2 (#4183)
Browse files Browse the repository at this point in the history
**What type of PR is this?**

Bug fix

**What does this PR do? Why is it needed?**

Deprecates the `RULES_GO_VERSION` constant in favor of `bazel_dep` and
keeps it at `0.50.0` for legacy consumers that may not be able to parse
RC suffixes.

**Which issues(s) does this PR fix?**

**Other notes for review**
  • Loading branch information
fmeum authored Dec 2, 2024
1 parent e8adba2 commit a103a08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
7 changes: 4 additions & 3 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ _TOOLS_NOGO = [
# new analyses may discover issues in existing builds.
TOOLS_NOGO = [str(Label(l)) for l in _TOOLS_NOGO]

# Current version or next version to be tagged. Gazelle and other tools may
# check this to determine compatibility.
RULES_GO_VERSION = "0.51.0-rc1"
# Deprecated field previously used for version detection. This will not be
# updated for new releases, use bazel_dep in MODULE.bazel to specify a minimum
# version of rules_go instead.
RULES_GO_VERSION = "0.50.0"

go_context = _go_context
gomock = _gomock
Expand Down
28 changes: 2 additions & 26 deletions go/tools/releaser/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ with review. Specifically, prepare does the following:
* Creates the release branch if it doesn't exist locally. Release branches
have names like "release-X.Y" where X and Y are the major and minor version
numbers.
* Checks that RULES_GO_VERSION is set in go/def.bzl on the local release branch
for the minor version being released. RULES_GO_VERSION must be a sematic
version without the "v" prefix that Go uses, like "1.2.4". It must match
the -version flag, which does require the "v" prefix.
* Creates an archive zip file from the tip of the local release branch.
* Creates or updates a draft GitHub release with the given release notes.
http_archive boilerplate is generated and appended to the release notes.
Expand Down Expand Up @@ -109,10 +105,9 @@ func runPrepare(ctx context.Context, stderr io.Writer, args []string) error {
return fmt.Errorf("release %s was already published", version)
}

// Check that RULES_GO_VERSION is set correctly on the release branch.
// If this is a minor release (x.y.0), create the release branch if it
// does not exist.
fmt.Fprintf(stderr, "checking RULES_GO_VERSION...\n")
fmt.Fprintf(stderr, "verifying release branch...\n")
rootDir, err := repoRoot()
if err != nil {
return err
Expand All @@ -125,19 +120,12 @@ func runPrepare(ctx context.Context, stderr io.Writer, args []string) error {
branchName := "release-" + majorMinor[len("v"):]
if !gitBranchExists(ctx, rootDir, branchName) {
if !isMinorRelease {
return fmt.Errorf("release branch %q does not exist locally. Fetch it, set RULES_GO_VERSION, add commits, and run this command again.", branchName)
}
if err := checkRulesGoVersion(ctx, rootDir, "HEAD", version); err != nil {
return err
return fmt.Errorf("release branch %q does not exist locally. Fetch it, add commits, and run this command again.", branchName)
}
fmt.Fprintf(stderr, "creating branch %s...\n", branchName)
if err := gitCreateBranch(ctx, rootDir, branchName, "HEAD"); err != nil {
return err
}
} else {
if err := checkRulesGoVersion(ctx, rootDir, branchName, version); err != nil {
return err
}
}

// Create an archive.
Expand Down Expand Up @@ -239,15 +227,3 @@ Release %s has been prepared and uploaded.

return nil
}

func checkRulesGoVersion(ctx context.Context, dir, refName, version string) error {
data, err := gitCatFile(ctx, dir, refName, "go/def.bzl")
if err != nil {
return err
}
rulesGoVersionStr := []byte(fmt.Sprintf(`RULES_GO_VERSION = "%s"`, version[len("v"):]))
if !bytes.Contains(data, rulesGoVersionStr) {
return fmt.Errorf("RULES_GO_VERSION was not set to %q in go/def.bzl. Set it, add commits, and run this command again.", version)
}
return nil
}

0 comments on commit a103a08

Please sign in to comment.