fix: revert: fix: 🐛 use latest instead of last (oldest) tag

- Add logs
This commit is contained in:
RaviAnand Mohabir 2024-07-11 17:25:35 +02:00
parent 913e80c62b
commit fe6812860e
3 changed files with 23 additions and 10 deletions

View File

@ -24,6 +24,7 @@ func init() {
tagRegex *string = flag.String("tag-regex", "", "Regex pattern to look for tag in tag-file") tagRegex *string = flag.String("tag-regex", "", "Regex pattern to look for tag in tag-file")
notes *string = flag.String("notes", "", "Notes to use in release") notes *string = flag.String("notes", "", "Notes to use in release")
notesFile *string = flag.String("notes-file", "", "File to use for release notes") notesFile *string = flag.String("notes-file", "", "File to use for release notes")
logLevel *string = flag.String("log-level", "", "Level for logging")
) )
flag.Parse() flag.Parse()
@ -47,6 +48,10 @@ func init() {
if notesFile != nil && *notesFile != "" { if notesFile != nil && *notesFile != "" {
args.NotesFile = *notesFile args.NotesFile = *notesFile
} }
if logLevel != nil && *logLevel != "" {
args.Level = *logLevel
}
} }
func main() { func main() {

View File

@ -96,6 +96,8 @@ func Exec(ctx context.Context, args Args) error {
if err != nil { if err != nil {
return fmt.Errorf("error getting git tag %w", err) return fmt.Errorf("error getting git tag %w", err)
} }
log.WithField("tag", tag).Info("Fetched latest git tag")
} else if args.TagFile != "" { } else if args.TagFile != "" {
log.WithField("file", args.TagFile).Info("Reading tag from file") log.WithField("file", args.TagFile).Info("Reading tag from file")

View File

@ -9,7 +9,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -17,6 +16,7 @@ import (
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport/client" "github.com/go-git/go-git/v5/plumbing/transport/client"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http" githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
log "github.com/sirupsen/logrus"
) )
type GetLatestGitTagOption func(repo *git.Repository) error type GetLatestGitTagOption func(repo *git.Repository) error
@ -50,7 +50,7 @@ func SetBasicAuth(username, password string) func(repo *git.Repository) error {
func FetchTags() func(repo *git.Repository) error { func FetchTags() func(repo *git.Repository) error {
return func(repo *git.Repository) error { return func(repo *git.Repository) error {
log.Println("Fetching latest git tags") log.Info("Fetching latest git tags")
err := repo.Fetch(&git.FetchOptions{Tags: git.AllTags}) err := repo.Fetch(&git.FetchOptions{Tags: git.AllTags})
@ -82,18 +82,24 @@ func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) {
return "", fmt.Errorf("error getting git tag refs %w", err) return "", fmt.Errorf("error getting git tag refs %w", err)
} }
ref, err := tagRefs.Next() for {
r, err := tagRefs.Next()
if err == io.EOF { if err == io.EOF {
return tag, fmt.Errorf("couldn't find any git tags %w", err) break
} }
if err != nil { if err != nil {
return tag, fmt.Errorf("error iterating tags %w", err) return "", fmt.Errorf("error iterating tags %w", err)
} }
parts := strings.Split(string(ref.Name()), "/") parts := strings.Split(string(r.Name()), "/")
tag = strings.Join(parts[2:], "/") tag = strings.Join(parts[2:], "/")
}
if tag == "" {
return tag, fmt.Errorf("couldn't find any git tags")
}
return return
} }