-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:bobg/modver
- Loading branch information
Showing
25 changed files
with
1,408 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
*~ | ||
cover.out | ||
modver | ||
/cover.out | ||
/modver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM golang:latest | ||
|
||
ADD . /app | ||
|
||
WORKDIR /app | ||
|
||
RUN go build ./cmd/modver-action | ||
|
||
ENTRYPOINT ["/app/modver-action"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Modver | ||
description: Analyze pull requests for changes in Go code that require updating a module's version number. | ||
author: Bob Glickstein | ||
inputs: | ||
github_token: | ||
description: 'The GitHub token to use for authentication.' | ||
required: true | ||
pull_request_url: | ||
description: 'The full github.com URL of the pull request.' | ||
required: true | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
|
||
"github.com/bobg/modver/v2" | ||
"github.com/bobg/modver/v2/internal" | ||
) | ||
|
||
func main() { | ||
os.Setenv("GOROOT", "/usr/local/go") // Work around some Docker weirdness. | ||
|
||
prURL := os.Getenv("INPUT_PULL_REQUEST_URL") | ||
host, owner, reponame, prnum, err := internal.ParsePR(prURL) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
token := os.Getenv("INPUT_GITHUB_TOKEN") | ||
if token == "" { | ||
log.Fatal("No GitHub token in the environment variable INPUT_GITHUB_TOKEN") | ||
} | ||
ctx := context.Background() | ||
gh, err := internal.NewClient(ctx, host, token) | ||
if err != nil { | ||
log.Fatalf("Creating GitHub client: %s", err) | ||
} | ||
result, err := internal.PR(ctx, gh, owner, reponame, prnum) | ||
if err != nil { | ||
log.Fatalf("Running comparison: %s", err) | ||
} | ||
modver.Pretty(os.Stdout, result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/google/go-github/v50/github" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/bobg/modver/v2" | ||
"github.com/bobg/modver/v2/internal" | ||
) | ||
|
||
func doCompare(ctx context.Context, opts options) (modver.Result, error) { | ||
return doCompareHelper(ctx, opts, internal.NewClient, internal.PR, modver.CompareGitWith, modver.CompareDirs) | ||
} | ||
|
||
type ( | ||
newClientType = func(ctx context.Context, host, token string) (*github.Client, error) | ||
prType = func(ctx context.Context, gh *github.Client, owner, reponame string, prnum int) (modver.Result, error) | ||
compareGitWithType = func(ctx context.Context, repoURL, olderRev, newerRev string, f func(older, newer string) (modver.Result, error)) (modver.Result, error) | ||
compareDirsType = func(older, newer string) (modver.Result, error) | ||
) | ||
|
||
func doCompareHelper(ctx context.Context, opts options, newClient newClientType, pr prType, compareGitWith compareGitWithType, compareDirs compareDirsType) (modver.Result, error) { | ||
if opts.pr != "" { | ||
host, owner, reponame, prnum, err := internal.ParsePR(opts.pr) | ||
if err != nil { | ||
return modver.None, errors.Wrap(err, "parsing pull-request URL") | ||
} | ||
if opts.ghtoken == "" { | ||
return modver.None, fmt.Errorf("usage: %s -pr URL [-token TOKEN]", os.Args[0]) | ||
} | ||
gh, err := newClient(ctx, host, opts.ghtoken) | ||
if err != nil { | ||
return modver.None, errors.Wrap(err, "creating GitHub client") | ||
} | ||
return pr(ctx, gh, owner, reponame, prnum) | ||
} | ||
|
||
if opts.gitRepo != "" { | ||
if len(opts.args) != 2 { | ||
return nil, fmt.Errorf("usage: %s -git REPO [-gitcmd GIT_COMMAND] [-q | -pretty] [-v1 OLDERVERSION -v2 NEWERVERSION | -versions] OLDERREV NEWERREV", os.Args[0]) | ||
} | ||
|
||
callback := modver.CompareDirs | ||
if opts.versions { | ||
callback = getTags(&opts.v1, &opts.v2, opts.args[0], opts.args[1]) | ||
} | ||
|
||
return compareGitWith(ctx, opts.gitRepo, opts.args[0], opts.args[1], callback) | ||
} | ||
if len(opts.args) != 2 { | ||
return nil, fmt.Errorf("usage: %s [-q | -pretty] [-v1 OLDERVERSION -v2 NEWERVERSION] OLDERDIR NEWERDIR", os.Args[0]) | ||
} | ||
return compareDirs(opts.args[0], opts.args[1]) | ||
} |
Oops, something went wrong.