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

GitHub Actions friendly outputs #97

Merged
merged 2 commits into from
Sep 17, 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
3 changes: 3 additions & 0 deletions tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tagpr

import (
"context"
"fmt"
"strings"

"github.com/google/go-github/v47/github"
Expand Down Expand Up @@ -95,6 +96,8 @@ func (tp *tagpr) tagRelease(ctx context.Context, pr *github.PullRequest, currVer
return err
}

fmt.Fprintf(tp.out, "::set-output name=tag::%s\n", nextTag)

if !tp.cfg.Release() {
return nil
}
Expand Down
41 changes: 35 additions & 6 deletions tagpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package tagpr

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -35,6 +37,7 @@ type tagpr struct {
cfg *config
gitPath string
remoteName, owner, repo string
out io.Writer
}

func (tp *tagpr) latestSemverTag() string {
Expand All @@ -46,7 +49,7 @@ func (tp *tagpr) latestSemverTag() string {
}

func newTagPR(ctx context.Context, c *commander) (*tagpr, error) {
tp := &tagpr{c: c, gitPath: c.gitPath}
tp := &tagpr{c: c, gitPath: c.gitPath, out: c.outStream}

var err error
tp.remoteName, err = tp.detectRemote()
Expand Down Expand Up @@ -169,7 +172,12 @@ func (tp *tagpr) Run(ctx context.Context) error {
if err != nil {
return err
}
return tp.tagRelease(ctx, pr, currVer, latestSemverTag)
if err := tp.tagRelease(ctx, pr, currVer, latestSemverTag); err != nil {
return err
}
b, _ := json.Marshal(pr)
fmt.Fprintf(tp.out, "::set-output name=pull_request::%s\n", string(b))
return nil
}
shasStr, _, err := tp.c.Git("log", "--merges", "--pretty=format:%P",
fmt.Sprintf("%s..%s/%s", fromCommitish, tp.remoteName, releaseBranch))
Expand Down Expand Up @@ -485,16 +493,37 @@ OUT:
addingLabels = append(addingLabels, autoLableName)
_, _, err = tp.gh.Issues.AddLabelsToIssue(
ctx, tp.owner, tp.repo, *pr.Number, addingLabels)
return err
if err != nil {
return err
}
tmpPr, _, err := tp.gh.PullRequests.Get(ctx, tp.owner, tp.repo, *pr.Number)
if err == nil {
pr = tmpPr
}
b, _ := json.Marshal(pr)
fmt.Fprintf(tp.out, "::set-output name=pull_request::%s\n", string(b))
return nil
}
currTagPR.Title = github.String(title)
currTagPR.Body = github.String(mergeBody(*currTagPR.Body, body))
_, _, err = tp.gh.PullRequests.Edit(ctx, tp.owner, tp.repo, *currTagPR.Number, currTagPR)
pr, _, err := tp.gh.PullRequests.Edit(ctx, tp.owner, tp.repo, *currTagPR.Number, currTagPR)
if err != nil {
return err
}
if len(addingLabels) > 0 {
_, _, err = tp.gh.Issues.AddLabelsToIssue(
_, _, err := tp.gh.Issues.AddLabelsToIssue(
ctx, tp.owner, tp.repo, *currTagPR.Number, addingLabels)
if err != nil {
return err
}
tmpPr, _, err := tp.gh.PullRequests.Get(ctx, tp.owner, tp.repo, *pr.Number)
if err == nil {
pr = tmpPr
}
}
return err
b, _ := json.Marshal(pr)
fmt.Fprintf(tp.out, "::set-output name=pull_request::%s\n", string(b))
return nil
}

var (
Expand Down