You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-09-16 09:26:52 +02:00
@@ -9,6 +9,6 @@ trim_trailing_whitespace = true
|
|||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
|
|
||||||
[*.md]
|
[*.{md,yml}]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
10
README.md
10
README.md
@@ -76,11 +76,19 @@ repo: user/repo
|
|||||||
binary_name: my-binary
|
binary_name: my-binary
|
||||||
archive:
|
archive:
|
||||||
name_template: "{{.BinaryName}}_{{.Version}}_{{.Os}}_{{.Arch}}"
|
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}}`
|
> - Default `name_template` is `{{.BinaryName}}_{{.Os}}_{{.Arch}}`
|
||||||
> - Valid formats are `tar.gz` and `zip`, default is `tar.gz`
|
> - 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
|
### Add more files
|
||||||
|
|
||||||
|
@@ -3,14 +3,13 @@ package config
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
|
||||||
"github.com/goreleaser/releaser/uname"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ArchiveConfig config used for the archive
|
// ArchiveConfig config used for the archive
|
||||||
type ArchiveConfig struct {
|
type ArchiveConfig struct {
|
||||||
Format string
|
Format string
|
||||||
NameTemplate string `yaml:"name_template"`
|
NameTemplate string `yaml:"name_template"`
|
||||||
|
Replacements map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type archiveNameData struct {
|
type archiveNameData struct {
|
||||||
@@ -23,8 +22,8 @@ type archiveNameData struct {
|
|||||||
// ArchiveName following the given template
|
// ArchiveName following the given template
|
||||||
func (config ProjectConfig) ArchiveName(goos, goarch string) (string, error) {
|
func (config ProjectConfig) ArchiveName(goos, goarch string) (string, error) {
|
||||||
var data = archiveNameData{
|
var data = archiveNameData{
|
||||||
Os: uname.FromGo(goos),
|
Os: replace(config.Archive.Replacements, goos),
|
||||||
Arch: uname.FromGo(goarch),
|
Arch: replace(config.Archive.Replacements, goarch),
|
||||||
Version: config.Git.CurrentTag,
|
Version: config.Git.CurrentTag,
|
||||||
BinaryName: config.BinaryName,
|
BinaryName: config.BinaryName,
|
||||||
}
|
}
|
||||||
@@ -36,3 +35,11 @@ func (config ProjectConfig) ArchiveName(goos, goarch string) (string, error) {
|
|||||||
err = t.Execute(&out, data)
|
err = t.Execute(&out, data)
|
||||||
return out.String(), err
|
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{
|
Archive: ArchiveConfig{
|
||||||
NameTemplate: "{{.BinaryName}}_{{.Os}}_{{.Arch}}_{{.Version}}",
|
NameTemplate: "{{.BinaryName}}_{{.Os}}_{{.Arch}}_{{.Version}}",
|
||||||
|
Replacements: map[string]string{
|
||||||
|
"darwin": "Darwin",
|
||||||
|
"amd64": "x86_64",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
name, err := config.ArchiveName("darwin", "amd64")
|
name, err := config.ArchiveName("darwin", "amd64")
|
||||||
|
@@ -113,6 +113,18 @@ func (config *ProjectConfig) fillBasicData() {
|
|||||||
if config.Archive.Format == "" {
|
if config.Archive.Format == "" {
|
||||||
config.Archive.Format = "tar.gz"
|
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) {
|
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"))
|
|
||||||
}
|
|
Reference in New Issue
Block a user