drone-gitea-release/main.go
RaviAnand Mohabir 2c8cdd7fcc
Some checks failed
continuous-integration/drone/push Build is failing
fix: 🐛 only parse flags if available
2024-06-25 14:39:56 +02:00

81 lines
1.8 KiB
Go

package main
import (
"context"
"gitea.dikurium.ch/InnoPeak/drone-gitea-release/plugin"
"github.com/kelseyhightower/envconfig"
"github.com/sirupsen/logrus"
flag "github.com/spf13/pflag"
)
var args plugin.Args
func init() {
if err := envconfig.Process("", &args); err != nil {
logrus.Fatalln(err)
}
var (
titleFormat *string = flag.String("title-format", "", "Format to use for the release title")
tagFile *string = flag.String("tag-file", "", "File to check for tag to release")
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")
notesFile *string = flag.String("notes-file", "", "File to use for release notes")
)
flag.Parse()
if titleFormat != nil && *titleFormat != "" {
args.TitleFormat = *titleFormat
}
if tagFile != nil && *tagFile != "" {
args.TagFile = *tagFile
}
if tagRegex != nil && *tagRegex != "" {
args.TagRegex = *tagRegex
}
if notes != nil && *notes != "" {
args.Notes = *notes
}
if notesFile != nil && *notesFile != "" {
args.NotesFile = *notesFile
}
}
func main() {
logrus.SetFormatter(new(formatter))
switch args.Level {
case "debug":
logrus.SetFormatter(textFormatter)
logrus.SetLevel(logrus.DebugLevel)
case "trace":
logrus.SetFormatter(textFormatter)
logrus.SetLevel(logrus.TraceLevel)
}
if err := plugin.Exec(context.Background(), args); err != nil {
logrus.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,
}