feat: ✨ add option to fetch git tags when getting latest
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
925bfe59e6
commit
3625bbe90c
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user