mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-18 03:56:52 +02:00
name template wip
This commit is contained in:
parent
d80a5a2ecf
commit
16e1b95308
@ -9,6 +9,9 @@ import (
|
||||
|
||||
"github.com/goreleaser/releaser/config/git"
|
||||
yaml "gopkg.in/yaml.v1"
|
||||
"bytes"
|
||||
"text/template"
|
||||
"github.com/goreleaser/releaser/uname"
|
||||
)
|
||||
|
||||
var filePatterns = []string{"LICENCE*", "LICENSE*", "README*", "CHANGELOG*"}
|
||||
@ -36,13 +39,14 @@ type GitInfo struct {
|
||||
|
||||
// ProjectConfig includes all project configuration
|
||||
type ProjectConfig struct {
|
||||
Repo string
|
||||
BinaryName string `yaml:"binary_name"`
|
||||
Files []string
|
||||
Brew Homebrew
|
||||
Token string `yaml:"-"`
|
||||
Build BuildConfig
|
||||
Git GitInfo `yaml:"-"`
|
||||
Repo string
|
||||
BinaryName string `yaml:"binary_name"`
|
||||
Files []string
|
||||
Brew Homebrew
|
||||
Token string `yaml:"-"`
|
||||
Build BuildConfig
|
||||
Git GitInfo `yaml:"-"`
|
||||
NameTemplate string
|
||||
}
|
||||
|
||||
// Load config file
|
||||
@ -64,6 +68,33 @@ func Load(file string) (config ProjectConfig, err error) {
|
||||
return config, config.validate()
|
||||
}
|
||||
|
||||
type NameData struct {
|
||||
Goos string
|
||||
Goarch string
|
||||
Os string
|
||||
Arch string
|
||||
Version string
|
||||
BinaryName string
|
||||
}
|
||||
|
||||
func (config *ProjectConfig) NameFor(goos, goarch, version string) (string, error) {
|
||||
var data = NameData{
|
||||
Goos: goos,
|
||||
Goarch: goarch,
|
||||
Os: uname.FromGo(goos),
|
||||
Arch: uname.FromGo(goarch),
|
||||
Version: version,
|
||||
BinaryName: config.BinaryName,
|
||||
}
|
||||
var out bytes.Buffer
|
||||
template, err := template.New(data.BinaryName).Parse(config.NameTemplate)
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
err = template.Execute(&out, data)
|
||||
return out.String(), err
|
||||
}
|
||||
|
||||
func (config *ProjectConfig) validate() (err error) {
|
||||
if config.BinaryName == "" {
|
||||
return errors.New("missing binary_name")
|
||||
@ -106,6 +137,9 @@ func (config *ProjectConfig) fillBasicData() {
|
||||
if len(config.Build.Arches) == 0 {
|
||||
config.Build.Arches = []string{"amd64", "386"}
|
||||
}
|
||||
if config.NameTemplate == "" {
|
||||
config.NameTemplate = "{{.BinaryName}}_{{.Os}}_{{.Arch}}"
|
||||
}
|
||||
}
|
||||
|
||||
func (config *ProjectConfig) fillGitData() (err error) {
|
||||
|
@ -69,6 +69,17 @@ func TestValidadeMinimalConfig(t *testing.T) {
|
||||
assert.NoError(config.validate())
|
||||
}
|
||||
|
||||
func TestNameTemplate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var config = ProjectConfig{
|
||||
BinaryName: "test",
|
||||
NameTemplate : "{{.BinaryName}}_{{.Os}}_{{.Goos}}_{{.Arch}}_{{.Goarch}}_{{.Version}}",
|
||||
}
|
||||
name, err := config.NameFor("darwin", "amd64", "v1.2.3")
|
||||
assert.NoError(err)
|
||||
assert.Equal("test_Darwin_darwin_x86_64_amd64_v1.2.3", name)
|
||||
}
|
||||
|
||||
func assertFiles(t *testing.T, dir string, files []string) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
@ -10,3 +10,4 @@ build:
|
||||
- windows
|
||||
- darwin
|
||||
- linux
|
||||
NameTemplate: {{.BinaryName}}_{{.Version}}_{{.Os}}_{{.Arch}}
|
||||
|
@ -37,11 +37,15 @@ func (Pipe) Run(config config.ProjectConfig) error {
|
||||
|
||||
func build(system, arch string, config config.ProjectConfig) error {
|
||||
log.Println("Building", system+"/"+arch, "...")
|
||||
name, err := config.NameFor(system, arch, config.Git.CurrentTag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := exec.Command(
|
||||
"go",
|
||||
"build",
|
||||
"-ldflags=-s -w -X main.version="+config.Git.CurrentTag,
|
||||
"-o", target(system, arch, config.BinaryName),
|
||||
"-o", "dist/"+name+"/"+config.BinaryName,
|
||||
config.Build.Main,
|
||||
)
|
||||
cmd.Env = append(
|
||||
@ -54,13 +58,8 @@ func build(system, arch string, config config.ProjectConfig) error {
|
||||
var stdout bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stdout
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
if err := cmd.Run(); err != nil {
|
||||
return errors.New(stdout.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func target(system, arch, binary string) string {
|
||||
return "dist/" + binary + "_" + uname.FromGo(system) + "_" + uname.FromGo(arch) + "/" + binary
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/goreleaser/releaser/config"
|
||||
"github.com/goreleaser/releaser/uname"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/appengine/file"
|
||||
)
|
||||
|
||||
// Pipe for compress
|
||||
@ -36,7 +37,11 @@ func (Pipe) Run(config config.ProjectConfig) error {
|
||||
}
|
||||
|
||||
func create(system, arch string, config config.ProjectConfig) error {
|
||||
file, err := os.Create("dist/" + nameFor(system, arch, config.BinaryName) + ".tar.gz")
|
||||
name, err := config.NameFor(system, arch, config.Git.CurrentTag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := os.Create("dist/" + name + ".tar.gz")
|
||||
log.Println("Creating", file.Name(), "...")
|
||||
if err != nil {
|
||||
return err
|
||||
@ -53,7 +58,7 @@ func create(system, arch string, config config.ProjectConfig) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return addFile(tw, config.BinaryName+ext(system), binaryPath(system, arch, config.BinaryName))
|
||||
return addFile(tw, config.BinaryName+extFor(system), "dist/"+name+"/"+config.BinaryName)
|
||||
}
|
||||
|
||||
func addFile(tw *tar.Writer, name, path string) (err error) {
|
||||
@ -82,15 +87,7 @@ func addFile(tw *tar.Writer, name, path string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func nameFor(system, arch, binary string) string {
|
||||
return binary + "_" + uname.FromGo(system) + "_" + uname.FromGo(arch)
|
||||
}
|
||||
|
||||
func binaryPath(system, arch, binary string) string {
|
||||
return "dist/" + nameFor(system, arch, binary) + "/" + binary
|
||||
}
|
||||
|
||||
func ext(system string) string {
|
||||
func extFor(system string) string {
|
||||
if system == "windows" {
|
||||
return ".exe"
|
||||
}
|
||||
|
@ -46,7 +46,11 @@ func (Pipe) Run(config config.ProjectConfig) error {
|
||||
system := system
|
||||
arch := arch
|
||||
g.Go(func() error {
|
||||
return upload(client, *r.ID, owner, repo, system, arch, config.BinaryName)
|
||||
name, err := config.NameFor(system, arch, config.Git.CurrentTag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return upload(client, *r.ID, owner, repo, name+".tar.gz")
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -63,8 +67,7 @@ func description(diff string) string {
|
||||
return result + "\nBuilt with " + string(bts)
|
||||
}
|
||||
|
||||
func upload(client *github.Client, releaseID int, owner, repo, system, arch, binaryName string) error {
|
||||
name := binaryName + "_" + uname.FromGo(system) + "_" + uname.FromGo(arch) + ".tar.gz"
|
||||
func upload(client *github.Client, releaseID int, owner, repo, name string) error {
|
||||
file, err := os.Open("dist/" + name)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
x
Reference in New Issue
Block a user