diff options
| author | Alan Donovan <adonovan@google.com> | 2025-07-29 11:20:59 -0400 |
|---|---|---|
| committer | Alan Donovan <adonovan@google.com> | 2025-07-29 09:47:41 -0700 |
| commit | e5dd27fc71edea3015b34b5061a4f4fe6e86f0cc (patch) | |
| tree | 846c6b32cf8dc0a08048741cb265b890ac369df6 | |
| parent | 74641f3495984766c171703d06af11f123e07a11 (diff) | |
| download | go-x-website-e5dd27fc71edea3015b34b5061a4f4fe6e86f0cc.tar.xz | |
cmd/golangorg: serve latest commit on gopls' latest release branch
Rather than serving docs at the gopls release itself, this CL
causes us to serve whatever is on the release branch. This allows
us to cherrypick doc fixes into the branch without all the fuss
of a gopls release.
Change-Id: I5f99458407388747a093219cac16e178f28ba527
Reviewed-on: https://go-review.googlesource.com/c/website/+/691415
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
| -rw-r--r-- | cmd/golangorg/server.go | 5 | ||||
| -rw-r--r-- | internal/gitfs/git.go | 47 |
2 files changed, 36 insertions, 16 deletions
diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go index 85af5afe..71218c05 100644 --- a/cmd/golangorg/server.go +++ b/cmd/golangorg/server.go @@ -200,8 +200,9 @@ func NewHandler(contentDir, goroot string) http.Handler { go watchGit(&tipGoroot, "https://go.googlesource.com/go", "HEAD") } - // go.dev/gopls serves the latest gopls release of golang.org/x/tools/gopls/doc. - contentFS = addGopls(contentFS, "gopls/latest") + // go.dev/gopls serves golang.org/x/tools/gopls/doc from the + // tip commit on the latest release branch. + contentFS = addGopls(contentFS, "gopls/latest-release-branch") // beta.golang.org is an old name for tip. mux.Handle("beta.golang.org/", redirectPrefix("https://tip.golang.org/")) diff --git a/internal/gitfs/git.go b/internal/gitfs/git.go index 0c610d00..c25f1bbb 100644 --- a/internal/gitfs/git.go +++ b/internal/gitfs/git.go @@ -12,10 +12,8 @@ import ( "io" "io/fs" "log" - "maps" "net/http" pathpkg "path" - "slices" "strings" "golang.org/x/mod/semver" @@ -81,9 +79,8 @@ func (r *Repo) handshake() error { // Resolve looks up the given ref and returns the corresponding Hash. // -// As a special case (to support gopls), a ref of the form -// "dir/latest" returns the latest semver release tag -// "refs/tags/dir/vX.Y.Z..." according to Go module version semantics. +// As a special case, a ref of "gopls/latest-release-branch" returns +// the tip commit on the latest release branch of gopls. func (r *Repo) Resolve(ref string) (Hash, error) { if h, err := parseHash(ref); err == nil { return h, nil @@ -93,20 +90,24 @@ func (r *Repo) Resolve(ref string) (Hash, error) { return Hash{}, fmt.Errorf("resolve %s: %v", ref, err) } - // "gopls/latest" -> latest of "refs/tags/gopls/vX.Y.Z" - if pathpkg.Base(ref) == "latest" { - // Find release tags. - pre := fmt.Sprintf("refs/tags/%s/", pathpkg.Dir(ref)) + // gopls/latest-release-branch means (a) resolve + // gopls@latest by sorting tags "refs/tags/gopls/vX.Y.Z" in + // the usual way, then (b) find the latest commit on its + // release branch "gopls-release-branch.X.Y". + // + // This avoids the need to release gopls just to pick up doc + // changes that have been cherrypicked to the release branch. + if ref == "gopls/latest-release-branch" { + // Find gopls release tags. + const pre = "refs/tags/gopls/" refs, err := r.refs(pre + "v") if err != nil { return fail(err) } // Extract semvers in ascending order. - names := slices.Collect(maps.Keys(refs)) - slices.Sort(names) var versions []string // "vX.Y.Z" - for _, name := range names { + for name := range refs { versions = append(versions, strings.TrimPrefix(name, pre)) } semver.Sort(versions) @@ -122,8 +123,26 @@ func (r *Repo) Resolve(ref string) (Hash, error) { if latest == "" { return fail(fmt.Errorf("no release tag matching %q", pre)) } - log.Printf("resolved %s -> %s (%s)", ref, latest, refs[latest]) - return refs[latest], nil + log.Printf("resolved %s to %s (%s)", ref, latest, refs[latest]) + + // Parse latest as vX.Y. + majmin := semver.MajorMinor(pathpkg.Base(latest)) + if !strings.HasPrefix(majmin, "v") { + return fail(fmt.Errorf("can't parse latest version %q as vX.Y", majmin)) + } + + // Resolve gopls release branch to tip commit. + branch := fmt.Sprintf("refs/heads/gopls-release-branch.%s", strings.TrimPrefix(majmin, "v")) + refs2, err := r.refs(branch) + if err != nil { + return fail(err) + } + branchHash, ok := refs2[branch] + if !ok { + return fail(fmt.Errorf("cannot resolve %q", branch)) + } + log.Printf("resolved %s to %s", branch, branchHash) + return branchHash, nil } refs, err := r.refs(ref) |
