feat: add option to fetch git tags when getting latest
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
RaviAnand Mohabir 2024-06-26 16:09:18 +02:00
parent 925bfe59e6
commit 3625bbe90c
2 changed files with 22 additions and 2 deletions

View File

@ -36,6 +36,7 @@ type Args struct {
Notes string `envconfig:"PLUGIN_NOTES"`
IsPrerelease bool `envconfig:"PLUGIN_IS_PRERELEASE"`
SkipIfNoNotesFile bool `envconfig:"PLUGIN_SKIP_IF_NO_NOTES_FILE"`
FetchGitTags bool `envconfig:"PLUGIN_FETCH_GIT_TAGS" default:"true"`
}
type TitleTemplateCtx struct {
@ -74,7 +75,11 @@ func Exec(ctx context.Context, args Args) error {
}
if args.UseLatestGitTag {
tag, err = getLatestGitTag()
var options = make([]GetLatestGitTagOption, 0)
if args.FetchGitTags {
options = append(options, FetchTags)
}
tag, err = getLatestGitTag(options...)
if err != nil {
return fmt.Errorf("error getting git tag %w", err)

View File

@ -13,7 +13,22 @@ import (
"os/exec"
)
func getLatestGitTag() (string, error) {
type GetLatestGitTagOption func() error
var FetchTags = func() error {
err := exec.Command("git", "fetch", "--tags")
return err.Err
}
func getLatestGitTag(options ...GetLatestGitTagOption) (string, error) {
for _, opt := range options {
err := opt()
if err != nil {
return "", err
}
}
tag, err := exec.Command("git", "describe", "--tags", "--abbrev=0").Output()
if err != nil {