mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +02:00
feat: get annotated tag message (#2730)
refs #2726 Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
parent
cbcdd41f97
commit
9b9eef04a2
@ -116,6 +116,11 @@ func getGitInfo() (context.GitInfo, error) {
|
||||
}, ErrNoTag
|
||||
}
|
||||
|
||||
subject, err := getTagSubject(tag)
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get tag subject: %w", err)
|
||||
}
|
||||
|
||||
previous, err := getPreviousTag(tag)
|
||||
if err != nil {
|
||||
// shouldn't error, will only affect templates
|
||||
@ -132,6 +137,7 @@ func getGitInfo() (context.GitInfo, error) {
|
||||
CommitDate: date,
|
||||
URL: gitURL,
|
||||
Summary: summary,
|
||||
Subject: subject,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -199,6 +205,10 @@ func getSummary() (string, error) {
|
||||
return git.Clean(git.Run("describe", "--always", "--dirty", "--tags"))
|
||||
}
|
||||
|
||||
func getTagSubject(tag string) (string, error) {
|
||||
return git.Clean(git.Run("tag", "-l", "--format='%(contents:subject)'", tag))
|
||||
}
|
||||
|
||||
func getTag() (string, error) {
|
||||
var tag string
|
||||
var err error
|
||||
|
@ -37,6 +37,22 @@ func TestSingleCommit(t *testing.T) {
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||
require.Equal(t, "v0.0.1", ctx.Git.Summary)
|
||||
require.Equal(t, "commit1", ctx.Git.Subject)
|
||||
}
|
||||
|
||||
func TestAnnotatedTags(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
||||
testlib.GitCommit(t, "commit1")
|
||||
testlib.GitAnnotatedTag(t, "v0.0.1", "first version")
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||
require.Equal(t, "first version", ctx.Git.Subject)
|
||||
require.Equal(t, "v0.0.1", ctx.Git.Summary)
|
||||
}
|
||||
|
||||
func TestBranch(t *testing.T) {
|
||||
|
@ -50,6 +50,14 @@ func GitTag(tb testing.TB, tag string) {
|
||||
require.Empty(tb, out)
|
||||
}
|
||||
|
||||
// GitAnnotatedTag creates an annotated tag.
|
||||
func GitAnnotatedTag(tb testing.TB, tag, subject string) {
|
||||
tb.Helper()
|
||||
out, err := fakeGit("tag", "-a", tag, "-m", subject)
|
||||
require.NoError(tb, err)
|
||||
require.Empty(tb, out)
|
||||
}
|
||||
|
||||
// GitBranch creates a git branch.
|
||||
func GitBranch(tb testing.TB, branch string) {
|
||||
tb.Helper()
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/pkg/build"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -40,6 +39,7 @@ const (
|
||||
commitTimestamp = "CommitTimestamp"
|
||||
gitURL = "GitURL"
|
||||
summary = "Summary"
|
||||
subject = "Subject"
|
||||
releaseURL = "ReleaseURL"
|
||||
major = "Major"
|
||||
minor = "Minor"
|
||||
@ -89,6 +89,7 @@ func New(ctx *context.Context) *Template {
|
||||
commitTimestamp: ctx.Git.CommitDate.UTC().Unix(),
|
||||
gitURL: ctx.Git.URL,
|
||||
summary: ctx.Git.Summary,
|
||||
subject: ctx.Git.Subject,
|
||||
releaseURL: ctx.ReleaseURL,
|
||||
env: ctx.Env,
|
||||
date: ctx.Date.UTC().Format(time.RFC3339),
|
||||
|
@ -33,6 +33,7 @@ func TestWithArtifact(t *testing.T) {
|
||||
ctx.Git.Commit = "commit"
|
||||
ctx.Git.FullCommit = "fullcommit"
|
||||
ctx.Git.ShortCommit = "shortcommit"
|
||||
ctx.Git.Subject = "awesome release"
|
||||
ctx.ReleaseNotes = "test release notes"
|
||||
for expect, tmpl := range map[string]string{
|
||||
"bar": "{{.Env.FOO}}",
|
||||
@ -58,6 +59,7 @@ func TestWithArtifact(t *testing.T) {
|
||||
"1.2.4": "{{.Version | incpatch }}",
|
||||
"test release notes": "{{ .ReleaseNotes }}",
|
||||
"v1.2.2": "{{ .PreviousTag }}",
|
||||
"awesome release": "{{ .Subject }}",
|
||||
} {
|
||||
tmpl := tmpl
|
||||
expect := expect
|
||||
|
@ -27,6 +27,7 @@ type GitInfo struct {
|
||||
CommitDate time.Time
|
||||
URL string
|
||||
Summary string
|
||||
Subject string
|
||||
}
|
||||
|
||||
// Env is the environment variables.
|
||||
|
@ -43,6 +43,7 @@ On fields that support templating, these fields are always available:
|
||||
| `.ReleaseURL` | the current release download url[^4] |
|
||||
| `.Summary` | the git summary, e.g. `v1.0.0-10-g34f56g3`[^5] |
|
||||
| `.PrefixedSummary` | the git summary prefixed with the monorepo config tag prefix (if any) |
|
||||
| `.Subject` | the annotated tag message, or the message of the commit it points out to |
|
||||
|
||||
[^1]: The `v` prefix is stripped and it might be changed in `snapshot` and `nightly` builds.
|
||||
[^2]: Assuming `Tag` is a valid a SemVer, otherwise empty/zeroed.
|
||||
|
Loading…
Reference in New Issue
Block a user