1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-11 14:39:28 +02:00

feat: annotated tag contents (#2744)

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2021-12-06 16:52:26 -03:00 committed by GitHub
parent 167d95e67f
commit 6ea7fb792a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 20 deletions

View File

@ -121,6 +121,11 @@ func getGitInfo() (context.GitInfo, error) {
return context.GitInfo{}, fmt.Errorf("couldn't get tag subject: %w", err)
}
contents, err := getTagContents(tag)
if err != nil {
return context.GitInfo{}, fmt.Errorf("couldn't get tag contents: %w", err)
}
previous, err := getPreviousTag(tag)
if err != nil {
// shouldn't error, will only affect templates
@ -137,7 +142,8 @@ func getGitInfo() (context.GitInfo, error) {
CommitDate: date,
URL: gitURL,
Summary: summary,
Subject: subject,
TagSubject: subject,
TagContents: contents,
}, nil
}
@ -209,6 +215,11 @@ func getTagSubject(tag string) (string, error) {
return git.Clean(git.Run("tag", "-l", "--format='%(contents:subject)'", tag))
}
func getTagContents(tag string) (string, error) {
out, err := git.Run("tag", "-l", "--format='%(contents)'", tag)
return strings.ReplaceAll(strings.TrimSuffix(out, "\n"), "'", ""), err
}
func getTag() (string, error) {
var tag string
var err error

View File

@ -6,11 +6,10 @@ import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
)
func TestDescription(t *testing.T) {
@ -37,21 +36,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)
require.Equal(t, "commit1", ctx.Git.TagSubject)
}
func TestAnnotatedTags(t *testing.T) {
testlib.Mktmp(t)
t.Log(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")
testlib.GitAnnotatedTag(t, "v0.0.1", "first version\n\nlalalla\nlalal\nlah")
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, "first version", ctx.Git.TagSubject)
require.Equal(t, "first version\n\nlalalla\nlalal\nlah\n", ctx.Git.TagContents)
require.Equal(t, "v0.0.1", ctx.Git.Summary)
}

View File

@ -51,9 +51,9 @@ func GitTag(tb testing.TB, tag string) {
}
// GitAnnotatedTag creates an annotated tag.
func GitAnnotatedTag(tb testing.TB, tag, subject string) {
func GitAnnotatedTag(tb testing.TB, tag, message string) {
tb.Helper()
out, err := fakeGit("tag", "-a", tag, "-m", subject)
out, err := fakeGit("tag", "-a", tag, "-m", message)
require.NoError(tb, err)
require.Empty(tb, out)
}

View File

@ -39,7 +39,8 @@ const (
commitTimestamp = "CommitTimestamp"
gitURL = "GitURL"
summary = "Summary"
subject = "Subject"
tagSubject = "TagSubject"
tagContents = "TagContents"
releaseURL = "ReleaseURL"
major = "Major"
minor = "Minor"
@ -89,7 +90,8 @@ func New(ctx *context.Context) *Template {
commitTimestamp: ctx.Git.CommitDate.UTC().Unix(),
gitURL: ctx.Git.URL,
summary: ctx.Git.Summary,
subject: ctx.Git.Subject,
tagSubject: ctx.Git.TagSubject,
tagContents: ctx.Git.TagContents,
releaseURL: ctx.ReleaseURL,
env: ctx.Env,
date: ctx.Date.UTC().Format(time.RFC3339),

View File

@ -33,7 +33,8 @@ func TestWithArtifact(t *testing.T) {
ctx.Git.Commit = "commit"
ctx.Git.FullCommit = "fullcommit"
ctx.Git.ShortCommit = "shortcommit"
ctx.Git.Subject = "awesome release"
ctx.Git.TagSubject = "awesome release"
ctx.Git.TagContents = "awesome release\n\nanother line"
ctx.ReleaseNotes = "test release notes"
for expect, tmpl := range map[string]string{
"bar": "{{.Env.FOO}}",
@ -59,7 +60,8 @@ func TestWithArtifact(t *testing.T) {
"1.2.4": "{{.Version | incpatch }}",
"test release notes": "{{ .ReleaseNotes }}",
"v1.2.2": "{{ .PreviousTag }}",
"awesome release": "{{ .Subject }}",
"awesome release": "{{ .TagSubject }}",
"awesome release\n\nanother line": "{{ .TagContents }}",
} {
tmpl := tmpl
expect := expect

View File

@ -27,7 +27,8 @@ type GitInfo struct {
CommitDate time.Time
URL string
Summary string
Subject string
TagSubject string
TagContents string
}
// Env is the environment variables.

View File

@ -43,13 +43,16 @@ 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 |
| `.TagSubject` | the annotated tag message subject, or the message subject of the commit it points out[^6] |
| `.TagContents` | the annotated tag message, or the message of the commit it points out[^7] |
[^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.
[^3]: Will panic if not a semantic version.
[^4]: Composed from the current SCM's download URL and current tag. For instance, on GitHub, it'll be `https://github.com/{owner}/{repo}/releases/tag/{tag}`.
[^5]: It is generated by `git describe --dirty --always --tags`, the format will be `{Tag}-$N-{CommitSHA}`
[^6]: As reported by `git tag -l --format='%(contents:subject)'`
[^7]: As reported by `git tag -l --format='%(contents)'`
## Single-artifact extra fields
@ -58,15 +61,15 @@ may have some extra fields:
| Key | Description |
|-----------------|---------------------------------------|
| `.Os` | `GOOS`[^6] |
| `.Arch` | `GOARCH`[^6] |
| `.Arm` | `GOARM`[^6] |
| `.Mips` | `GOMIPS`[^6] |
| `.Os` | `GOOS`[^8] |
| `.Arch` | `GOARCH`[^8] |
| `.Arm` | `GOARM`[^8] |
| `.Mips` | `GOMIPS`[^8] |
| `.Binary` | binary name |
| `.ArtifactName` | archive name |
| `.ArtifactPath` | absolute path to artifact |
[^6]: Might have been replaced by `archives.replacements`.
[^8]: Might have been replaced by `archives.replacements`.
## nFPM extra fields