Compare commits

..

16 Commits
0.9.0 ... main

Author SHA1 Message Date
964ea60e55 chore: bump 0.12.0 → 0.13.0 [CI SKIP]
All checks were successful
continuous-integration/drone/tag Build is passing
2024-10-25 16:16:43 +00:00
2386e278c7 Merge branch 'main' of https://gitea.dikurium.ch/InnoPeak/drone-gitea-release into main
Some checks failed
continuous-integration/drone/push Build is failing
2024-10-25 18:16:24 +02:00
66de41874d feat: use time.Time.Before() instead of Sub() 2024-10-25 18:16:24 +02:00
9aace7aa2b chore: bump 0.11.1 → 0.12.0 [CI SKIP]
All checks were successful
continuous-integration/drone/tag Build is passing
2024-10-25 16:14:51 +00:00
6c787535a8 feat: use tagger.when to find latest tag
Some checks failed
continuous-integration/drone/push Build is failing
2024-10-25 18:14:25 +02:00
e65c52c67c chore: bump 0.11.0 → 0.11.1 [CI SKIP]
All checks were successful
continuous-integration/drone/tag Build is passing
2024-07-11 17:54:57 +02:00
d19022dad8 fix: 🐛 append newline after success message, use logger [CI SKIP] 2024-07-11 17:54:33 +02:00
2daf8b0d53 chore: bump 0.10.1 → 0.11.0 [CI SKIP]
All checks were successful
continuous-integration/drone/tag Build is passing
2024-07-11 15:34:11 +00:00
d9f25a2613 Merge branch 'main' of https://gitea.dikurium.ch/InnoPeak/drone-gitea-release into main
Some checks failed
continuous-integration/drone/push Build is failing
2024-07-11 17:33:48 +02:00
b2c43a5f3d feat: use log.textformatter 2024-07-11 17:33:47 +02:00
1c9f839870 chore: bump 0.10.0 → 0.10.1 [CI SKIP]
All checks were successful
continuous-integration/drone/tag Build is passing
2024-07-11 15:26:02 +00:00
76e800c9d4 Merge branch 'main' of https://gitea.dikurium.ch/InnoPeak/drone-gitea-release into main
Some checks failed
continuous-integration/drone/push Build is failing
2024-07-11 17:25:35 +02:00
fe6812860e fix: revert: fix: 🐛 use latest instead of last (oldest) tag
- Add logs
2024-07-11 17:25:35 +02:00
8ff9355fcf chore: bump 0.9.0 → 0.10.0 [CI SKIP]
All checks were successful
continuous-integration/drone/tag Build is passing
2024-07-11 15:09:55 +00:00
913e80c62b Merge branch 'main' of https://gitea.dikurium.ch/InnoPeak/drone-gitea-release into main
Some checks failed
continuous-integration/drone/push Build is failing
2024-07-11 17:09:36 +02:00
cecbbddd07 feat: 🔊 add logs 2024-07-11 17:09:36 +02:00
5 changed files with 100 additions and 39 deletions

View File

@ -1,3 +1,39 @@
## 0.13.0 (2024-10-25)
### Feat
- :sparkles: use time.Time.Before() instead of Sub()
## 0.12.0 (2024-10-25)
### Feat
- :sparkles: use tagger.when to find latest tag
## 0.11.1 (2024-07-11)
### Fix
- :bug: append newline after success message, use logger [CI SKIP]
## 0.11.0 (2024-07-11)
### Feat
- :sparkles: use log.textformatter
## 0.10.1 (2024-07-11)
### Fix
- revert: :rewind: fix: 🐛 use latest instead of last (oldest) tag - Add logs
## 0.10.0 (2024-07-11)
### Feat
- :loud_sound: add logs
## 0.9.0 (2024-07-11) ## 0.9.0 (2024-07-11)
### Feat ### Feat

View File

@ -5,5 +5,5 @@ commitizen:
name: cz_conventional_commits name: cz_conventional_commits
tag_format: $version tag_format: $version
update_changelog_on_bump: true update_changelog_on_bump: true
version: 0.9.0 version: 0.13.0
version_scheme: semver version_scheme: semver

34
main.go
View File

@ -6,7 +6,7 @@ import (
"gitea.dikurium.ch/InnoPeak/drone-gitea-release/plugin" "gitea.dikurium.ch/InnoPeak/drone-gitea-release/plugin"
"github.com/kelseyhightower/envconfig" "github.com/kelseyhightower/envconfig"
"github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
) )
@ -15,7 +15,7 @@ var args plugin.Args
func init() { func init() {
if err := envconfig.Process("", &args); err != nil { if err := envconfig.Process("", &args); err != nil {
logrus.Fatalln(err) log.Fatalln(err)
} }
var ( var (
@ -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,34 +48,25 @@ 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() {
logrus.SetFormatter(new(formatter)) log.SetFormatter(&log.TextFormatter{
DisableTimestamp: true,
})
switch args.Level { switch args.Level {
case "debug": case "debug":
logrus.SetFormatter(textFormatter) log.SetLevel(log.DebugLevel)
logrus.SetLevel(logrus.DebugLevel)
case "trace": case "trace":
logrus.SetFormatter(textFormatter) log.SetLevel(log.TraceLevel)
logrus.SetLevel(logrus.TraceLevel)
} }
if err := plugin.Exec(context.Background(), args); err != nil { if err := plugin.Exec(context.Background(), args); err != nil {
logrus.Fatalln(err) log.Fatalln(err)
} }
} }
// default formatter that writes logs without including timestamp
// or level information.
type formatter struct{}
func (*formatter) Format(entry *logrus.Entry) ([]byte, error) {
return []byte(entry.Message), nil
}
// text formatter that writes logs with level information
var textFormatter = &logrus.TextFormatter{
DisableTimestamp: true,
}

View File

@ -9,6 +9,7 @@ import (
"text/template" "text/template"
"code.gitea.io/sdk/gitea" "code.gitea.io/sdk/gitea"
log "github.com/sirupsen/logrus"
) )
var ( var (
@ -71,7 +72,7 @@ func Exec(ctx context.Context, args Args) error {
if err != nil { if err != nil {
if os.IsNotExist(err) && args.SkipIfNoNotesFile { if os.IsNotExist(err) && args.SkipIfNoNotesFile {
fmt.Println("No notes file found, skipping release") log.Info("No notes file found, skipping release")
return nil return nil
} }
return fmt.Errorf("error reading notes file %w", err) return fmt.Errorf("error reading notes file %w", err)
@ -95,7 +96,11 @@ 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")
var pattern = defaultTagRegex var pattern = defaultTagRegex
if args.TagRegex != "" { if args.TagRegex != "" {
pattern = regexp.MustCompile(args.TagRegex) pattern = regexp.MustCompile(args.TagRegex)
@ -118,6 +123,8 @@ func Exec(ctx context.Context, args Args) error {
tag = matches[i] tag = matches[i]
} }
} }
log.WithField("tag", tag).Info("Found tag")
} else { } else {
return fmt.Errorf("latest git tag or tag file must be given") return fmt.Errorf("latest git tag or tag file must be given")
} }
@ -142,6 +149,11 @@ func Exec(ctx context.Context, args Args) error {
title = titleBuffer.String() title = titleBuffer.String()
log.WithFields(log.Fields{
"template": titleTmpl.DefinedTemplates(),
"title": title,
}).Info("Generated title with template")
client, err := gitea.NewClient(args.GiteaUrl, gitea.SetBasicAuth(args.GiteaUsername, args.GiteaPassword)) client, err := gitea.NewClient(args.GiteaUrl, gitea.SetBasicAuth(args.GiteaUsername, args.GiteaPassword))
if err != nil { if err != nil {
@ -160,7 +172,7 @@ func Exec(ctx context.Context, args Args) error {
} }
releaseURL := fmt.Sprintf("%s/%s/%s/releases/tag/%s", args.GiteaUrl, args.Owner, args.Repo, release.TagName) releaseURL := fmt.Sprintf("%s/%s/%s/releases/tag/%s", args.GiteaUrl, args.Owner, args.Repo, release.TagName)
fmt.Printf("Successfully created release at %s", releaseURL) log.WithField("url", releaseURL).Info("Successfully created release")
writeCard( writeCard(
args.Pipeline.Card.Path, args.Pipeline.Card.Path,

View File

@ -11,11 +11,12 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"strings" "time"
"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
@ -34,6 +35,8 @@ func (bat BasicAuthTransport) RoundTrip(req *http.Request) (resp *http.Response,
func SetBasicAuth(username, password string) func(repo *git.Repository) error { func SetBasicAuth(username, password string) func(repo *git.Repository) error {
return func(repo *git.Repository) error { return func(repo *git.Repository) error {
log.Println("Configuring basic auth for https")
customClient := &http.Client{ customClient := &http.Client{
Transport: BasicAuthTransport{username, password, http.DefaultTransport}, Transport: BasicAuthTransport{username, password, http.DefaultTransport},
} }
@ -47,6 +50,8 @@ 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.Info("Fetching git tags")
err := repo.Fetch(&git.FetchOptions{Tags: git.AllTags}) err := repo.Fetch(&git.FetchOptions{Tags: git.AllTags})
if err == git.NoErrAlreadyUpToDate { if err == git.NoErrAlreadyUpToDate {
@ -57,40 +62,56 @@ func FetchTags() func(repo *git.Repository) error {
} }
} }
func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) { func getLatestGitTag(options ...GetLatestGitTagOption) (string, error) {
r, err := git.PlainOpen(".") var (
tag string
tagDate *time.Time
err error
)
repo, err := git.PlainOpen(".")
if err != nil { if err != nil {
return "", fmt.Errorf("error opening git repo at %s: %w", ".", err) return "", fmt.Errorf("error opening git repo at %s: %w", ".", err)
} }
for _, opt := range options { for _, opt := range options {
err := opt(r) err := opt(repo)
if err != nil { if err != nil {
return "", err return "", err
} }
} }
tagRefs, err := r.Tags() tags, err := repo.TagObjects()
if err != nil { if err != nil {
return "", fmt.Errorf("error getting git tag refs %w", err) return "", fmt.Errorf("error getting git tags %w", err)
} }
ref, err := tagRefs.Next() for {
t, err := tags.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()), "/") if tagDate != nil && t.Tagger.When.Before(*tagDate) {
tag = strings.Join(parts[2:], "/") continue
}
return tagDate = &t.Tagger.When
tag = t.Name
}
if tag == "" {
return tag, fmt.Errorf("couldn't find any git tags")
}
return tag, err
} }
func writeCard(path, schema string, card interface{}) { func writeCard(path, schema string, card interface{}) {