-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
102 lines (84 loc) · 2.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"git-release/release"
"time"
"github.com/pkg/errors"
"github.com/spf13/afero"
"os"
log "github.com/sirupsen/logrus"
)
// Version contains current application version
const Version string = "6.0.0"
func init() {
log.SetReportCaller(false)
log.SetFormatter(&log.TextFormatter{
ForceColors: true,
FullTimestamp: true,
DisableLevelTruncation: true,
DisableTimestamp: true,
})
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel)
log.Debugf("git-release v%v ", Version)
l := []string{
"GITHUB_REPOSITORY",
"GITHUB_TOKEN",
"GITHUB_WORKSPACE",
"GITHUB_API_URL",
"GITHUB_SERVER_URL",
"GITHUB_REF",
"GITHUB_SHA",
}
for _, v := range l {
if os.Getenv(v) == "" {
log.Fatalf("%v is not defined", v)
}
}
}
func main() {
fs := afero.NewOsFs()
conf, err := GetConfig(fs)
if err != nil {
log.Fatal(errors.Wrap(err, "error fetching configuration"))
}
rel, err := release.GetRelease(
fs,
os.Args[1:],
conf.TagPrefix,
conf.ReleaseName,
conf.ReleaseNamePrefix,
conf.ReleaseNameSuffix,
conf.UnreleasedCreate || conf.UnreleasedDelete,
)
if err != nil {
log.Fatal(errors.Wrap(err, "error fetching release configuration"))
}
if conf.ChangelogFile != "" {
rel.Changelog, err = conf.GetChangelog(fs, rel)
if err != nil {
log.Fatal(errors.Wrap(err, "error reading changelog"))
}
}
cli, err := Login(os.Getenv("GITHUB_TOKEN"))
if err != nil {
log.Fatal(errors.Wrap(err, "login error"))
}
if conf.UnreleasedCreate || conf.UnreleasedDelete {
log.Warnf("deleting precedent release ❗")
err := rel.DeleteUnreleased(cli.Repositories, cli.Git)
if err != nil {
log.Fatal(errors.Wrap(err, "error preparing for Unreleased release update"))
}
if conf.UnreleasedDelete {
return
}
if err := rel.UpdateUnreleasedTag(cli.Git); err != nil {
log.Fatal(errors.Wrapf(err, "error creating %v tag", rel.Reference.Tag))
}
time.Sleep(3 * time.Second)
}
log.Infof("creating %v release", rel.Name)
if err := rel.Publish(cli.Repositories); err != nil {
log.Fatal(err)
}
}