mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-07 07:10:11 +02:00
parent
ef5a7a2fd9
commit
d2b1cb5d26
@ -9,6 +9,6 @@ trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
|
||||
[*.md]
|
||||
[*.{md,yml}]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
10
README.md
10
README.md
@ -76,11 +76,19 @@ repo: user/repo
|
||||
binary_name: my-binary
|
||||
archive:
|
||||
name_template: "{{.BinaryName}}_{{.Version}}_{{.Os}}_{{.Arch}}"
|
||||
format: tar.gz
|
||||
format: zip
|
||||
replacements:
|
||||
amd64: 64-bit
|
||||
386: 32-bit
|
||||
darwin: macOS
|
||||
linux: Tux
|
||||
```
|
||||
|
||||
> - Default `name_template` is `{{.BinaryName}}_{{.Os}}_{{.Arch}}`
|
||||
> - Valid formats are `tar.gz` and `zip`, default is `tar.gz`
|
||||
> - By default, `replacements` replace `GOOS` with `uname -s` values and
|
||||
> `GOARCH` with `uname -m` values. They keys should always be in the `GOOS` and
|
||||
> `GOARCH` form.
|
||||
|
||||
### Add more files
|
||||
|
||||
|
@ -3,14 +3,13 @@ package config
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
|
||||
"github.com/goreleaser/releaser/uname"
|
||||
)
|
||||
|
||||
// ArchiveConfig config used for the archive
|
||||
type ArchiveConfig struct {
|
||||
Format string
|
||||
NameTemplate string `yaml:"name_template"`
|
||||
Replacements map[string]string
|
||||
}
|
||||
|
||||
type archiveNameData struct {
|
||||
@ -23,8 +22,8 @@ type archiveNameData struct {
|
||||
// ArchiveName following the given template
|
||||
func (config ProjectConfig) ArchiveName(goos, goarch string) (string, error) {
|
||||
var data = archiveNameData{
|
||||
Os: uname.FromGo(goos),
|
||||
Arch: uname.FromGo(goarch),
|
||||
Os: replace(config.Archive.Replacements, goos),
|
||||
Arch: replace(config.Archive.Replacements, goarch),
|
||||
Version: config.Git.CurrentTag,
|
||||
BinaryName: config.BinaryName,
|
||||
}
|
||||
@ -36,3 +35,11 @@ func (config ProjectConfig) ArchiveName(goos, goarch string) (string, error) {
|
||||
err = t.Execute(&out, data)
|
||||
return out.String(), err
|
||||
}
|
||||
|
||||
func replace(replacements map[string]string, original string) string {
|
||||
result := replacements[original]
|
||||
if result == "" {
|
||||
return original
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
@ -15,6 +15,10 @@ func TestNameTemplate(t *testing.T) {
|
||||
},
|
||||
Archive: ArchiveConfig{
|
||||
NameTemplate: "{{.BinaryName}}_{{.Os}}_{{.Arch}}_{{.Version}}",
|
||||
Replacements: map[string]string{
|
||||
"darwin": "Darwin",
|
||||
"amd64": "x86_64",
|
||||
},
|
||||
},
|
||||
}
|
||||
name, err := config.ArchiveName("darwin", "amd64")
|
||||
|
@ -113,6 +113,18 @@ func (config *ProjectConfig) fillBasicData() {
|
||||
if config.Archive.Format == "" {
|
||||
config.Archive.Format = "tar.gz"
|
||||
}
|
||||
if len(config.Archive.Replacements) == 0 {
|
||||
config.Archive.Replacements = map[string]string{
|
||||
"darwin": "Darwin",
|
||||
"linux": "Linux",
|
||||
"freebsd": "FreeBSD",
|
||||
"openbsd": "OpenBSD",
|
||||
"netbsd": "NetBSD",
|
||||
"windows": "Windows",
|
||||
"386": "i386",
|
||||
"amd64": "x86_64",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (config *ProjectConfig) fillGitData() (err error) {
|
||||
|
@ -1,21 +0,0 @@
|
||||
package uname
|
||||
|
||||
var mapping = map[string]string{
|
||||
"darwin": "Darwin",
|
||||
"linux": "Linux",
|
||||
"freebsd": "FreeBSD",
|
||||
"openbsd": "OpenBSD",
|
||||
"netbsd": "NetBSD",
|
||||
"windows": "Windows",
|
||||
"386": "i386",
|
||||
"amd64": "x86_64",
|
||||
}
|
||||
|
||||
// FromGo translates GOOS and GOARCH to uname compatibles
|
||||
func FromGo(s string) string {
|
||||
result := mapping[s]
|
||||
if result == "" {
|
||||
result = s
|
||||
}
|
||||
return result
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package uname
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUname(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
assert.Equal("Darwin", FromGo("darwin"))
|
||||
assert.Equal("blah", FromGo("blah"))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user