Skip to content

Commit

Permalink
Merge pull request #30 from Songmu/adjustment
Browse files Browse the repository at this point in the history
create a normal release instead of a draft when tagging
  • Loading branch information
Songmu authored Aug 17, 2022
2 parents 4c509d0 + d03c551 commit 99cf8d1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 45 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
- name: upload
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: dist/*
draft: false
7 changes: 0 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- "**"
pull_request: {}
jobs:
test:
runs-on: ${{ matrix.os }}
Expand All @@ -13,17 +12,11 @@ jobs:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
steps:
- name: setup go
uses: actions/setup-go@v3
with:
go-version: 1.x
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
if: "matrix.os == 'windows-latest'"
- name: checkout
uses: actions/checkout@v3
- name: test
Expand Down
10 changes: 3 additions & 7 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ func ghClient(ctx context.Context, token, host string) (*github.Client, error) {
oauthClient := oauth2.NewClient(ctx, ts)
client := github.NewClient(oauthClient)

if host != "" {
if host == "github.com" {
host = "https://api.github.com/"
} else {
// ref. https://github.com/google/go-github/issues/958
host = fmt.Sprintf("https://%s/api/v3/", host)
}
if host != "" && host != "github.com" {
// ref. https://github.com/google/go-github/issues/958
host = fmt.Sprintf("https://%s/api/v3/", host)
u, err := url.Parse(host)
if err != nil {
return nil, err
Expand Down
65 changes: 37 additions & 28 deletions rcpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
releaseBranch, branch)
}

// XXX: should care GIT_*_NAME etc?
if _, _, err := rp.c.gitE("config", "user.email"); err != nil {
rp.c.git("config", "--local", "user.email", gitEmail)
}
Expand All @@ -168,7 +169,7 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
}
if len(pulls) > 0 && isRcpr(pulls[0]) {
rp.c.git("checkout", "HEAD~")
vfile, err := detectVersionFile(".", currVer.Naked())
vfile, err := detectVersionFile(".", currVer)
if err != nil {
return err
}
Expand All @@ -189,7 +190,9 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
previousTag = nil
}

// Pick up the previous commit to avoid picking up the merge of the pull
// To avoid putting pull requests created by rcpr itself in the release notes,
// we generate release notes in advance.
// Get the previous commitish to avoid picking up the merge of the pull
// request made by rcpr.
targetCommitish, _, err := rp.c.gitE("rev-parse", "HEAD~")
if err != nil {
Expand All @@ -213,14 +216,19 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
if err != nil {
return err
}
draft := true

// Don't use GenerateReleaseNote flag and use pre generated one
_, _, err = rp.gh.Repositories.CreateRelease(
ctx, rp.owner, rp.repo, &github.RepositoryRelease{
TagName: &nextTag,
TargetCommitish: &releaseBranch,
Name: &releases.Name,
Body: &releases.Body,
Draft: &draft,
// I want to make it as a draft release by default, but it is difficult to get a draft release
// from another tool via API, and there is no tool supports it, so I will make it as a normal
// release. In the future, there may be an option to create it as a Draft, or conversely,
// an option not to create a release.
// Draft: github.Bool(true),
})
return err
}
Expand All @@ -247,19 +255,23 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
nextVer := guessNextSemver(currVer, currRcpr)

// TODO: make configurable version file
vfile, err := detectVersionFile(".", currVer.Naked())
vfile, err := detectVersionFile(".", currVer)
if err != nil {
return err
}
if vfile != "" {
if err := bumpVersionFile(vfile, currVer.Naked(), nextVer.Naked()); err != nil {
if err := bumpVersionFile(vfile, currVer, nextVer); err != nil {
return err
}
}
// XXX do some releng related changes before commit

// TODO To be able to run some kind of change script set by configuration in advance.

rp.c.git("commit", "--allow-empty", "-am", autoCommitMessage)

// cherry-pick if the remote branch is exists and changed
// XXX: Do I need to apply merge commits too?
// (We ommited merge commits for now, because if we cherry-pick them, we need to add options like "-m 1".
out, _, err := rp.c.gitE(
"log", "--no-merges", "--pretty=format:%h %s", "main.."+rp.remoteName+"/"+rcBranch)
if err == nil {
Expand All @@ -276,12 +288,14 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
}
}
if len(cherryPicks) > 0 {
// Specify a commitish one by one for cherry-pick instead of multiple commitish,
// and apply it as much as possible.
for i := len(cherryPicks) - 1; i >= 0; i-- {
commitish := cherryPicks[i]
_, _, err := rp.c.gitE(
"cherry-pick", "--keep-redundant-commits", "--allow-empty", commitish)

// conflict / Need error handling in case of non-conflict error?
// conflict, etc. / Need error handling in case of non-conflict error?
if err != nil {
rp.c.gitE("cherry-pick", "--abort")
}
Expand Down Expand Up @@ -313,17 +327,14 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
}

// TODO: pull request template
pstr := func(str string) *string {
return &str
}
title := fmt.Sprintf("release %s", nextVer.Tag())

if currRcpr == nil {
pr, _, err := rp.gh.PullRequests.Create(ctx, rp.owner, rp.repo, &github.NewPullRequest{
Title: pstr(title),
Body: pstr(releases.Body),
Title: github.String(title),
Body: github.String(releases.Body),
Base: &releaseBranch,
Head: pstr(head),
Head: github.String(head),
})
if err != nil {
return err
Expand All @@ -332,8 +343,8 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
ctx, rp.owner, rp.repo, *pr.Number, []string{autoLableName})
return err
}
currRcpr.Title = pstr(title)
currRcpr.Body = pstr(mergeBody(*currRcpr.Body, releases.Body))
currRcpr.Title = github.String(title)
currRcpr.Body = github.String(mergeBody(*currRcpr.Body, releases.Body))
_, _, err = rp.gh.PullRequests.Edit(ctx, rp.owner, rp.repo, *currRcpr.Number, currRcpr)
return err
}
Expand Down Expand Up @@ -393,11 +404,8 @@ const versionRegBase = `(?i)((?:^|[^-_0-9a-zA-Z])version[^-_0-9a-zA-Z].*)`

var versionReg = regexp.MustCompile(versionRegBase + `([0-9]+\.[0-9]+\.[0-9]+)`)

func detectVersionFile(root, ver string) (string, error) {
if ver[0] == 'v' {
return "", fmt.Errorf("don't v-prefix: %s", ver)
}
verReg, err := regexp.Compile(versionRegBase + regexp.QuoteMeta(ver))
func detectVersionFile(root string, ver *semv) (string, error) {
verReg, err := regexp.Compile(versionRegBase + regexp.QuoteMeta(ver.Naked()))
if err != nil {
return "", err
}
Expand Down Expand Up @@ -436,7 +444,11 @@ func detectVersionFile(root, ver string) (string, error) {
if len(list) < 1 {
return "", nil
}
return list[0], nil // XXX
return list[0], nil
// XXX: Currently, version file detection methods are inaccurate; it might be better to limit it to
// gemspec, setup.py, setup.cfg, package.json, META.json, and so on. However, there may be cases
// where some projects have their own version files, and it is annoying to deal with various
// languages, etc. one by one, so this is the way to go. We would improve it.
}

type fileList struct {
Expand All @@ -456,11 +468,8 @@ func (fl *fileList) list() []string {
return fl.l
}

func bumpVersionFile(fpath, from, to string) error {
if from[0] == 'v' {
return fmt.Errorf("don't v-prefix: %s", from)
}
verReg, err := regexp.Compile(versionRegBase + regexp.QuoteMeta(from))
func bumpVersionFile(fpath string, from, to *semv) error {
verReg, err := regexp.Compile(versionRegBase + regexp.QuoteMeta(from.Naked()))
if err != nil {
return err
}
Expand All @@ -475,7 +484,7 @@ func bumpVersionFile(fpath, from, to string) error {
return match
}
replaced = true
return verReg.ReplaceAll(match, []byte(`${1}`+to))
return verReg.ReplaceAll(match, []byte(`${1}`+to.Naked()))
})
return os.WriteFile(fpath, updated, 0666)
}
Expand Down
3 changes: 2 additions & 1 deletion rcpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
)

func TestDetectVersionFile(t *testing.T) {
f, err := detectVersionFile(".", "0.0.0")
v, _ := newSemver("0.0.0")
f, err := detectVersionFile(".", v)
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit 99cf8d1

Please sign in to comment.