mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-04 03:11:55 +02:00
parent
4ce13bc7c3
commit
5dba7fbfdf
@ -129,6 +129,8 @@ type Release struct {
|
||||
|
||||
// FPM config
|
||||
type FPM struct {
|
||||
NameTemplate string `yaml:"name_template,omitempty"`
|
||||
Replacements map[string]string `yaml:",omitempty"`
|
||||
Formats []string `yaml:",omitempty"`
|
||||
Dependencies []string `yaml:",omitempty"`
|
||||
Conflicts []string `yaml:",omitempty"`
|
||||
|
@ -9,6 +9,29 @@ generate `.deb`, `.rpm` and other archives. Check its
|
||||
```yml
|
||||
# .goreleaser.yml
|
||||
fpm:
|
||||
# You can change the name of the package.
|
||||
# This is parsed with the Go template engine and the following variables
|
||||
# are available:
|
||||
# - ProjectName
|
||||
# - Tag
|
||||
# - Version (Git tag without `v` prefix)
|
||||
# - Os
|
||||
# - Arch
|
||||
# - Arm (ARM version)
|
||||
# - Env (environment variables)
|
||||
# Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
|
||||
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
|
||||
|
||||
# Replacements for GOOS and GOARCH in the package name.
|
||||
# Keys should be valid GOOSs or GOARCHs.
|
||||
# Values are the respective replacements.
|
||||
# Default is empty.
|
||||
replacements:
|
||||
amd64: 64-bit
|
||||
386: 32-bit
|
||||
darwin: macOS
|
||||
linux: Tux
|
||||
|
||||
# Your app's vendor.
|
||||
# Default is empty.
|
||||
vendor: Drum Roll Inc.
|
||||
|
@ -14,13 +14,15 @@ import (
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/linux"
|
||||
"github.com/goreleaser/goreleaser/internal/nametemplate"
|
||||
"github.com/goreleaser/goreleaser/internal/template"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
)
|
||||
|
||||
// ErrNoFPM is shown when fpm cannot be found in $PATH
|
||||
var ErrNoFPM = errors.New("fpm not present in $PATH")
|
||||
|
||||
const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
||||
|
||||
// Pipe for fpm packaging
|
||||
type Pipe struct{}
|
||||
|
||||
@ -30,8 +32,12 @@ func (Pipe) String() string {
|
||||
|
||||
// Default sets the pipe defaults
|
||||
func (Pipe) Default(ctx *context.Context) error {
|
||||
if ctx.Config.FPM.Bindir == "" {
|
||||
ctx.Config.FPM.Bindir = "/usr/local/bin"
|
||||
var fpm = &ctx.Config.FPM
|
||||
if fpm.Bindir == "" {
|
||||
fpm.Bindir = "/usr/local/bin"
|
||||
}
|
||||
if fpm.NameTemplate == "" {
|
||||
fpm.NameTemplate = defaultNameTemplate
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -74,12 +80,14 @@ func doRun(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func create(ctx *context.Context, format, arch string, binaries []artifact.Artifact) error {
|
||||
// TODO: should add template support here probably... for now, let's use archive's template
|
||||
folder, err := nametemplate.Apply(ctx, binaries[0], ctx.Config.ProjectName)
|
||||
name, err := template.Apply(
|
||||
ctx.Config.FPM.NameTemplate,
|
||||
template.NewFields(ctx, binaries[0], ctx.Config.FPM.Replacements),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var path = filepath.Join(ctx.Config.Dist, folder)
|
||||
var path = filepath.Join(ctx.Config.Dist, name)
|
||||
var file = path + "." + format
|
||||
var log = log.WithField("format", format).WithField("arch", arch)
|
||||
dir, err := ioutil.TempDir("", "fpm")
|
||||
@ -120,7 +128,7 @@ func create(ctx *context.Context, format, arch string, binaries []artifact.Artif
|
||||
}
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Type: artifact.LinuxPackage,
|
||||
Name: folder + "." + format,
|
||||
Name: name + "." + format,
|
||||
Path: file,
|
||||
Goos: binaries[0].Goos,
|
||||
Goarch: binaries[0].Goarch,
|
||||
|
@ -44,11 +44,8 @@ func TestRunPipe(t *testing.T) {
|
||||
Config: config.Project{
|
||||
ProjectName: "mybin",
|
||||
Dist: dist,
|
||||
// TODO: remove this when fpm have its own name template
|
||||
Archive: config.Archive{
|
||||
NameTemplate: "foo",
|
||||
},
|
||||
FPM: config.FPM{
|
||||
NameTemplate: defaultNameTemplate,
|
||||
Formats: []string{"deb", "rpm"},
|
||||
Dependencies: []string{"make"},
|
||||
Conflicts: []string{"git"},
|
||||
@ -92,6 +89,27 @@ func TestNoFPMInPath(t *testing.T) {
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), ErrNoFPM.Error())
|
||||
}
|
||||
|
||||
func TestInvalidNameTemplate(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Parallelism: runtime.NumCPU(),
|
||||
Artifacts: artifact.New(),
|
||||
Config: config.Project{
|
||||
FPM: config.FPM{
|
||||
NameTemplate: "{{.Foo}",
|
||||
Formats: []string{"deb"},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "mybin",
|
||||
Goos: "linux",
|
||||
Goarch: "amd64",
|
||||
Type: artifact.Binary,
|
||||
})
|
||||
assert.Contains(t, Pipe{}.Run(ctx).Error(), `template: {{.Foo}:1: unexpected "}" in operand`)
|
||||
}
|
||||
|
||||
|
||||
func TestCreateFileDoesntExist(t *testing.T) {
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
assert.NoError(t, err)
|
||||
@ -119,7 +137,7 @@ func TestCreateFileDoesntExist(t *testing.T) {
|
||||
Goarch: "amd64",
|
||||
Type: artifact.Binary,
|
||||
})
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
assert.Contains(t, Pipe{}.Run(ctx).Error(), `dist/mybin/mybin', does it exist?`)
|
||||
}
|
||||
|
||||
func TestDefault(t *testing.T) {
|
||||
@ -130,6 +148,7 @@ func TestDefault(t *testing.T) {
|
||||
}
|
||||
assert.NoError(t, Pipe{}.Default(ctx))
|
||||
assert.Equal(t, "/usr/local/bin", ctx.Config.FPM.Bindir)
|
||||
assert.Equal(t, defaultNameTemplate, ctx.Config.FPM.NameTemplate)
|
||||
}
|
||||
|
||||
func TestDefaultSet(t *testing.T) {
|
||||
@ -137,9 +156,11 @@ func TestDefaultSet(t *testing.T) {
|
||||
Config: config.Project{
|
||||
FPM: config.FPM{
|
||||
Bindir: "/bin",
|
||||
NameTemplate: "foo",
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(t, Pipe{}.Default(ctx))
|
||||
assert.Equal(t, "/bin", ctx.Config.FPM.Bindir)
|
||||
assert.Equal(t, "foo", ctx.Config.FPM.NameTemplate)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user