Skip to content

Commit

Permalink
add .github/release.yml automatically when it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Aug 27, 2022
1 parent 67d608f commit 9e5e9e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
6 changes: 0 additions & 6 deletions changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"fmt"
"os"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion rcpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -226,14 +227,30 @@ 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
}
}
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)

Expand Down
8 changes: 8 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package rcpr

import "os"

func exists(filename string) bool {
_, err := os.Stat(filename)
return err == nil
}

0 comments on commit 9e5e9e1

Please sign in to comment.