Merge pull request #3881 from MichaelEischer/cleanup-release-helper
Cleanup release helper
This commit is contained in:
commit
9cdc8da10f
1 changed files with 21 additions and 9 deletions
|
@ -103,16 +103,13 @@ func build(sourceDir, outputDir, goos, goarch string) (filename string) {
|
||||||
)
|
)
|
||||||
c.Stdout = os.Stdout
|
c.Stdout = os.Stdout
|
||||||
c.Stderr = os.Stderr
|
c.Stderr = os.Stderr
|
||||||
c.Dir = sourceDir
|
|
||||||
|
|
||||||
verbose("run %v %v in %v", "go", c.Args, c.Dir)
|
|
||||||
|
|
||||||
c.Dir = sourceDir
|
c.Dir = sourceDir
|
||||||
c.Env = append(os.Environ(),
|
c.Env = append(os.Environ(),
|
||||||
"CGO_ENABLED=0",
|
"CGO_ENABLED=0",
|
||||||
"GOOS="+goos,
|
"GOOS="+goos,
|
||||||
"GOARCH="+goarch,
|
"GOARCH="+goarch,
|
||||||
)
|
)
|
||||||
|
verbose("run %v %v in %v", "go", c.Args, c.Dir)
|
||||||
|
|
||||||
err := c.Run()
|
err := c.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -151,11 +148,9 @@ func compress(goos, inputDir, filename string) (outputFile string) {
|
||||||
case "windows":
|
case "windows":
|
||||||
outputFile = strings.TrimSuffix(filename, ".exe") + ".zip"
|
outputFile = strings.TrimSuffix(filename, ".exe") + ".zip"
|
||||||
c = exec.Command("zip", "-q", "-X", outputFile, filename)
|
c = exec.Command("zip", "-q", "-X", outputFile, filename)
|
||||||
c.Dir = inputDir
|
|
||||||
default:
|
default:
|
||||||
outputFile = filename + ".bz2"
|
outputFile = filename + ".bz2"
|
||||||
c = exec.Command("bzip2", filename)
|
c = exec.Command("bzip2", filename)
|
||||||
c.Dir = inputDir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rm(filepath.Join(inputDir, outputFile))
|
rm(filepath.Join(inputDir, outputFile))
|
||||||
|
@ -163,7 +158,6 @@ func compress(goos, inputDir, filename string) (outputFile string) {
|
||||||
c.Stdout = os.Stdout
|
c.Stdout = os.Stdout
|
||||||
c.Stderr = os.Stderr
|
c.Stderr = os.Stderr
|
||||||
c.Dir = inputDir
|
c.Dir = inputDir
|
||||||
|
|
||||||
verbose("run %v %v in %v", "go", c.Args, c.Dir)
|
verbose("run %v %v in %v", "go", c.Args, c.Dir)
|
||||||
|
|
||||||
err := c.Run()
|
err := c.Run()
|
||||||
|
@ -188,14 +182,19 @@ func buildForTarget(sourceDir, outputDir, goos, goarch string) (filename string)
|
||||||
|
|
||||||
func buildTargets(sourceDir, outputDir string, targets map[string][]string) {
|
func buildTargets(sourceDir, outputDir string, targets map[string][]string) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
msg("building with %d workers", runtime.NumCPU())
|
// the go compiler is already parallelized, thus reduce the concurrency a bit
|
||||||
|
workers := runtime.GOMAXPROCS(0) / 4
|
||||||
|
if workers < 1 {
|
||||||
|
workers = 1
|
||||||
|
}
|
||||||
|
msg("building with %d workers", workers)
|
||||||
|
|
||||||
type Job struct{ GOOS, GOARCH string }
|
type Job struct{ GOOS, GOARCH string }
|
||||||
|
|
||||||
var wg errgroup.Group
|
var wg errgroup.Group
|
||||||
ch := make(chan Job)
|
ch := make(chan Job)
|
||||||
|
|
||||||
for i := 0; i < runtime.NumCPU(); i++ {
|
for i := 0; i < workers; i++ {
|
||||||
wg.Go(func() error {
|
wg.Go(func() error {
|
||||||
for job := range ch {
|
for job := range ch {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
@ -233,6 +232,18 @@ var defaultBuildTargets = map[string][]string{
|
||||||
"solaris": {"amd64"},
|
"solaris": {"amd64"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func downloadModules(sourceDir string) {
|
||||||
|
c := exec.Command("go", "mod", "download")
|
||||||
|
c.Stdout = os.Stdout
|
||||||
|
c.Stderr = os.Stderr
|
||||||
|
c.Dir = sourceDir
|
||||||
|
|
||||||
|
err := c.Run()
|
||||||
|
if err != nil {
|
||||||
|
die("error downloading modules: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(pflag.Args()) != 0 {
|
if len(pflag.Args()) != 0 {
|
||||||
die("USAGE: build-release-binaries [OPTIONS]")
|
die("USAGE: build-release-binaries [OPTIONS]")
|
||||||
|
@ -242,5 +253,6 @@ func main() {
|
||||||
outputDir := abs(opts.OutputDir)
|
outputDir := abs(opts.OutputDir)
|
||||||
mkdir(outputDir)
|
mkdir(outputDir)
|
||||||
|
|
||||||
|
downloadModules(sourceDir)
|
||||||
buildTargets(sourceDir, outputDir, defaultBuildTargets)
|
buildTargets(sourceDir, outputDir, defaultBuildTargets)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue