Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add .github/release.yml automatically when it doesn't exist #60

Merged
merged 2 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}