1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

feat: allow Major, Minor and Patch fields on docker tags

This commit is contained in:
Carlos Alexandro Becker 2018-01-18 23:55:26 -02:00
parent e9351781cb
commit 675e2ea211
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 15 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
"text/template"
"github.com/apex/log"
"github.com/masterminds/semver"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
@ -119,13 +120,21 @@ func tagName(ctx *context.Context, tagTemplate string) (string, error) {
if err != nil {
return "", err
}
sv, err := semver.NewVersion(ctx.Git.CurrentTag)
if err != nil {
return "", err
}
data := struct {
Version, Tag string
Env map[string]string
Version, Tag string
Major, Minor, Patch int64
Env map[string]string
}{
Version: ctx.Version,
Tag: ctx.Git.CurrentTag,
Env: ctx.Env,
Major: sv.Major(),
Minor: sv.Minor(),
Patch: sv.Patch(),
}
err = t.Execute(&out, data)
return out.String(), err

View File

@ -65,6 +65,8 @@ func TestRunPipe(t *testing.T) {
Binary: "mybin",
TagTemplates: []string{
"{{.Tag}}-{{.Env.FOO}}",
"v{{.Major}}",
"v{{.Major}}.{{.Minor}}",
"latest",
},
Files: []string{
@ -73,6 +75,8 @@ func TestRunPipe(t *testing.T) {
},
expect: []string{
registry + "goreleaser/test_run_pipe:v1.0.0-123",
registry + "goreleaser/test_run_pipe:v1",
registry + "goreleaser/test_run_pipe:v1.0",
registry + "goreleaser/test_run_pipe:latest",
},
err: "",