Skip to content

Commit

Permalink
Merge pull request #44 from ipfs/fixes
Browse files Browse the repository at this point in the history
Fix patch release handling, general messaging and changelog entry discovery
  • Loading branch information
galargh authored Nov 10, 2024
2 parents 27467cb + ee04983 commit 01c0fe7
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 62 deletions.
20 changes: 10 additions & 10 deletions actions/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func CheckBranch(github *github.Client, owner, repo, branch string) error {
return err
}
if len(runs) > 0 {
return fmt.Errorf("check %s on https://github.com/%s/%s/tree/%s is not completed yet (%w)", runs[0].GetName(), owner, repo, branch, ErrInProgress)
return fmt.Errorf("⚠️ check %s on https://github.com/%s/%s/tree/%s is not completed yet (%w)", runs[0].GetName(), owner, repo, branch, ErrInProgress)
}

runs, err = github.GetUnsuccessfulCheckRuns(owner, repo, branch)
if err != nil {
return err
}
if len(runs) > 0 {
return fmt.Errorf("check %s on https://github.com/%s/%s/tree/%s is not successful (%w)", runs[0].GetName(), owner, repo, branch, ErrIncomplete)
return fmt.Errorf("⚠️ check %s on https://github.com/%s/%s/tree/%s is not successful (%w)", runs[0].GetName(), owner, repo, branch, ErrIncomplete)
}

return nil
Expand All @@ -45,12 +45,12 @@ func CheckPR(github *github.Client, owner, repo, head string, shouldBeMerged boo
return err
}
if pr == nil {
return fmt.Errorf("PR for https://github.com/%s/%s/tree/%s not found (%w)", owner, repo, head, ErrIncomplete)
return fmt.Errorf("⚠️ PR for https://github.com/%s/%s/tree/%s not found (%w)", owner, repo, head, ErrIncomplete)
}

if !pr.GetMerged() {
if pr.GetState() == "closed" {
return fmt.Errorf("%s is closed (%w)", pr.GetHTMLURL(), ErrIncomplete)
return fmt.Errorf("⚠️ %s is closed (%w)", pr.GetHTMLURL(), ErrIncomplete)
}

err = CheckBranch(github, owner, repo, head)
Expand All @@ -59,7 +59,7 @@ func CheckPR(github *github.Client, owner, repo, head string, shouldBeMerged boo
}

if shouldBeMerged {
return fmt.Errorf("%s is not merged (%w)", pr.GetHTMLURL(), ErrInProgress)
return fmt.Errorf("⚠️ %s is not merged (%w)", pr.GetHTMLURL(), ErrInProgress)
}
}

Expand All @@ -72,14 +72,14 @@ func CheckWorkflowRun(github *github.Client, owner, repo, branch, file, job, pat
return err
}
if run == nil {
return fmt.Errorf("workflow run %s for https://github.com/%s/%s/tree/%s not found (%w)", file, owner, repo, branch, ErrIncomplete)
return fmt.Errorf("⚠️ workflow run %s for https://github.com/%s/%s/tree/%s not found (%w)", file, owner, repo, branch, ErrIncomplete)
}

if run.GetStatus() != "completed" {
return fmt.Errorf("%s is not completed (%w)", run.GetHTMLURL(), ErrInProgress)
return fmt.Errorf("⚠️ %s is not completed (%w)", run.GetHTMLURL(), ErrInProgress)
}
if run.GetConclusion() != "success" {
return fmt.Errorf("%s did not succeed (%w)", run.GetHTMLURL(), ErrFailure)
return fmt.Errorf("⚠️ %s did not succeed (%w)", run.GetHTMLURL(), ErrFailure)
}

runLogs, err := github.GetWorkflowRunLogs(owner, repo, run.GetID())
Expand All @@ -89,7 +89,7 @@ func CheckWorkflowRun(github *github.Client, owner, repo, branch, file, job, pat

jobLogs := runLogs.JobLogs[job]
if jobLogs == nil {
return fmt.Errorf("%s does not have a %s job (%w)", run.GetHTMLURL(), job, ErrFailure)
return fmt.Errorf("⚠️ %s does not have a %s job (%w)", run.GetHTMLURL(), job, ErrFailure)
}

matched, err := regexp.MatchString(pattern, jobLogs.RawLogs)
Expand All @@ -98,7 +98,7 @@ func CheckWorkflowRun(github *github.Client, owner, repo, branch, file, job, pat
}

if !matched {
return fmt.Errorf("%s does not have the pattern %s (%w)", run.GetHTMLURL(), pattern, ErrIncomplete)
return fmt.Errorf("⚠️ %s does not have the pattern %s (%w)", run.GetHTMLURL(), pattern, ErrIncomplete)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion actions/merge_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (ctx MergeBranch) Run() error {
return err
}
if !util.ConfirmPR(pr) {
return fmt.Errorf("%s not merged", pr.GetHTMLURL())
return fmt.Errorf("🚨 %s not merged", pr.GetHTMLURL())
}

return nil
Expand Down
30 changes: 22 additions & 8 deletions actions/prepare_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"fmt"
"os"
"strconv"
"strings"

gh "github.com/google/go-github/v48/github"
Expand Down Expand Up @@ -186,7 +187,7 @@ func (ctx PrepareBranch) GetBody(branch, foreword string) (string, error) {
return "", err
}
if file == nil {
return "", fmt.Errorf("https://github.com/%s/%s/tree/%s/go.mod not found", repos.Kubo.Owner, repos.Kubo.Repo, branch)
return "", fmt.Errorf("🚨 https://github.com/%s/%s/tree/%s/go.mod not found", repos.Kubo.Owner, repos.Kubo.Repo, branch)
}

content, err := base64.StdEncoding.DecodeString(*file.Content)
Expand All @@ -204,7 +205,7 @@ func (ctx PrepareBranch) GetBody(branch, foreword string) (string, error) {
}
}
if boxoVersion == "" {
return "", fmt.Errorf("boxo version not found in https://github.com/%s/%s/tree/%s/go.mod", repos.Kubo.Owner, repos.Kubo.Repo, branch)
return "", fmt.Errorf("🚨 boxo version not found in https://github.com/%s/%s/tree/%s/go.mod", repos.Kubo.Owner, repos.Kubo.Repo, branch)
}

// find the boxo commit or tag in boxo version
Expand Down Expand Up @@ -254,7 +255,18 @@ func (ctx PrepareBranch) Run() error {
branch := repos.Kubo.VersionReleaseBranch(ctx.Version)
var source string
if ctx.Version.IsPatch() {
source = repos.Kubo.ReleaseBranch // TODO: this is not correct, we should use the previous patch release branch
// NOTE: For patch releases we want to create the new release branch from the previous release branch, e.g.
// when creating release-0.50.6, we want to create it from release-0.50.5
patchVersion, err := strconv.Atoi(ctx.Version.Patch())
if err != nil {
return err
}
previousVersionString := fmt.Sprintf("%s.%s", ctx.Version.MajorMinor(), strconv.Itoa(patchVersion-1))
previousVersion, err := util.NewVersion(previousVersionString)
if err != nil {
return err
}
source = repos.Kubo.VersionReleaseBranch(previousVersion)
} else {
source = repos.Kubo.DefaultBranch
}
Expand All @@ -264,6 +276,8 @@ func (ctx PrepareBranch) Run() error {
body := fmt.Sprintf("This PR creates release %s", ctx.Version.MajorMinorPatch())
draft := ctx.Version.IsPrerelease()

// NOTE: This should update const CurrentVersionNumber in version.go to the full version without a v prefix
// on the version release branch created from source
pr, err := ctx.UpdateVersion(branch, source, currentVersionNumber, base, title, body, draft)
if err != nil {
return err
Expand All @@ -280,7 +294,7 @@ func (ctx PrepareBranch) Run() error {
return err
}

fmt.Printf("Your release PR is ready at %s\n", pr.GetHTMLURL())
fmt.Printf("💁 Your release PR is ready at %s\n", pr.GetHTMLURL())

// TODO: check for conflicts and tell the user to resolve them
// or resolve them automatically with git merge origin/release -X ours
Expand All @@ -291,7 +305,7 @@ git cherry-pick -x <commit>
Please approve after all the required commits are cherry-picked.`, branch, repos.Kubo.Owner, repos.Kubo.Repo, repos.Kubo.DefaultBranch)
if !util.Confirm(prompt) {
return fmt.Errorf("cherry-picking commits to https://github.com/%s/%s/tree/%s was not confirmed correctly", repos.Kubo.Owner, repos.Kubo.Repo, branch)
return fmt.Errorf("🚨 cherry-picking commits to https://github.com/%s/%s/tree/%s was not confirmed correctly", repos.Kubo.Owner, repos.Kubo.Repo, branch)
}

if !ctx.Version.IsPrerelease() {
Expand All @@ -302,7 +316,7 @@ Please approve after all the required commits are cherry-picked.`, branch, repos

fmt.Println("Use merge commit to merge this PR! You'll have to tag it after the merge.")
if !util.ConfirmPR(pr) {
return fmt.Errorf("%s not merged", pr.GetHTMLURL())
return fmt.Errorf("🚨 %s not merged", pr.GetHTMLURL())
}
}

Expand All @@ -321,9 +335,9 @@ Please approve after all the required commits are cherry-picked.`, branch, repos
}

if ctx.Version.IsPrerelease() {
fmt.Printf(`Release PR ready at %s. Do not merge it.`, pr.GetHTMLURL())
fmt.Printf(`💁 Release PR ready at %s. Do not merge it.`, pr.GetHTMLURL())
} else if !pr.GetMerged() && !util.ConfirmPR(pr) {
return fmt.Errorf("%s not merged", pr.GetHTMLURL())
return fmt.Errorf("🚨 %s not merged", pr.GetHTMLURL())
}
}

Expand Down
6 changes: 3 additions & 3 deletions actions/prepare_next.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (ctx PrepareNext) Check() error {
return err
}
if issue == nil {
return fmt.Errorf("issue '%s' not found in https://github.com/%s/%s/issues (%w)", title, repos.Kubo.Owner, repos.Kubo.Repo, ErrIncomplete)
return fmt.Errorf("⚠️ issue '%s' not found in https://github.com/%s/%s/issues (%w)", title, repos.Kubo.Owner, repos.Kubo.Repo, ErrIncomplete)
}

err = CheckPR(ctx.GitHub, repos.Kubo.Owner, repos.Kubo.Repo, branch, true)
Expand All @@ -56,7 +56,7 @@ func (ctx PrepareNext) Run() error {
return err
}
if file == nil {
return fmt.Errorf("https://github.com/%s/%s/tree/%s/docs/RELEASE_ISSUE_TEMPLATE.md not found", repos.Kubo.Owner, repos.Kubo.Repo, repos.Kubo.DefaultBranch)
return fmt.Errorf("🚨 https://github.com/%s/%s/tree/%s/docs/RELEASE_ISSUE_TEMPLATE.md not found", repos.Kubo.Owner, repos.Kubo.Repo, repos.Kubo.DefaultBranch)
}

content, err := base64.StdEncoding.DecodeString(*file.Content)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (ctx PrepareNext) Run() error {
}

if !util.ConfirmPR(pr) {
return fmt.Errorf("%s not merged", pr.GetHTMLURL())
return fmt.Errorf("🚨 %s not merged", pr.GetHTMLURL())
}

return nil
Expand Down
22 changes: 11 additions & 11 deletions actions/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ func (ctx Promote) Check() error {
return err
}
if issue == nil {
return fmt.Errorf("issue '%s' not found in https://github.com/%s/%s/issues (%w)", repos.Kubo.ReleaseIssueTitle(ctx.Version), repos.Kubo.Owner, repos.Kubo.Repo, ErrFailure)
return fmt.Errorf("⚠️ issue '%s' not found in https://github.com/%s/%s/issues (%w)", repos.Kubo.ReleaseIssueTitle(ctx.Version), repos.Kubo.Owner, repos.Kubo.Repo, ErrFailure)
}

comment, err := ctx.GitHub.GetIssueComment(repos.Kubo.Owner, repos.Kubo.Repo, issue.GetNumber(), ctx.getReleaseIssueComment())
if err != nil {
return err
}
if comment == nil {
return fmt.Errorf("comment '%s' not found in %s (%w)", ctx.getReleaseIssueComment(), issue.GetHTMLURL(), ErrIncomplete)
return fmt.Errorf("⚠️ comment '%s' not found in %s (%w)", ctx.getReleaseIssueComment(), issue.GetHTMLURL(), ErrIncomplete)
}

if ctx.Matrix == nil {
Expand All @@ -111,7 +111,7 @@ func (ctx Promote) Check() error {
}
}
if !found {
return fmt.Errorf("post '%s' not found in https://matrix.to/#/#ipfs-chatter:ipfs.io (%w)", ctx.getDiscoursePostTitle(), ErrIncomplete)
return fmt.Errorf("⚠️ post '%s' not found in https://matrix.to/#/#ipfs-chatter:ipfs.io (%w)", ctx.getDiscoursePostTitle(), ErrIncomplete)
}
}

Expand All @@ -121,10 +121,10 @@ func (ctx Promote) Check() error {
return err
}
if release == nil {
return fmt.Errorf("release '%s' not found in https://github.com/%s/%s/releases (%w)", ctx.Version, repos.Kubo.Owner, repos.Kubo.Repo, ErrFailure)
return fmt.Errorf("⚠️ release '%s' not found in https://github.com/%s/%s/releases (%w)", ctx.Version, repos.Kubo.Owner, repos.Kubo.Repo, ErrFailure)
}
if !strings.Contains(release.GetBody(), "- 💬 [Discuss]") {
return fmt.Errorf("%s does not contain a discuss link (%w)", release.GetHTMLURL(), ErrIncomplete)
return fmt.Errorf("⚠️ %s does not contain a discuss link (%w)", release.GetHTMLURL(), ErrIncomplete)
}
}

Expand All @@ -141,7 +141,7 @@ func (ctx Promote) Run() error {
return err
}
if issue == nil {
return fmt.Errorf("issue '%s' not found in https://github.com/%s/%s/issues", repos.Kubo.ReleaseIssueTitle(ctx.Version), repos.Kubo.Owner, repos.Kubo.Repo)
return fmt.Errorf("🚨 issue '%s' not found in https://github.com/%s/%s/issues", repos.Kubo.ReleaseIssueTitle(ctx.Version), repos.Kubo.Owner, repos.Kubo.Repo)
}

_, err = ctx.GitHub.GetOrCreateIssueComment(repos.Kubo.Owner, repos.Kubo.Repo, issue.GetNumber(), ctx.getReleaseIssueComment())
Expand All @@ -161,7 +161,7 @@ Remember to pin the topic globally!
Please approve once the post is up.`, ctx.getDiscoursePostTitle(), ctx.getDiscoursePostBody())
if !util.Confirm(prompt) {
return fmt.Errorf("creation of discourse post was not confirmed correctly")
return fmt.Errorf("🚨 creation of discourse post was not confirmed correctly")
}

if !ctx.Version.IsPrerelease() {
Expand All @@ -173,7 +173,7 @@ Use the following template:
Please approve once the post is linked.`, url, strings.ReplaceAll(ctx.Version.String(), ".", "-"))

if !util.Confirm(prompt) {
return fmt.Errorf("%s does not contain a discuss link", url)
return fmt.Errorf("🚨 %s does not contain a discuss link", url)
}
}

Expand All @@ -186,15 +186,15 @@ Url: %s
Please approve once the post is up.`, url)
if !util.Confirm(prompt) {
return fmt.Errorf("creation of reddit post was not confirmed correctly")
return fmt.Errorf("🚨 creation of reddit post was not confirmed correctly")
}

file, err := ctx.GitHub.GetFile(repos.Kubo.Owner, repos.Kubo.Repo, "docs/changelogs/"+ctx.Version.MajorMinor()+".md", "release")
if err != nil {
return err
}
if file == nil {
return fmt.Errorf("https://github.com/%s/%s/blob/release/docs/changelogs/%s.md not found", repos.Kubo.Owner, repos.Kubo.Repo, ctx.Version.MajorMinor())
return fmt.Errorf("🚨 https://github.com/%s/%s/blob/release/docs/changelogs/%s.md not found", repos.Kubo.Owner, repos.Kubo.Repo, ctx.Version.MajorMinor())
}

content, err := base64.StdEncoding.DecodeString(*file.Content)
Expand All @@ -219,7 +219,7 @@ What's happening?: #Kubo %s was just released!
Please approve once the message is up.`, ctx.Version, strings.Join(highlights, "\n"), url)
if !util.Confirm(prompt) {
return fmt.Errorf("creation of twitter post was not confirmed correctly")
return fmt.Errorf("🚨 creation of twitter post was not confirmed correctly")
}
}

Expand Down
2 changes: 1 addition & 1 deletion actions/publish_to_distributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (ctx PublishToDistributions) Run() error {
return err
}
if !util.ConfirmPR(pr) {
return fmt.Errorf("%s not merged", pr.GetHTMLURL())
return fmt.Errorf("🚨 %s not merged", pr.GetHTMLURL())
}
return nil
}
26 changes: 11 additions & 15 deletions actions/publish_to_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package actions
import (
"encoding/base64"
"fmt"
"strconv"
"strings"

"github.com/ipfs/kuboreleaser/github"
Expand All @@ -25,7 +24,7 @@ func (ctx PublishToGitHub) Check() error {
return err
}
if release == nil {
return fmt.Errorf("release '%s' not found in https://github.com/%s/%s/releases (%w)", ctx.Version.String(), repos.Kubo.Owner, repos.Kubo.Repo, ErrIncomplete)
return fmt.Errorf("⚠️ release '%s' not found in https://github.com/%s/%s/releases (%w)", ctx.Version.String(), repos.Kubo.Owner, repos.Kubo.Repo, ErrIncomplete)
}

return CheckWorkflowRun(ctx.GitHub, repos.Kubo.Owner, repos.Kubo.Repo, repos.Kubo.DefaultBranch, repos.Kubo.SyncReleaseAssetsWorkflowName, repos.Kubo.SyncReleaseAssetsWorkflowJobName, ctx.Version.String())
Expand All @@ -43,7 +42,7 @@ func (ctx PublishToGitHub) Run() error {
return err
}
if file == nil {
return fmt.Errorf("https://github.com/%s/%s/blob/%s/docs/changelogs/%s.md not found", repos.Kubo.Owner, repos.Kubo.Repo, repos.Kubo.ReleaseBranch, ctx.Version.MajorMinor())
return fmt.Errorf("🚨 https://github.com/%s/%s/blob/%s/docs/changelogs/%s.md not found", repos.Kubo.Owner, repos.Kubo.Repo, repos.Kubo.ReleaseBranch, ctx.Version.MajorMinor())
}

content, err := base64.StdEncoding.DecodeString(*file.Content)
Expand All @@ -53,21 +52,18 @@ func (ctx PublishToGitHub) Run() error {

body = string(content)

index := strings.Index(body, "- [Overview](#overview)\n")
header := fmt.Sprintf("## %s\n", ctx.Version.MajorMinorPatch())

index := strings.Index(body, header)
if index != -1 {
index += len("- [Overview](#overview)\n")
body = body[index:]
body = body[index+len(header):]
} else {
body = "<!-- Please fill out the release description manually -->"
}

if ctx.Version.IsPatch() {
patch, err := strconv.Atoi(ctx.Version.Patch())
if err != nil {
return err
}
index = strings.Index(body, fmt.Sprintf("## %s.%d\n", ctx.Version.MajorMinor(), patch-1))
if index != -1 {
body = body[:index]
}
index = strings.Index(body, "## ")
if index != -1 {
body = body[:index]
}
}

Expand Down
Loading

0 comments on commit 01c0fe7

Please sign in to comment.