releaser: Add --try flag to ease testing

This commit is contained in:
Bjørn Erik Pedersen
2017-07-05 09:43:47 +02:00
parent aa6b1b9be7
commit e7a54e7afc
4 changed files with 98 additions and 48 deletions

View File

@@ -193,29 +193,49 @@ func getReleaseNotesDocsTempFilename(version string) string {
return filepath.Join(getReleaseNotesDocsTempDirAndName(version))
}
func writeReleaseNotesToTemp(version string, infos gitInfos) (string, error) {
func (r *ReleaseHandler) writeReleaseNotesToTemp(version string, infos gitInfos) (string, error) {
docsTempPath, name := getReleaseNotesDocsTempDirAndName(version)
os.Mkdir(docsTempPath, os.ModePerm)
f, err := os.Create(filepath.Join(docsTempPath, name))
if err != nil {
var (
w io.WriteCloser
)
if !r.try {
os.Mkdir(docsTempPath, os.ModePerm)
f, err := os.Create(filepath.Join(docsTempPath, name))
if err != nil {
return "", err
}
name = f.Name()
defer f.Close()
w = f
} else {
w = os.Stdout
}
if err := writeReleaseNotes(version, infos, w); err != nil {
return "", err
}
defer f.Close()
if err := writeReleaseNotes(version, infos, f); err != nil {
return "", err
}
return f.Name(), nil
return name, nil
}
func writeReleaseNotesToDocs(title, sourceFilename string) (string, error) {
func (r *ReleaseHandler) writeReleaseNotesToDocs(title, sourceFilename string) (string, error) {
targetFilename := filepath.Base(sourceFilename)
contentDir := hugoFilepath("docs/content/release-notes")
targetFullFilename := filepath.Join(contentDir, targetFilename)
if r.try {
return targetFullFilename, nil
}
os.Mkdir(contentDir, os.ModePerm)
b, err := ioutil.ReadFile(sourceFilename)