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

feat: custom tag.sort (#3611)

closes #3609

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2022-12-02 21:50:04 -03:00 committed by GitHub
parent 4c62c9b450
commit f5696d01ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 2 deletions

View File

@ -22,11 +22,20 @@ func (Pipe) String() string {
return "getting and validating git state"
}
// this pipe does not implement Defaulter because it runs before the defaults
// pipe, and we need to set some defaults of our own first.
func setDefaults(ctx *context.Context) {
if ctx.Config.Git.TagSort == "" {
ctx.Config.Git.TagSort = "-version:refname"
}
}
// Run the pipe.
func (Pipe) Run(ctx *context.Context) error {
if _, err := exec.LookPath("git"); err != nil {
return ErrNoGit
}
setDefaults(ctx)
info, err := getInfo(ctx)
if err != nil {
return err
@ -275,7 +284,7 @@ func gitTagsPointingAt(ctx *context.Context, ref string) ([]string, error) {
"--points-at",
ref,
"--sort",
"-version:refname",
ctx.Config.Git.TagSort,
))
}

View File

@ -172,6 +172,24 @@ func TestShallowClone(t *testing.T) {
})
}
func TestTagSortOrder(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
testlib.GitCommit(t, "commit1")
testlib.GitCommit(t, "commit2")
testlib.GitCommit(t, "commit3")
testlib.GitTag(t, "v0.0.1-rc.2")
testlib.GitTag(t, "v0.0.1")
ctx := context.New(config.Project{
Git: config.Git{
TagSort: "-version:creatordate",
},
})
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
}
func TestTagIsNotLastCommit(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)

View File

@ -16,6 +16,11 @@ import (
"github.com/invopop/jsonschema"
)
// Git configs.
type Git struct {
TagSort string `yaml:"tag_sort,omitempty" json:"tag_sort,omitempty"`
}
// GitHubURLs holds the URLs to be used when using github enterprise.
type GitHubURLs struct {
API string `yaml:"api,omitempty" json:"api,omitempty"`
@ -931,6 +936,7 @@ type Project struct {
Announce Announce `yaml:"announce,omitempty" json:"announce,omitempty"`
SBOMs []SBOM `yaml:"sboms,omitempty" json:"sboms,omitempty"`
Chocolateys []Chocolatey `yaml:"chocolateys,omitempty" json:"chocolatey,omitempty"`
Git Git `yaml:"git,omitempty" json:"git,omitempty"`
UniversalBinaries []UniversalBinary `yaml:"universal_binaries,omitempty" json:"universal_binaries,omitempty"`

View File

@ -572,7 +572,7 @@ builds:
## Complex templated environment variables
> Since v1.14.
> Since v1.14.0.
Builds environment variables are templateable.

View File

@ -0,0 +1,15 @@
# Git
> Since v1.14.0.
This allows you to change the behavior of some Git commands.
```yaml
# .goreleaser.yaml
git:
# What should be used to sort tags when gathering the current and previous
# tags if there are more than one tag in the same commit.
#
# Default: `-version:refname`
tag_sort: -version:creatordate
```

View File

@ -88,6 +88,7 @@ nav:
- customization/hooks.md
- customization/dist.md
- customization/project.md
- customization/git.md
- Build:
- customization/build.md
- customization/verifiable_builds.md