Skip to content

Commit

Permalink
[microsoft/release-branch.go1.17] Add "make" retry capability, with 5…
Browse files Browse the repository at this point in the history
… in Windows CI (#299)

* Add "make" retry capability, with 5 in Windows CI

* Report error if GO_MAKE_MAX_RETRY_ATTEMPTS is not an int
  • Loading branch information
dagood committed Jan 27, 2022
1 parent 50ba7c0 commit a0895e3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
41 changes: 39 additions & 2 deletions eng/_core/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"

"github.com/microsoft/go/_core/archive"
"github.com/microsoft/go/_core/patch"
Expand Down Expand Up @@ -126,12 +127,35 @@ func build(o *options) error {
}
}

buildCommandLine := append(shellPrefix, "make"+scriptExtension)
// Set GOBUILDEXIT so 'make.bat' exits with exit code upon failure. The ordinary behavior of
// 'make.bat' is to always end with 0 exit code even if an error occurred, so 'all.bat' can
// handle the error. See https://github.com/golang/go/issues/7806.
if err := os.Setenv("GOBUILDEXIT", "1"); err != nil {
return err
}

if err := runCommandLine(buildCommandLine...); err != nil {
maxAttempts, err := getMaxMakeRetryAttempts()
if err != nil {
return err
}

buildCommandLine := append(shellPrefix, "make"+scriptExtension)

for i := 0; i < maxAttempts; i++ {
if maxAttempts > 1 {
fmt.Printf("---- Running 'make' attempt %v of %v...\n", i+1, maxAttempts)
}
err := runCommandLine(buildCommandLine...)
if err != nil {
if i+1 < maxAttempts {
fmt.Printf("---- Build command failed with error: %v\n", err)
continue
}
return err
}
break
}

if os.Getenv("CGO_ENABLED") != "0" {
fmt.Println("---- Building race runtime...")
err := runCommandLine(
Expand Down Expand Up @@ -216,3 +240,16 @@ func runCmd(cmd *exec.Cmd) error {
fmt.Printf("---- Running command: %v\n", cmd.Args)
return cmd.Run()
}

func getMaxMakeRetryAttempts() (int, error) {
const retryEnvVarName = "GO_MAKE_MAX_RETRY_ATTEMPTS"
a := os.Getenv(retryEnvVarName)
if a == "" {
return 1, nil
}
i, err := strconv.Atoi(a)
if err != nil {
return 0, fmt.Errorf("env var '%v' is not an int: %w", retryEnvVarName, err)
}
return i, nil
}
5 changes: 5 additions & 0 deletions eng/pipeline/jobs/run-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ jobs:

- ${{ if eq(parameters.builder.os, 'windows') }}:
- template: ../steps/checkout-windows-task.yml
- pwsh: |
Write-Host "Increasing max build retries to mitigate 'Access denied' flakiness during EXE copying on Windows."
Write-Host "##vso[task.setvariable variable=GO_MAKE_MAX_RETRY_ATTEMPTS]5"
displayName: Increase 'make' retry attempts
# Initialize stage 0 toolset ahead of time so we can track timing data separately from the
# build operations. When we call this script again later, it won't download Go again.
Expand Down

0 comments on commit a0895e3

Please sign in to comment.