From 675e2ea211998c6970dc5cb8eaab13e80816a886 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 18 Jan 2018 23:55:26 -0200 Subject: [PATCH] feat: allow Major, Minor and Patch fields on docker tags --- pipeline/docker/docker.go | 13 +++++++++++-- pipeline/docker/docker_test.go | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pipeline/docker/docker.go b/pipeline/docker/docker.go index 64f934219..677bd7005 100644 --- a/pipeline/docker/docker.go +++ b/pipeline/docker/docker.go @@ -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 diff --git a/pipeline/docker/docker_test.go b/pipeline/docker/docker_test.go index fba9ef497..7f24ccf6e 100644 --- a/pipeline/docker/docker_test.go +++ b/pipeline/docker/docker_test.go @@ -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: "",