Skip to content

Commit

Permalink
cmd/golangorg: add doc/next page to preview draft release notes
Browse files Browse the repository at this point in the history
The improved release note process is being used starting with Go 1.23.
That means instead of a single doc/go1.23.html draft file in the main
Go repository, doc/next contains a set of release note fragments.
Having small, orthogonal files avoids merge conflicts, and a release
note test requires that release notes are written and included in the
same CL that's adding new APIs. As a result, the set of completed
release notes even before we enter the release freeze is greater than
ever before.

While it's possible to view those fragments using tip.golang.org
(e.g., by visiting https://tip.golang.org/doc/next), reading them
that way isn't practical. The relnote generate tool exists to merge
fragments into a complete Markdown document, and this tool will be
used when eventually moving a complete draft of Go 1.23 release notes
to x/website.

To aid the remaining work of completing the release note draft, this
change adds a dynamic /doc/next page to preview what the relnote
generate tool will produce. Combined with existing functionality of
the -tip flag, it makes https://tip.golang.org/doc/next display a live
preview of the checked-in release notes draft.

It can also be used to preview release note draft locally. For example,
if $HOME/gotip is a Go checkout where one is editing doc/next content:

go run golang.org/x/website/cmd/golangorg@latest -goroot=$HOME/gotip

Will serve a live preview at http://localhost:6060/go.dev/doc/next.
It can be slightly more convenient to refresh a browser without having
to re-run 'relnote generate'.

For golang/go#64169.
For golang/go#65614.

Change-Id: Ie1d3650076421a95a691dd84a554a113dd1187b1
Reviewed-on: https://go-review.googlesource.com/c/website/+/587436
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
dmitshur authored and gopherbot committed May 22, 2024
1 parent 9e5eadf commit 89cd698
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
6 changes: 6 additions & 0 deletions _content/doc/next.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Next Release Notes Draft
template: true
---

{{with docNext}}{{.}}{{else}}No next release note fragments available.{{end}}
37 changes: 35 additions & 2 deletions cmd/golangorg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"time"

"cloud.google.com/go/datastore"
"golang.org/x/build/relnote"
"golang.org/x/build/repos"
"golang.org/x/website"
"golang.org/x/website/internal/blog"
Expand All @@ -49,6 +50,7 @@ import (
"golang.org/x/website/internal/tour"
"golang.org/x/website/internal/web"
"golang.org/x/website/internal/webtest"
"rsc.io/markdown"
)

var (
Expand Down Expand Up @@ -277,6 +279,7 @@ func newSite(mux *http.ServeMux, host string, content, goroot fs.FS) (*web.Site,
"rfc3339": parseRFC3339,
"section": section,
"version": func() string { return runtime.Version() },
"docNext": releaseNotePreview{goroot}.MergedFragments,
})
docs, err := pkgdoc.NewServer(fsys, site, googleCN)
if err != nil {
Expand All @@ -290,6 +293,34 @@ func newSite(mux *http.ServeMux, host string, content, goroot fs.FS) (*web.Site,
return site, nil
}

// releaseNotePreview implements a preview of upcoming release notes.
type releaseNotePreview struct {
goroot fs.FS // goroot provides the doc/next content to use, if any.
}

// MergedFragments returns Markdown obtained by merging release note fragments
// found in the doc/next directory in goroot, to preview relnote generate output.
// An empty string and no error is returned if the doc/next directory doesn't exist.
func (p releaseNotePreview) MergedFragments() (markdownWithEmbeddedHTML template.HTML, _ error) {
next, err := fs.Sub(p.goroot, "doc/next")
if err != nil {
return "", err
}
if _, err := fs.Stat(next, "."); os.IsNotExist(err) || errors.Is(err, errNoFileSystem) {
// No next release note fragments.
return "", nil
}
doc, err := relnote.Merge(next)
if err != nil {
return "", fmt.Errorf("relnote.Merge: %v", err)
}
// Note: It's possible to render doc, a parsed Markdown document with embedded HTML,
// into Markdown or HTML. We choose to render to Markdown and let x/website/internal/web
// handle the remaining conversion to HTML. This means the rendering is more consistent
// with what'll happen when relnote generate output is added as _content/doc/go1.N.md.
return template.HTML(markdown.ToMarkdown(doc)), nil
}

func parseRFC3339(s string) (time.Time, error) {
return time.Parse(time.RFC3339, s)
}
Expand Down Expand Up @@ -831,12 +862,14 @@ func (m *mountFS) Open(name string) (fs.File, error) {
return m.old.Open(name)
}

var errNoFileSystem = errors.New("no file system")

// Open returns fsys.Open(name) where fsys is the file system passed to the most recent call to Set.
// If there has been no call to Set, Open returns an error with text “no file system”.
// If there has been no call to Set, Open returns errNoFileSystem, an error with text “no file system”.
func (a *atomicFS) Open(name string) (fs.File, error) {
fsys, _ := a.v.Load().(*fs.FS)
if fsys == nil {
return nil, &fs.PathError{Path: name, Op: "open", Err: fmt.Errorf("no file system")}
return nil, &fs.PathError{Path: name, Op: "open", Err: errNoFileSystem}
}
return (*fsys).Open(name)
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/golangorg/testdata/web.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,9 @@ body contains is:merged author:

GET https://go.dev/CONTRIBUTORS
redirect == /AUTHORS

GET https://go.dev/doc/next
body contains <h1>Next Release Notes Draft</h1>

GET https://tip.golang.org/doc/next
body contains <h1>Next Release Notes Draft</h1>
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
golang.org/x/tools v0.21.0
google.golang.org/api v0.136.0
gopkg.in/yaml.v3 v3.0.1
rsc.io/markdown v0.0.0-20240306144322-0bf8f97ee8ef
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
rsc.io/markdown v0.0.0-20240306144322-0bf8f97ee8ef h1:mqLYrXCXYEZOop9/Dbo6RPX11539nwiCNBb1icVPmw8=
rsc.io/markdown v0.0.0-20240306144322-0bf8f97ee8ef/go.mod h1:8xcPgWmwlZONN1D9bjxtHEjrUtSEa3fakVF8iaewYKQ=

0 comments on commit 89cd698

Please sign in to comment.