scripts/release: Check changelog subdir with date

This commit is contained in:
Alexander Neumann 2018-02-16 23:13:02 +01:00
parent 84dcc3c396
commit b723094739

View file

@ -13,7 +13,6 @@ import (
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"time"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -24,8 +23,9 @@ var opts = struct {
IgnoreBranchName bool IgnoreBranchName bool
IgnoreUncommittedChanges bool IgnoreUncommittedChanges bool
IgnoreChangelogVersion bool IgnoreChangelogVersion bool
IgnoreChangelogRelease bool IgnoreChangelogReleaseDate bool
IgnoreChangelogCurrent bool IgnoreChangelogCurrent bool
IgnoreDockerBuildGoVersion bool
tarFilename string tarFilename string
buildDir string buildDir string
@ -37,8 +37,9 @@ func init() {
pflag.BoolVar(&opts.IgnoreBranchName, "ignore-branch-name", false, "allow releasing from other branches as 'master'") pflag.BoolVar(&opts.IgnoreBranchName, "ignore-branch-name", false, "allow releasing from other branches as 'master'")
pflag.BoolVar(&opts.IgnoreUncommittedChanges, "ignore-uncommitted-changes", false, "allow uncommitted changes") pflag.BoolVar(&opts.IgnoreUncommittedChanges, "ignore-uncommitted-changes", false, "allow uncommitted changes")
pflag.BoolVar(&opts.IgnoreChangelogVersion, "ignore-changelog-version", false, "ignore missing entry in CHANGELOG.md") pflag.BoolVar(&opts.IgnoreChangelogVersion, "ignore-changelog-version", false, "ignore missing entry in CHANGELOG.md")
pflag.BoolVar(&opts.IgnoreChangelogRelease, "ignore-changelog-releases", false, "ignore missing entry changelog/releases") pflag.BoolVar(&opts.IgnoreChangelogReleaseDate, "ignore-changelog-release-date", false, "ignore missing subdir with date in changelog/")
pflag.BoolVar(&opts.IgnoreChangelogCurrent, "ignore-changelog-current", false, "ignore check if CHANGELOG.md is up to date") pflag.BoolVar(&opts.IgnoreChangelogCurrent, "ignore-changelog-current", false, "ignore check if CHANGELOG.md is up to date")
pflag.BoolVar(&opts.IgnoreDockerBuildGoVersion, "ignore-docker-build-go-version", false, "ignore check if docker builder go version is up to date")
pflag.Parse() pflag.Parse()
} }
@ -172,32 +173,33 @@ func preCheckChangelogCurrent() {
} }
func preCheckChangelogRelease() { func preCheckChangelogRelease() {
if opts.IgnoreChangelogRelease { if opts.IgnoreChangelogReleaseDate {
return return
} }
f, err := os.Open(filepath.FromSlash("changelog/releases")) d, err := os.Open("changelog")
if err != nil { if err != nil {
die("unable to open releases file in changelog/: %v", err) die("error opening dir: %v", err)
} }
sc := bufio.NewScanner(f) names, err := d.Readdirnames(-1)
for sc.Scan() { if err != nil {
if sc.Err() != nil { _ = d.Close()
die("error reading releases file in changelog: %v", err) die("error listing dir: %v", err)
} }
if sc.Text() == fmt.Sprintf("%v %v", opts.Version, time.Now().Format("2006-01-02")) { err = d.Close()
if err != nil {
die("error closing dir: %v", err)
}
for _, name := range names {
if strings.HasPrefix(name, opts.Version+"_") {
return return
} }
} }
err = f.Close() die("unable to find subdir with date for version %v in changelog", opts.Version)
if err != nil {
die("close releases error: %v", err)
}
die("unable to find correct line for version %v (released today) in changelog/releases", opts.Version)
} }
func preCheckChangelogVersion() { func preCheckChangelogVersion() {
@ -226,6 +228,10 @@ func preCheckChangelogVersion() {
} }
func preCheckDockerBuilderGoVersion() { func preCheckDockerBuilderGoVersion() {
if opts.IgnoreDockerBuildGoVersion {
return
}
buf, err := exec.Command("go", "version").Output() buf, err := exec.Command("go", "version").Output()
if err != nil { if err != nil {
die("unable to check local Go version: %v", err) die("unable to check local Go version: %v", err)