From 9e5e9e1cebcb8ef8b839cc55d1f6d16790d7bc94 Mon Sep 17 00:00:00 2001 From: Songmu Date: Sat, 27 Aug 2022 20:47:12 +0900 Subject: [PATCH] add .github/release.yml automatically when it doesn't exist --- changelog.go | 6 ------ rcpr.go | 19 ++++++++++++++++++- util.go | 8 ++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 util.go diff --git a/changelog.go b/changelog.go index 1823027..00b6d19 100644 --- a/changelog.go +++ b/changelog.go @@ -4,7 +4,6 @@ import ( "bufio" "bytes" "fmt" - "os" "regexp" "strings" "time" @@ -38,11 +37,6 @@ func convertKeepAChangelogFormat(md string, d time.Time) string { return strings.TrimSpace(md) + "\n" } -func exists(filename string) bool { - _, err := os.Stat(filename) - return err == nil -} - var changelogReg = regexp.MustCompile(`(?i)^# Change\s?log`) func insertNewChangelog(orig string, section string) string { diff --git a/rcpr.go b/rcpr.go index bc67896..75872e8 100644 --- a/rcpr.go +++ b/rcpr.go @@ -9,6 +9,7 @@ import ( "log" "net/url" "os" + "path/filepath" "regexp" "strings" "time" @@ -226,6 +227,8 @@ func (rp *rcpr) Run(ctx context.Context) error { } else { vfile = rp.cfg.versionFile.String() } + // TODO To be able to run some kind of change script set by configuration in advance. + if vfile != "" { if err := bumpVersionFile(vfile, currVer, nextVer); err != nil { return err @@ -233,7 +236,21 @@ func (rp *rcpr) Run(ctx context.Context) error { } rp.c.GitE("add", "-f", rp.cfg.conf) // ignore any errors - // TODO To be able to run some kind of change script set by configuration in advance. + const releaseYml = ".github/release.yml" + // TODO: It would be nice to be able to add an exclude setting even if release.yml already exists. + if !exists(releaseYml) { + if err := os.MkdirAll(filepath.Dir(releaseYml), 0755); err != nil { + return err + } + if err := os.WriteFile(releaseYml, []byte(`changelog: + exclude: + labels: + - rcpr +`), 0644); err != nil { + return err + } + rp.c.GitE("add", "-f", releaseYml) + } rp.c.Git("commit", "--allow-empty", "-am", autoCommitMessage) diff --git a/util.go b/util.go new file mode 100644 index 0000000..a2f519d --- /dev/null +++ b/util.go @@ -0,0 +1,8 @@ +package rcpr + +import "os" + +func exists(filename string) bool { + _, err := os.Stat(filename) + return err == nil +}