diff options
| author | Dmitri Shuralyov <dmitshur@golang.org> | 2026-04-07 18:13:38 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-04-08 10:23:27 -0700 |
| commit | 3317e0bbb9d5ea3f5bc307c1d7739f1d80557d29 (patch) | |
| tree | 56db08e5f362483c9347ca217864b824e6821f5e /cmd/golangorg | |
| parent | a72b917a3cc89969c4421ce8abd1ee9bb3efbb95 (diff) | |
| download | go-x-website-3317e0bbb9d5ea3f5bc307c1d7739f1d80557d29.tar.xz | |
cmd/golangorg: use _goroot.zip during deploy tests too
The deploy process constructs a _goroot.zip file which is used as the
source of main Go repository content when serving go.dev. Start using
the same _goroot.zip file when running tests in Cloud Build.
Also move the flag.Parse to happen at the top of main, before some of
the flag values are accessed and potentially overridden.
For golang/go#78211.
Change-Id: Iaf182301836917d062c5f4c329db6bbc171415da
Reviewed-on: https://go-review.googlesource.com/c/website/+/763840
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'cmd/golangorg')
| -rw-r--r-- | cmd/golangorg/app.yaml | 1 | ||||
| -rw-r--r-- | cmd/golangorg/cloudbuild.yaml | 3 | ||||
| -rw-r--r-- | cmd/golangorg/server.go | 13 | ||||
| -rw-r--r-- | cmd/golangorg/server_test.go | 14 |
4 files changed, 23 insertions, 8 deletions
diff --git a/cmd/golangorg/app.yaml b/cmd/golangorg/app.yaml index 597744fa..2b6ae6f2 100644 --- a/cmd/golangorg/app.yaml +++ b/cmd/golangorg/app.yaml @@ -8,6 +8,7 @@ main: ./cmd/golangorg env_variables: GOLANGORG_REQUIRE_DL_SECRET_KEY: true GOLANGORG_ENFORCE_HOSTS: true + GOLANGORG_FORCE_GOROOT_ZIP: true GOLANGORG_REDIS_ADDR: 10.0.0.4:6379 # instance "gophercache" GOLANGORG_ANALYTICS: UA-11222381-2 DATASTORE_PROJECT_ID: golang-org diff --git a/cmd/golangorg/cloudbuild.yaml b/cmd/golangorg/cloudbuild.yaml index 3d85da70..29dd7ba7 100644 --- a/cmd/golangorg/cloudbuild.yaml +++ b/cmd/golangorg/cloudbuild.yaml @@ -20,8 +20,9 @@ steps: args: ["rm", "-rf", "_wikitmp/.git"] - name: golang args: ["sh", "-c", "cp -a _wikitmp/* _content/wiki"] - # Run tests. + # Run tests with GOROOT content from _goroot.zip. - name: golang + env: ["GOLANGORG_FORCE_GOROOT_ZIP=true"] args: ["go", "test", "./..."] # Coordinate with other Cloud Build jobs to deploy only newest commit. # May abort job here. diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go index 17d55a3f..3b015f98 100644 --- a/cmd/golangorg/server.go +++ b/cmd/golangorg/server.go @@ -25,6 +25,7 @@ import ( "path/filepath" "runtime" "runtime/debug" + "strconv" "strings" "sync" "sync/atomic" @@ -58,6 +59,7 @@ var ( contentDir = flag.String("content", "", "path to _content directory") runningOnAppEngine = os.Getenv("PORT") != "" + forceGorootZip, _ = strconv.ParseBool(os.Getenv("GOLANGORG_FORCE_GOROOT_ZIP")) tipFlag = flag.Bool("tip", runningOnAppEngine, "load git content for tip.golang.org") wikiFlag = flag.Bool("wiki", runningOnAppEngine, "load git content for go.dev/wiki") @@ -73,6 +75,9 @@ func usage() { } func main() { + flag.Usage = usage + flag.Parse() + // Running locally, find the local _content directory when it's available nearby, // so that updates to those files appear on the local dev instance without restarting. // On App Engine, leave contentDir empty, so we use the embedded copy, @@ -87,9 +92,12 @@ func main() { } } + if forceGorootZip { + *goroot = "_goroot.zip" + } + if runningOnAppEngine { log.Print("golang.org server starting") - *goroot = "_goroot.zip" log.SetFlags(log.Lshortfile | log.LstdFlags) port := "8080" if p := os.Getenv("PORT"); p != "" { @@ -98,9 +106,6 @@ func main() { *httpAddr = ":" + port } - flag.Usage = usage - flag.Parse() - // Check usage. if flag.NArg() > 0 { fmt.Fprintln(os.Stderr, "Unexpected arguments.") diff --git a/cmd/golangorg/server_test.go b/cmd/golangorg/server_test.go index 31594689..ceb1ec49 100644 --- a/cmd/golangorg/server_test.go +++ b/cmd/golangorg/server_test.go @@ -27,7 +27,11 @@ import ( func TestWeb(t *testing.T) { needsGorootDocDir(t) - h := NewHandler("../../_content", runtime.GOROOT()) + goroot := *goroot + if forceGorootZip { + goroot = "../../_goroot.zip" + } + h := NewHandler("../../_content", goroot) files, err := filepath.Glob("testdata/*.txt") if err != nil { @@ -48,7 +52,7 @@ var bads = []string{ " < ", "<-", "& ", - //"{{raw <code>", // TODO(go.dev/issue/78211,dmitshur): Disabled because it breaks testing during the deploy process (the _goroot.zip file isn't passed to tests). + "{{raw <code>", } var ignoreBads = []string{ @@ -81,7 +85,11 @@ Lines: func TestAll(t *testing.T) { needsGorootDocDir(t) - h := NewHandler("../../_content", runtime.GOROOT()) + goroot := *goroot + if forceGorootZip { + goroot = "../../_goroot.zip" + } + h := NewHandler("../../_content", goroot) get := func(url string) (code int, body string, err error) { if url == "https://go.dev/rebuild" { |
