drone-gitea-release/main.go

57 lines
1.4 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"
)
func main() {
logrus.SetFormatter(new(formatter))
var args plugin.Args
if err := envconfig.Process("", &args); err != nil {
logrus.Fatalln(err)
}
flag.StringVar(&args.TitleFormat, "title-format", "", "Format to use for the release title")
flag.StringVar(&args.TagFile, "tag-file", "", "File to check for tag to release")
flag.StringVar(&args.TagRegex, "tag-regex", "", "Regex pattern to look for tag in tag-file")
flag.StringVar(&args.Notes, "notes", "", "Notes to use in release")
flag.StringVar(&args.NotesFile, "notes-file", "", "File to use for release notes")
flag.Parse()
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,
}