Add template filepath for release tool
This allows a project to have a TEMPLATE file in the root of the repo to be used with the release tool. If they don't have this file and did not specify a custom file then it will use the compiled in template in the release tool. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
5fb3a0e0cf
commit
adc502b790
@ -61,6 +61,11 @@ This tool should be ran from the root of the project repository for a new releas
|
||||
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 (
|
||||
@ -100,8 +105,13 @@ This tool should be ran from the root of the project repository for a new releas
|
||||
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(releaseNotes)
|
||||
t, err := template.New("release-notes").Parse(tmpl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
const releaseNotes = `Welcome to the release of {{.ProjectName}} {{.Version}}!
|
||||
const (
|
||||
defaultTemplateFile = "TEMPLATE"
|
||||
releaseNotes = `Welcome to the release of {{.ProjectName}} {{.Version}}!
|
||||
{{if .PreRelease}}
|
||||
*This is a pre-release of {{.ProjectName}}*
|
||||
{{- end}}
|
||||
@ -33,3 +35,4 @@ Previous release can be found at [{{.Previous}}](https://github.com/{{.GithubRep
|
||||
* {{$dep.Previous}} -> {{$dep.Commit}} **{{$dep.Name}}**
|
||||
{{- end}}
|
||||
`
|
||||
)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func loadRelease(path string) (*release, error) {
|
||||
@ -163,3 +165,23 @@ func getContributors(previous, commit string) ([]string, error) {
|
||||
sort.Strings(out)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// getTemplate will use a builtin template if the template is not specified on the cli
|
||||
func getTemplate(context *cli.Context) (string, error) {
|
||||
path := context.GlobalString("template")
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
// if the template file does not exist and the path is for the default template then
|
||||
// return the compiled in template
|
||||
if os.IsNotExist(err) && path == defaultTemplateFile {
|
||||
return releaseNotes, nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
data, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(data), nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user