Skip to content

Commit 9035682

Browse files
heschigopherbot
authored andcommitted
internal/relui: cross-compile Go 1.21 with -distpack
In 1.21, make.bash has a new argument, -distpack, which builds the release archives reproducibly from any host architecture. See the related bug for more details. This converts relui to use -distpack to build everything. Mostly that's as simple as adding an alternate build mode for the source and binary archives. There are/were some wrinkles to work out: - We need to generate the timestamp at the top level of the workflow so that the source consistency check reuses that same timestamp. - Since we now get a zip out of the Windows build, we comically have to convert that back to a tarball to push it to a buildlet. Or at least I thought that was better than running unzip. - I haven't figured out what to do about the module files yet. I think I'd prefer to recreate them in relui -- this code is really not happy about getting multiple files back from a build step. - I didn't make a clear distinction between host and target builders in the BuildletStep. Maybe I should. But the distpack codepaths are so much smaller that it was easy to verify they didn't use the wrong config anywhere. For golang/go#58659. Change-Id: I4c4cf5b5450046a62d062d7c0bbfe94157ee9446 Reviewed-on: https://go-review.googlesource.com/c/build/+/478158 Run-TryBot: Heschi Kreinick <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Heschi Kreinick <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent 208db0b commit 9035682

File tree

6 files changed

+276
-52
lines changed

6 files changed

+276
-52
lines changed

cmd/relui/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,13 @@ func main() {
238238
}
239239
var h http.Handler = relui.NewServer(dbPool, w, base, siteHeader, ms)
240240
if metadata.OnGCE() {
241-
h = access.RequireIAPAuthHandler(h, access.IAPSkipAudienceValidation)
241+
project, err := metadata.ProjectID()
242+
if err != nil {
243+
log.Fatal("failed to read project ID from metadata server")
244+
}
245+
if project == "symbolic-datum-552" {
246+
h = access.RequireIAPAuthHandler(h, access.IAPSkipAudienceValidation)
247+
}
242248
}
243249
log.Fatalln(https.ListenAndServe(ctx, &ochttp.Handler{Handler: GRPCHandler(grpcServer, h)}))
244250
}

internal/relui/buildrelease_test.go

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,20 @@ import (
4040

4141
func TestRelease(t *testing.T) {
4242
t.Run("beta", func(t *testing.T) {
43-
testRelease(t, "go1.18beta1", task.KindBeta)
43+
testRelease(t, "go1.17", 18, "go1.18beta1", task.KindBeta)
4444
})
4545
t.Run("rc", func(t *testing.T) {
46-
testRelease(t, "go1.18rc1", task.KindRC)
46+
testRelease(t, "go1.17", 18, "go1.18rc1", task.KindRC)
4747
})
4848
t.Run("major", func(t *testing.T) {
49-
testRelease(t, "go1.18", task.KindMajor)
49+
testRelease(t, "go1.17", 18, "go1.18", task.KindMajor)
5050
})
5151
}
5252

53+
func TestDistpack(t *testing.T) {
54+
testRelease(t, "go1.20", 21, "go1.21", task.KindMajor)
55+
}
56+
5357
func TestSecurity(t *testing.T) {
5458
t.Run("success", func(t *testing.T) {
5559
testSecurity(t, true)
@@ -96,7 +100,7 @@ type releaseTestDeps struct {
96100
publishedFiles map[string]*task.WebsiteFile
97101
}
98102

99-
func newReleaseTestDeps(t *testing.T, wantVersion string) *releaseTestDeps {
103+
func newReleaseTestDeps(t *testing.T, previousTag, wantVersion string) *releaseTestDeps {
100104
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
101105
t.Skip("Requires bash shell scripting support.")
102106
}
@@ -168,7 +172,7 @@ esac
168172

169173
goRepo := task.NewFakeRepo(t, "go")
170174
base := goRepo.Commit(goFiles)
171-
goRepo.Tag("go1.17", base)
175+
goRepo.Tag(previousTag, base)
172176
dlRepo := task.NewFakeRepo(t, "dl")
173177
toolsRepo := task.NewFakeRepo(t, "tools")
174178
toolsRepo1 := toolsRepo.Commit(map[string]string{
@@ -238,12 +242,12 @@ esac
238242
}
239243
}
240244

241-
func testRelease(t *testing.T, wantVersion string, kind task.ReleaseKind) {
242-
deps := newReleaseTestDeps(t, wantVersion)
245+
func testRelease(t *testing.T, prevTag string, major int, wantVersion string, kind task.ReleaseKind) {
246+
deps := newReleaseTestDeps(t, prevTag, wantVersion)
243247
wd := workflow.New()
244248

245249
deps.gerrit.wantReviewers = []string{"heschi", "dmitshur"}
246-
v := addSingleReleaseWorkflow(deps.buildTasks, deps.milestoneTasks, deps.versionTasks, wd, 18, kind, workflow.Const(deps.gerrit.wantReviewers))
250+
v := addSingleReleaseWorkflow(deps.buildTasks, deps.milestoneTasks, deps.versionTasks, wd, major, kind, workflow.Const(deps.gerrit.wantReviewers))
247251
workflow.Output(wd, "Published Go version", v)
248252

249253
w, err := workflow.Start(wd, map[string]interface{}{
@@ -253,7 +257,7 @@ func testRelease(t *testing.T, wantVersion string, kind task.ReleaseKind) {
253257
if err != nil {
254258
t.Fatal(err)
255259
}
256-
_, err = w.Run(deps.ctx, &verboseListener{t: t, onStall: deps.cancel})
260+
outputs, err := w.Run(deps.ctx, &verboseListener{t: t, onStall: deps.cancel})
257261
if err != nil {
258262
t.Fatal(err)
259263
}
@@ -262,7 +266,7 @@ func testRelease(t *testing.T, wantVersion string, kind task.ReleaseKind) {
262266
wantPublishedFiles := map[string]string{
263267
wantVersion + ".src.tar.gz": "source",
264268
}
265-
for _, t := range releasetargets.TargetsForGo1Point(18) {
269+
for _, t := range releasetargets.TargetsForGo1Point(major) {
266270
switch t.GOOS {
267271
case "darwin":
268272
wantPublishedFiles[wantVersion+"."+t.Name+".tar.gz"] = "archive"
@@ -305,12 +309,16 @@ func testRelease(t *testing.T, wantVersion string, kind task.ReleaseKind) {
305309
if len(wantPublishedFiles) != 0 {
306310
t.Errorf("missing %d published files: %v", len(wantPublishedFiles), wantPublishedFiles)
307311
}
312+
versionFile := outputs["VERSION file"].(string)
313+
if !strings.Contains(versionFile, wantVersion) {
314+
t.Errorf("version file should contain %q, got %q", wantVersion, versionFile)
315+
}
308316
checkTGZ(t, dlURL, files, "src.tar.gz", &task.WebsiteFile{
309317
OS: "",
310318
Arch: "",
311319
Kind: "source",
312320
}, map[string]string{
313-
"go/VERSION": wantVersion,
321+
"go/VERSION": versionFile,
314322
"go/src/make.bash": makeScript,
315323
})
316324
checkContents(t, dlURL, files, "windows-amd64.msi", &task.WebsiteFile{
@@ -323,24 +331,23 @@ func testRelease(t *testing.T, wantVersion string, kind task.ReleaseKind) {
323331
Arch: "amd64",
324332
Kind: "archive",
325333
}, map[string]string{
326-
"go/VERSION": wantVersion,
334+
"go/VERSION": versionFile,
327335
"go/tool/something_orother/compile": "",
328-
"go/pkg/something_orother/race.a": "",
329336
})
330337
checkZip(t, dlURL, files, "windows-amd64.zip", &task.WebsiteFile{
331338
OS: "windows",
332339
Arch: "amd64",
333340
Kind: "archive",
334341
}, map[string]string{
335-
"go/VERSION": wantVersion,
342+
"go/VERSION": versionFile,
336343
"go/tool/something_orother/compile": "",
337344
})
338345
checkTGZ(t, dlURL, files, "linux-armv6l.tar.gz", &task.WebsiteFile{
339346
OS: "linux",
340347
Arch: "armv6l",
341348
Kind: "archive",
342349
}, map[string]string{
343-
"go/VERSION": wantVersion,
350+
"go/VERSION": versionFile,
344351
"go/tool/something_orother/compile": "",
345352
})
346353
checkContents(t, dlURL, files, "darwin-amd64.pkg", &task.WebsiteFile{
@@ -371,14 +378,14 @@ func testRelease(t *testing.T, wantVersion string, kind task.ReleaseKind) {
371378
if err != nil {
372379
t.Fatal(err)
373380
}
374-
if string(version) != wantVersion {
375-
t.Errorf("VERSION file is %q, expected %q", version, wantVersion)
381+
if string(version) != versionFile {
382+
t.Errorf("VERSION file is %q, expected %q", version, versionFile)
376383
}
377384
}
378385
}
379386

380387
func testSecurity(t *testing.T, mergeFixes bool) {
381-
deps := newReleaseTestDeps(t, "go1.18rc1")
388+
deps := newReleaseTestDeps(t, "go1.17", "go1.18rc1")
382389

383390
// Set up the fake merge process. Once we stop to ask for approval, commit
384391
// the fix to the public server.
@@ -429,7 +436,7 @@ func testSecurity(t *testing.T, mergeFixes bool) {
429436
}
430437

431438
func TestAdvisoryTrybotFail(t *testing.T) {
432-
deps := newReleaseTestDeps(t, "go1.18rc1")
439+
deps := newReleaseTestDeps(t, "go1.17", "go1.18rc1")
433440
defaultApprove := deps.buildTasks.ApproveAction
434441
approvedTrybots := false
435442
deps.buildTasks.ApproveAction = func(ctx *workflow.TaskContext) error {
@@ -462,9 +469,17 @@ func TestAdvisoryTrybotFail(t *testing.T) {
462469

463470
// makeScript pretends to be make.bash. It creates a fake go command that
464471
// knows how to fake the commands the release process runs.
465-
const makeScript = `#!/bin/bash
472+
const makeScript = `#!/bin/bash -eu
466473
467474
GO=../
475+
476+
if [[ $# >0 && $1 == "-distpack" ]]; then
477+
mkdir -p $GO/pkg/distpack
478+
tmp=$(mktemp).tar.gz
479+
tar czf $tmp -C $GO/.. go
480+
mv $tmp $GO/pkg/distpack/go1.99.src.tar.gz
481+
fi
482+
468483
mkdir -p $GO/bin
469484
470485
cat <<'EOF' >$GO/bin/go
@@ -494,14 +509,30 @@ cp $GO/bin/go $GO/bin/go.exe
494509
# versimilitude.
495510
mkdir -p $GO/tool/something_orother/
496511
touch $GO/tool/something_orother/compile
512+
513+
if [[ $# >0 && $1 == "-distpack" ]]; then
514+
case $GOOS in
515+
"windows")
516+
tmp=$(mktemp).zip
517+
# The zip command isn't installed on our buildlets. Python is.
518+
(cd $GO/.. && python3 -m zipfile -c $tmp go/)
519+
mv $tmp $GO/pkg/distpack/go1.99.$GOOS-$GOARCH.zip
520+
;;
521+
*)
522+
tmp=$(mktemp).tar.gz
523+
tar czf $tmp -C $GO/.. go
524+
mv $tmp $GO/pkg/distpack/go1.99.$GOOS-$GOARCH.tar.gz
525+
;;
526+
esac
527+
fi
497528
`
498529

499530
// allScript pretends to be all.bash. It is hardcoded to pass.
500531
const allScript = `#!/bin/bash -eu
501532
502533
echo "I'm a test! :D"
503534
504-
if [[ $GO_BUILDER_NAME =~ "js-wasm" ]]; then
535+
if [[ $GO_BUILDER_NAME = "js-wasm" ]]; then
505536
echo "Oh no, WASM is broken"
506537
exit 1
507538
fi

0 commit comments

Comments
 (0)