forked from containerd/containerd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
143 lines (127 loc) · 3.4 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"fmt"
"os"
"text/template"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
const vendorConf = "vendor.conf"
type note struct {
Title string `toml:"title"`
Description string `toml:"description"`
}
type change struct {
Commit string `toml:"commit"`
Description string `toml:"description"`
}
type dependency struct {
Name string
Commit string
Previous string
}
type download struct {
Filename string
Hash string
}
type release struct {
ProjectName string `toml:"project_name"`
GithubRepo string `toml:"github_repo"`
Commit string `toml:"commit"`
Previous string `toml:"previous"`
PreRelease bool `toml:"pre_release"`
Preface string `toml:"preface"`
Notes map[string]note `toml:"notes"`
BreakingChanges map[string]change `toml:"breaking"`
// generated fields
Changes []change
Contributors []string
Dependencies []dependency
Version string
Downloads []download
}
func main() {
app := cli.NewApp()
app.Name = "release"
app.Description = `release tooling.
This tool should be ran from the root of the project repository for a new release.
`
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "dry,n",
Usage: "run the release tooling as a dry run to print the release notes to stdout",
},
cli.StringFlag{
Name: "template,t",
Usage: "template filepath to use in place of the default",
Value: defaultTemplateFile,
},
}
app.Action = func(context *cli.Context) error {
var (
path = context.Args().First()
tag = parseTag(path)
)
r, err := loadRelease(path)
if err != nil {
return err
}
logrus.Info("Welcome to the %s release tool...", r.ProjectName)
previous, err := getPreviousDeps(r.Previous)
if err != nil {
return err
}
changes, err := changelog(r.Previous, r.Commit)
if err != nil {
return err
}
logrus.Infof("creating new release %s with %d new changes...", tag, len(changes))
rd, err := fileFromRev(r.Commit, vendorConf)
if err != nil {
return err
}
deps, err := parseDependencies(rd)
if err != nil {
return err
}
updatedDeps := updatedDeps(previous, deps)
contributors, err := getContributors(r.Previous, r.Commit)
if err != nil {
return err
}
// update the release fields with generated data
r.Contributors = contributors
r.Dependencies = updatedDeps
r.Changes = changes
r.Version = tag
tmpl, err := getTemplate(context)
if err != nil {
return err
}
if context.Bool("dry") {
t, err := template.New("release-notes").Parse(tmpl)
if err != nil {
return err
}
return t.Execute(os.Stdout, r)
}
logrus.Info("release complete!")
return nil
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}