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