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

apply the commits added on the RC branch with cherry-pick #9

Merged
merged 1 commit into from
Aug 15, 2022
Merged
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
36 changes: 33 additions & 3 deletions rcpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const (
autoCommitMessage = "[rcpr] prepare for the next release"
)

var remoteReg = regexp.MustCompile(`origin\s.*?github\.com[:/]([-a-zA-Z0-9]+)/(\S+)`)

type rcpr struct {
}

Expand All @@ -35,6 +33,11 @@ func (rp *rcpr) latestSemverTag() string {
return ""
}

var (
gitlogReg = regexp.MustCompile(`^([a-f0-9]+) (.*?)\r?`)
remoteReg = regexp.MustCompile(`origin\s.*?github\.com[:/]([-a-zA-Z0-9]+)/(\S+)`)
)

// Run the rcpr
func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) error {
log.SetOutput(errStream)
Expand Down Expand Up @@ -80,7 +83,34 @@ func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) err
// XXX do some releng related changes before commit
c.git("commit", "--allow-empty", "-am", autoCommitMessage)

// TODO: If remote rc branches are advanced, apply them with cherry-pick, etc.
// cherry-pick if the remote branch is exists and changed
out, _, err := git("log", "--pretty=format:%h %an %s", "main...origin/"+rcBranch)
if err == nil {
var cherryPicks []string
for _, line := range strings.Split(out, "\n") {
m := gitlogReg.FindStringSubmatch(line)
if len(m) < 3 {
continue
}
commitish := m[1]
authorAndSubject := m[2]
if authorAndSubject != gitUser+" "+autoCommitMessage {
cherryPicks = append(cherryPicks, commitish)
}
}
if len(cherryPicks) > 0 {
for i := len(cherryPicks) - 1; i >= 0; i-- {
commitish := cherryPicks[i]
_, _, err := git(
"cherry-pick", "--keep-redundant-commits", "--allow-empty", commitish)

// conflict / Need error handling in case of non-conflict error?
if err != nil {
git("reset", "--hard", "ORIG_HEAD")
}
}
}
}

c.git("push", "--force", "origin", rcBranch)
if c.err != nil {
Expand Down