mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-04 03:11:55 +02:00
wip
This commit is contained in:
parent
8b63e6555b
commit
efff5d5e17
48
build/build.go
Normal file
48
build/build.go
Normal file
@ -0,0 +1,48 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
|
||||
"github.com/goreleaser/releaser/config"
|
||||
"github.com/kardianos/osext"
|
||||
)
|
||||
|
||||
func Build(version string, config config.ProjectConfig) error {
|
||||
currentPath, err := osext.ExecutableFolder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(currentPath)
|
||||
for _, os := range config.Build.Oses {
|
||||
for _, arch := range config.Build.Arches {
|
||||
fmt.Println("Building", os, arch)
|
||||
cmd := exec.Command(
|
||||
"go", "build",
|
||||
"-ldflags=\"-s -w -X main.version="+version+"\"",
|
||||
"-o", target(os, arch, config.BinaryName),
|
||||
config.Main,
|
||||
)
|
||||
cmd.Env = append(
|
||||
cmd.Env,
|
||||
"GOOS="+os,
|
||||
"GOARCH="+arch,
|
||||
// "GOPATH="+
|
||||
)
|
||||
var stdout bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stdout
|
||||
err := cmd.Run()
|
||||
fmt.Println(stdout.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func target(os, arch, binary string) string {
|
||||
return "dist/" + binary + "_" + os + "_" + arch + "/" + binary
|
||||
}
|
@ -16,6 +16,11 @@ type HomebrewDeploy struct {
|
||||
Token string
|
||||
}
|
||||
|
||||
type BuildConfig struct {
|
||||
Oses []string
|
||||
Arches []string
|
||||
}
|
||||
|
||||
type ProjectConfig struct {
|
||||
Repo string
|
||||
Main string
|
||||
@ -23,6 +28,7 @@ type ProjectConfig struct {
|
||||
FileList []string
|
||||
Brew HomebrewDeploy
|
||||
Token string
|
||||
Build BuildConfig
|
||||
}
|
||||
|
||||
func Load(file string) (config ProjectConfig, err error) {
|
||||
@ -60,6 +66,12 @@ func fix(config ProjectConfig) ProjectConfig {
|
||||
if config.Brew != emptyBrew && config.Brew.Token == "" {
|
||||
config.Brew.Token = config.Token
|
||||
}
|
||||
if len(config.Build.Oses) == 0 {
|
||||
config.Build.Oses = []string{"linux", "darwin"}
|
||||
}
|
||||
if len(config.Build.Arches) == 0 {
|
||||
config.Build.Arches = []string{"amd64", "386"}
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user