mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-26 04:22:05 +02:00
checksums name template support
This commit is contained in:
parent
31ba37351c
commit
c541d99c58
@ -11,8 +11,10 @@ builds:
|
||||
- amd64
|
||||
- arm
|
||||
- arm64
|
||||
checksum:
|
||||
name_template: '{{ .ProjectName }}_checksums.txt'
|
||||
archive:
|
||||
name_template: '{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
|
||||
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
|
||||
replacements:
|
||||
darwin: Darwin
|
||||
linux: Linux
|
||||
|
15
README.md
15
README.md
@ -339,6 +339,21 @@ snapshot:
|
||||
name_template: SNAPSHOT-{{.Commit}}
|
||||
```
|
||||
|
||||
### Checksums file customization
|
||||
|
||||
```yml
|
||||
# .goreleaser.yml
|
||||
checksum:
|
||||
# You can change the name of the checksums file.
|
||||
# This is parsed with Golang template engine and the following variables
|
||||
# are available:
|
||||
# - ProjectName
|
||||
# - Tag
|
||||
# - Version (Tag with the `v` prefix stripped)
|
||||
# The default is `{{ .ProjectName }}_{{ .Version }}_checksums.txt`
|
||||
name_template: "{{ .ProjectName }}_checksums.txt"
|
||||
```
|
||||
|
||||
### Homebrew tap customization
|
||||
|
||||
The brew section specifies how the formula should be created.
|
||||
|
@ -151,6 +151,14 @@ type Snapshot struct {
|
||||
XXX map[string]interface{} `yaml:",inline"`
|
||||
}
|
||||
|
||||
// Checksum config
|
||||
type Checksum struct {
|
||||
NameTemplate string `yaml:"name_template,omitempty"`
|
||||
|
||||
// Capture all undefined fields and should be empty after loading
|
||||
XXX map[string]interface{} `yaml:",inline"`
|
||||
}
|
||||
|
||||
// Project includes all project configuration
|
||||
type Project struct {
|
||||
ProjectName string `yaml:"project_name,omitempty"`
|
||||
@ -161,6 +169,7 @@ type Project struct {
|
||||
FPM FPM `yaml:",omitempty"`
|
||||
Snapcraft Snapcraft `yaml:",omitempty"`
|
||||
Snapshot Snapshot `yaml:",omitempty"`
|
||||
Checksum Checksum `yaml:",omitempty"`
|
||||
|
||||
// this is a hack ¯\_(ツ)_/¯
|
||||
SingleBuild Build `yaml:"build,omitempty"`
|
||||
@ -196,32 +205,33 @@ func LoadReader(fd io.Reader) (config Project, err error) {
|
||||
}
|
||||
|
||||
func checkOverflows(config Project) error {
|
||||
var checker = &overflowChecker{}
|
||||
checker.check(config.XXX, "")
|
||||
checker.check(config.Archive.XXX, "archive")
|
||||
var overflow = &overflowChecker{}
|
||||
overflow.check(config.XXX, "")
|
||||
overflow.check(config.Archive.XXX, "archive")
|
||||
for i, ov := range config.Archive.FormatOverrides {
|
||||
checker.check(ov.XXX, fmt.Sprintf("archive.format_overrides[%d]", i))
|
||||
overflow.check(ov.XXX, fmt.Sprintf("archive.format_overrides[%d]", i))
|
||||
}
|
||||
checker.check(config.Brew.XXX, "brew")
|
||||
checker.check(config.Brew.GitHub.XXX, "brew.github")
|
||||
overflow.check(config.Brew.XXX, "brew")
|
||||
overflow.check(config.Brew.GitHub.XXX, "brew.github")
|
||||
for i, build := range config.Builds {
|
||||
checker.check(build.XXX, fmt.Sprintf("builds[%d]", i))
|
||||
checker.check(build.Hooks.XXX, fmt.Sprintf("builds[%d].hooks", i))
|
||||
overflow.check(build.XXX, fmt.Sprintf("builds[%d]", i))
|
||||
overflow.check(build.Hooks.XXX, fmt.Sprintf("builds[%d].hooks", i))
|
||||
for j, ignored := range build.Ignore {
|
||||
checker.check(ignored.XXX, fmt.Sprintf("builds[%d].ignored_builds[%d]", i, j))
|
||||
overflow.check(ignored.XXX, fmt.Sprintf("builds[%d].ignored_builds[%d]", i, j))
|
||||
}
|
||||
}
|
||||
checker.check(config.FPM.XXX, "fpm")
|
||||
checker.check(config.Snapcraft.XXX, "snapcraft")
|
||||
checker.check(config.Release.XXX, "release")
|
||||
checker.check(config.Release.GitHub.XXX, "release.github")
|
||||
checker.check(config.SingleBuild.XXX, "build")
|
||||
checker.check(config.SingleBuild.Hooks.XXX, "builds.hooks")
|
||||
overflow.check(config.FPM.XXX, "fpm")
|
||||
overflow.check(config.Snapcraft.XXX, "snapcraft")
|
||||
overflow.check(config.Release.XXX, "release")
|
||||
overflow.check(config.Release.GitHub.XXX, "release.github")
|
||||
overflow.check(config.SingleBuild.XXX, "build")
|
||||
overflow.check(config.SingleBuild.Hooks.XXX, "builds.hooks")
|
||||
for i, ignored := range config.SingleBuild.Ignore {
|
||||
checker.check(ignored.XXX, fmt.Sprintf("builds.ignored_builds[%d]", i))
|
||||
overflow.check(ignored.XXX, fmt.Sprintf("builds.ignored_builds[%d]", i))
|
||||
}
|
||||
checker.check(config.Snapshot.XXX, "snapshot")
|
||||
return checker.err()
|
||||
overflow.check(config.Snapshot.XXX, "snapshot")
|
||||
overflow.check(config.Checksum.XXX, "checksum")
|
||||
return overflow.err()
|
||||
}
|
||||
|
||||
type overflowChecker struct {
|
||||
|
@ -54,6 +54,19 @@ func For(ctx *context.Context, target buildtarget.Target) (string, error) {
|
||||
)
|
||||
}
|
||||
|
||||
// ForChecksums returns the filename for the checksums file based on its
|
||||
// template
|
||||
func ForChecksums(ctx *context.Context) (string, error) {
|
||||
return apply(
|
||||
nameData{
|
||||
ProjectName: ctx.Config.ProjectName,
|
||||
Tag: ctx.Git.CurrentTag,
|
||||
Version: ctx.Version,
|
||||
},
|
||||
ctx.Config.Checksum.NameTemplate,
|
||||
)
|
||||
}
|
||||
|
||||
func apply(data nameData, templateStr string) (string, error) {
|
||||
var out bytes.Buffer
|
||||
t, err := template.New(data.ProjectName).Parse(templateStr)
|
||||
|
@ -10,8 +10,30 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestChecksums(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
|
||||
var config = config.Project{
|
||||
Checksum: config.Checksum{
|
||||
NameTemplate: "{{.ProjectName }}_{{.Tag}}_{{.Version}}_checksums.txt",
|
||||
},
|
||||
ProjectName: "testcheck",
|
||||
}
|
||||
var ctx = &context.Context{
|
||||
Config: config,
|
||||
Version: "1.0.0",
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.0",
|
||||
},
|
||||
}
|
||||
|
||||
name, err := ForChecksums(ctx)
|
||||
assert.NoError(err)
|
||||
assert.Equal("testcheck_v1.0.0_1.0.0_checksums.txt", name)
|
||||
}
|
||||
|
||||
func TestNameFor(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var assert = assert.New(t)
|
||||
|
||||
var config = config.Project{
|
||||
Archive: config.Archive{
|
||||
@ -37,7 +59,7 @@ func TestNameFor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNameForBuild(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var assert = assert.New(t)
|
||||
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
@ -83,8 +105,8 @@ func TestInvalidNameTemplate(t *testing.T) {
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestNameDefaltTemplate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
func TestNameDefaultTemplate(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Archive: config.Archive{
|
||||
@ -108,5 +130,4 @@ func TestNameDefaltTemplate(t *testing.T) {
|
||||
assert.Equal(key, name)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/checksum"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/name"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
@ -23,11 +24,12 @@ func (Pipe) Description() string {
|
||||
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
filename, err := name.ForChecksums(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := os.OpenFile(
|
||||
filepath.Join(
|
||||
ctx.Config.Dist,
|
||||
fmt.Sprintf("%v_checksums.txt", ctx.Config.ProjectName),
|
||||
),
|
||||
filepath.Join(ctx.Config.Dist, filename),
|
||||
os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_TRUNC,
|
||||
0644,
|
||||
)
|
||||
|
@ -12,11 +12,14 @@ import (
|
||||
)
|
||||
|
||||
// NameTemplate default name_template for the archive.
|
||||
const NameTemplate = "{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
||||
const NameTemplate = "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
||||
|
||||
// SnapshotNameTemplate represents the default format for snapshot release names.
|
||||
const SnapshotNameTemplate = "SNAPSHOT-{{ .Commit }}"
|
||||
|
||||
// ChecksumNameTemplate is the default name_template for the checksum file.
|
||||
const ChecksumNameTemplate = "{{ .ProjectName }}_{{ .Version }}_checksums.txt"
|
||||
|
||||
// Pipe for brew deployment
|
||||
type Pipe struct{}
|
||||
|
||||
@ -31,6 +34,9 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
if ctx.Config.Snapshot.NameTemplate == "" {
|
||||
ctx.Config.Snapshot.NameTemplate = SnapshotNameTemplate
|
||||
}
|
||||
if ctx.Config.Checksum.NameTemplate == "" {
|
||||
ctx.Config.Checksum.NameTemplate = ChecksumNameTemplate
|
||||
}
|
||||
if err := setReleaseDefaults(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user