Skip to content

Commit

Permalink
Merge pull request #60 from Songmu/releaseyml
Browse files Browse the repository at this point in the history
add .github/release.yml automatically when it doesn't exist
  • Loading branch information
Songmu authored Aug 27, 2022
2 parents 973836c + 9e5e9e1 commit fb10498
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 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
23 changes: 21 additions & 2 deletions 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 @@ -123,13 +124,15 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
return printVersion(outStream)
}

// main logic follows
rp, err := newRcpr(ctx, &commander{
gitPath: "git", outStream: outStream, errStream: errStream, dir: "."})
if err != nil {
return err
}
return rp.Run(ctx)
}

func (rp *rcpr) Run(ctx context.Context) error {
latestSemverTag := rp.latestSemverTag()
currVerStr := latestSemverTag
if currVerStr == "" {
Expand Down Expand Up @@ -224,14 +227,30 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
} 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 fb10498

Please sign in to comment.