feat: 🔊 add logs
This commit is contained in:
parent
3f0e9dd908
commit
cecbbddd07
20
main.go
20
main.go
@ -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 (
|
||||||
@ -50,19 +50,19 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logrus.SetFormatter(new(formatter))
|
log.SetFormatter(new(formatter))
|
||||||
|
|
||||||
switch args.Level {
|
switch args.Level {
|
||||||
case "debug":
|
case "debug":
|
||||||
logrus.SetFormatter(textFormatter)
|
log.SetFormatter(textFormatter)
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
case "trace":
|
case "trace":
|
||||||
logrus.SetFormatter(textFormatter)
|
log.SetFormatter(textFormatter)
|
||||||
logrus.SetLevel(logrus.TraceLevel)
|
log.SetLevel(log.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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,11 +70,11 @@ func main() {
|
|||||||
// or level information.
|
// or level information.
|
||||||
type formatter struct{}
|
type formatter struct{}
|
||||||
|
|
||||||
func (*formatter) Format(entry *logrus.Entry) ([]byte, error) {
|
func (*formatter) Format(entry *log.Entry) ([]byte, error) {
|
||||||
return []byte(entry.Message), nil
|
return []byte(entry.Message), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// text formatter that writes logs with level information
|
// text formatter that writes logs with level information
|
||||||
var textFormatter = &logrus.TextFormatter{
|
var textFormatter = &log.TextFormatter{
|
||||||
DisableTimestamp: true,
|
DisableTimestamp: true,
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
@ -96,6 +97,8 @@ func Exec(ctx context.Context, args Args) error {
|
|||||||
return fmt.Errorf("error getting git tag %w", err)
|
return fmt.Errorf("error getting git tag %w", err)
|
||||||
}
|
}
|
||||||
} 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 +121,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 +147,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 {
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -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.Println("Fetching latest 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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user