Skip to content

Commit faad8fc

Browse files
authored
Merge pull request #416 from dagood/dev/dagood/merge-b1.16-from-1.16
[boring-1.16] Merge from 1.16
2 parents e47cf58 + 34b83cc commit faad8fc

File tree

10 files changed

+160
-34
lines changed

10 files changed

+160
-34
lines changed

eng/_core/archive/archive.go

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,49 @@ import (
1616
"io"
1717
"io/fs"
1818
"os"
19+
"os/exec"
1920
"path/filepath"
2021
"runtime"
2122
"strings"
2223
"time"
2324
)
2425

26+
// CreateFromSource runs a Git command to generate an archive file from the Go source code at
27+
// "source". If output is "", the archive is produced in the build directory inside the
28+
// "eng/artifacts/bin" directory. A checksum file is also produced.
29+
func CreateFromSource(source string, output string) error {
30+
fmt.Printf("---- Creating Go source archive (tarball) from '%v'...\n", source)
31+
32+
if output == "" {
33+
output = filepath.Join(getBinDir(source), fmt.Sprintf("go.%v.src.tar.gz", getBuildID()))
34+
}
35+
36+
// Ensure the target directory exists.
37+
archiveDir := filepath.Dir(output)
38+
if err := os.MkdirAll(archiveDir, os.ModeDir|os.ModePerm); err != nil {
39+
return err
40+
}
41+
42+
// Use "^{tree}" to avoid Git including a global extended pax header. The commit it would list
43+
// is a temporary commit, and would only be confusing. See https://git-scm.com/docs/git-archive.
44+
cmd := exec.Command("git", "archive", "-o", output, "--prefix=go/", "HEAD^{tree}")
45+
cmd.Dir = source
46+
cmd.Stdout = os.Stdout
47+
cmd.Stderr = os.Stderr
48+
fmt.Printf("---- Running command: %v\n", cmd.Args)
49+
if err := cmd.Run(); err != nil {
50+
return err
51+
}
52+
53+
fmt.Printf("---- Creating checksum file...\n")
54+
if err := writeSHA256ChecksumFile(output); err != nil {
55+
return err
56+
}
57+
58+
fmt.Printf("---- Pack complete.\n")
59+
return nil
60+
}
61+
2562
// CreateFromBuild walks the Go build directory at "source" and produces an archive with the path
2663
// "output". If output is "", CreateFromBuild produces a file in the build directory inside the
2764
// "eng/artifacts/bin" directory. The output directory is created if it doesn't exist. This function
@@ -34,21 +71,14 @@ func CreateFromBuild(source string, output string) error {
3471
fmt.Printf("---- Creating Go archive (zip/tarball) from '%v'...\n", source)
3572

3673
if output == "" {
37-
// If BUILD_BUILDNUMBER is defined (e.g. a CI build), use it. For local builds, use "dev".
38-
archiveVersion := os.Getenv("BUILD_BUILDNUMBER")
39-
if archiveVersion == "" {
40-
archiveVersion = "dev"
41-
}
42-
74+
archiveVersion := getBuildID()
4375
archiveExtension := ".tar.gz"
4476
if runtime.GOOS == "windows" {
4577
archiveExtension = ".zip"
4678
}
4779

4880
archiveName := fmt.Sprintf("go.%v.%v-%v%v", archiveVersion, runtime.GOOS, runtime.GOARCH, archiveExtension)
49-
binDir := filepath.Join(source, "..", "eng", "artifacts", "bin")
50-
51-
output = filepath.Join(binDir, archiveName)
81+
output = filepath.Join(getBinDir(source), archiveName)
5282
}
5383

5484
// Ensure the target directory exists.
@@ -186,12 +216,27 @@ func CreateFromBuild(source string, output string) error {
186216
}
187217

188218
fmt.Printf("---- Creating checksum file...\n")
189-
writeSHA256ChecksumFile(output)
219+
if err := writeSHA256ChecksumFile(output); err != nil {
220+
return err
221+
}
190222

191223
fmt.Printf("---- Pack complete.\n")
192224
return nil
193225
}
194226

227+
// getBuildID returns BUILD_BUILDNUMBER if defined (e.g. a CI build). Otherwise, "dev".
228+
func getBuildID() string {
229+
archiveVersion := os.Getenv("BUILD_BUILDNUMBER")
230+
if archiveVersion == "" {
231+
return "dev"
232+
}
233+
return archiveVersion
234+
}
235+
236+
func getBinDir(source string) string {
237+
return filepath.Join(source, "..", "eng", "artifacts", "bin")
238+
}
239+
195240
// getArchivePathRuntime takes a path like "go1.7.linux-amd64.tar.gz" and extension like ".tar.gz",
196241
// and returns the os (linux) and arch (amd64). The "path" extension may have multiple '.'
197242
// characters in it, so "ext" must be passed in explicitly or else the match would be ambiguous.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"flag"
9+
"fmt"
10+
"os"
11+
"path/filepath"
12+
13+
"github.com/microsoft/go/_core/archive"
14+
)
15+
16+
const description = `
17+
This command creates a source archive of the Go submodule at HEAD.
18+
`
19+
20+
func main() {
21+
output := flag.String("o", "", "The path of the archive file to create, including extension. Default: a tar.gz file including build number in 'eng/artifacts/bin'.")
22+
help := flag.Bool("h", false, "Print this help message.")
23+
24+
flag.Usage = func() {
25+
fmt.Fprintf(flag.CommandLine.Output(), "Usage:\n")
26+
flag.PrintDefaults()
27+
fmt.Fprintf(flag.CommandLine.Output(), "%s\n", description)
28+
}
29+
30+
flag.Parse()
31+
if *help {
32+
flag.Usage()
33+
return
34+
}
35+
36+
repoRootDir, err := os.Getwd()
37+
if err != nil {
38+
panic(err)
39+
}
40+
41+
goRootDir := filepath.Join(repoRootDir, "go")
42+
43+
if err := archive.CreateFromSource(goRootDir, *output); err != nil {
44+
panic(err)
45+
}
46+
}

eng/_core/cmd/submodule-refresh/submodule-refresh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ applies patches to the stage by default, or optionally as commits.
1919
`
2020

2121
var commits = flag.Bool("commits", false, "Apply the patches as commits.")
22+
var skipPatch = flag.Bool("skip-patch", false, "Skip applying patches.")
2223
var origin = flag.String("origin", "", "Use this origin instead of the default defined in '.gitmodules' to fetch the repository.")
2324
var shallow = flag.Bool("shallow", false, "Clone the submodule with depth 1.")
2425
var fetchBearerToken = flag.String("fetch-bearer-token", "", "Use this bearer token to fetch the submodule repository.")
@@ -57,6 +58,10 @@ func refresh(rootDir string) error {
5758
return err
5859
}
5960

61+
if *skipPatch {
62+
return nil
63+
}
64+
6065
mode := patch.ApplyModeIndex
6166
if *commits {
6267
mode = patch.ApplyModeCommits

eng/_util/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module github.com/microsoft/go/_util
77
go 1.16
88

99
require (
10-
github.com/microsoft/go-infra v0.0.0-20211206195537-520f2621bcf4
10+
github.com/microsoft/go-infra v0.0.0-20220208232830-51df6c5b8843
1111
gotest.tools/gotestsum v1.6.5-0.20210515201937-ecb7c6956f6d
1212
)

eng/_util/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ
1515
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
1616
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
1717
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
18-
github.com/microsoft/go-infra v0.0.0-20211206195537-520f2621bcf4 h1:goYnnCGbN9HBwd0CtdiokVAlq5rTQkqq66K43kvGnhc=
19-
github.com/microsoft/go-infra v0.0.0-20211206195537-520f2621bcf4/go.mod h1:3IVGTm7qFJldQHximiWLg2kYfmugjZMGNHnvUo5Mo5M=
18+
github.com/microsoft/go-infra v0.0.0-20220208232830-51df6c5b8843 h1:IAk1GrsBP2l3sdWnaARrLALS9m6fVkGNgefpWRS0x2c=
19+
github.com/microsoft/go-infra v0.0.0-20220208232830-51df6c5b8843/go.mod h1:3IVGTm7qFJldQHximiWLg2kYfmugjZMGNHnvUo5Mo5M=
2020
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2121
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
2222
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

eng/pipeline/jobs/builders-to-jobs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ parameters:
1010
# If true, include a signing job that depends on all 'buildandpack' builder jobs finishing. This
1111
# lets us start the lengthy tasks of signing and testing in parallel.
1212
sign: false
13+
# If true, generate source archive tarballs, and sign them if signing is enabled.
14+
createSourceArchive: false
1315

1416
jobs:
1517
- ${{ each builder in parameters.builders }}:
1618
- template: run-job.yml
1719
parameters:
1820
builder: ${{ builder }}
21+
createSourceArchive: ${{ parameters.createSourceArchive }}
1922

2023
- ${{ if eq(parameters.sign, true) }}:
2124
- template: sign-job.yml

eng/pipeline/jobs/go-builder-matrix-jobs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ parameters:
99
innerloop: false
1010
outerloop: false
1111
sign: false
12+
createSourceArchive: false
1213

1314
jobs:
1415
- template: shorthand-builders-to-builders.yml
1516
parameters:
1617
jobsTemplate: builders-to-jobs.yml
1718
jobsParameters:
1819
sign: ${{ parameters.sign }}
20+
createSourceArchive: ${{ parameters.createSourceArchive }}
1921
shorthandBuilders:
2022
- ${{ if eq(parameters.innerloop, true) }}:
2123
- { os: linux, arch: amd64, config: buildandpack }

eng/pipeline/jobs/run-job.yml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
parameters:
88
# { id, os, arch, config, distro? }
99
builder: {}
10+
createSourceArchive: false
1011

1112
jobs:
1213
- job: ${{ parameters.builder.id }}
@@ -41,34 +42,30 @@ jobs:
4142
Write-Host "##vso[task.setvariable variable=GO_MAKE_MAX_RETRY_ATTEMPTS]5"
4243
displayName: Increase 'make' retry attempts
4344
44-
4545
# Initialize stage 0 toolset ahead of time so we can track timing data separately from the
4646
# build operations. When we call this script again later, it won't download Go again.
4747
- pwsh: |
4848
. eng/utilities.ps1
4949
Get-Stage0GoRoot
5050
displayName: Init stage 0 Go toolset
5151
52+
- template: ../steps/init-submodule-task.yml
53+
54+
# Create the source archive on one job only. The os choice is arbitrary.
55+
- ${{ if and(eq(parameters.createSourceArchive, true), eq(parameters.builder.config, 'buildandpack'), eq(parameters.builder.os, 'linux')) }}:
56+
- pwsh: |
57+
git config --global user.name "microsoft-golang-bot"
58+
git config --global user.email "microsoft-golang-bot@users.noreply.github.com"
59+
60+
# Turn the patches into commits, so HEAD includes the changes.
61+
eng/run.ps1 submodule-refresh -commits
62+
eng/run.ps1 pack-source
63+
displayName: Archive submodule source
64+
5265
- pwsh: |
53-
function fetch_submodule() {
54-
eng/run.ps1 submodule-refresh -shallow @args
55-
}
56-
57-
if ("$env:FETCH_BEARER_TOKEN") {
58-
fetch_submodule `
59-
-origin 'https://dnceng@dev.azure.com/dnceng/internal/_git/microsoft-go-mirror' `
60-
-fetch-bearer-token $env:FETCH_BEARER_TOKEN
61-
} else {
62-
fetch_submodule
63-
}
64-
# If non-public, use access token to fetch from repo. If public, don't use the access token,
65-
# because anonymous auth is fine.
66-
${{ if ne(variables['System.TeamProject'], 'public') }}:
67-
env:
68-
FETCH_BEARER_TOKEN: $(System.AccessToken)
69-
displayName: Set up submodule from internal mirror
70-
${{ if eq(variables['System.TeamProject'], 'public') }}:
71-
displayName: Set up submodule
66+
# Apply the patches as staged changes, so the HEAD commit is the same as upstream.
67+
eng/run.ps1 submodule-refresh
68+
displayName: Apply patches
7269
7370
# Use build script directly for "buildandpack". If we used run-builder, we would need to
7471
# download its external module dependencies.

eng/pipeline/rolling-internal-pipeline.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ stages:
2020
parameters:
2121
innerloop: true
2222
sign: true
23+
createSourceArchive: true
2324

2425
- stage: Publish
2526
dependsOn: Build
@@ -37,6 +38,7 @@ stages:
3738
steps:
3839
- template: steps/checkout-unix-task.yml
3940
- template: steps/init-pwsh-task.yml
41+
- template: steps/init-submodule-task.yml
4042

4143
- pwsh: |
4244
function TrimStart($s, $prefix) {
@@ -68,7 +70,7 @@ stages:
6870
- pwsh: |
6971
eng/run.ps1 createbuildassetjson `
7072
-artifacts-dir '$(Pipeline.Workspace)/Binaries Signed/' `
71-
-source-dir '$(Build.SourcesDirectory)' `
73+
-source-dir '$(Build.SourcesDirectory)/go' `
7274
-destination-url '$(blobDestinationUrl)' `
7375
-branch '$(PublishBranchAlias)' `
7476
-o '$(Pipeline.Workspace)/Binaries Signed/assets.json'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
# Shallow checkout sources on Windows
6+
steps:
7+
- pwsh: |
8+
function fetch_submodule() {
9+
eng/run.ps1 submodule-refresh -shallow -skip-patch @args
10+
}
11+
12+
if ("$env:FETCH_BEARER_TOKEN") {
13+
fetch_submodule `
14+
-origin 'https://dnceng@dev.azure.com/dnceng/internal/_git/microsoft-go-mirror' `
15+
-fetch-bearer-token $env:FETCH_BEARER_TOKEN
16+
} else {
17+
fetch_submodule
18+
}
19+
# If non-public, use access token to fetch from repo. If public, don't use the access token,
20+
# because anonymous auth is fine.
21+
${{ if ne(variables['System.TeamProject'], 'public') }}:
22+
env:
23+
FETCH_BEARER_TOKEN: $(System.AccessToken)
24+
displayName: Set up submodule from internal mirror
25+
${{ if eq(variables['System.TeamProject'], 'public') }}:
26+
displayName: Set up submodule

0 commit comments

Comments
 (0)