1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-04 03:11:55 +02:00
This commit is contained in:
Carlos Alexandro Becker 2016-12-21 11:37:31 -02:00
parent 8b63e6555b
commit efff5d5e17
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 63 additions and 0 deletions

48
build/build.go Normal file
View 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
}

View File

@ -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
}

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/goreleaser/releaser/build"
"github.com/goreleaser/releaser/config"
)
@ -12,4 +13,6 @@ func main() {
panic(err)
}
fmt.Println(config)
err = build.Build("master", config)
fmt.Println(err)
}