Skip to content

Commit

Permalink
add support for GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbatm committed Feb 12, 2021
1 parent 3be7626 commit e56a399
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GLOBAL OPTIONS:
--git-branch value git branch [$BUILDKITE_BRANCH, $CIRCLE_BRANCH, $TRAVIS_BRANCH]
--git-origin value URL of the repo [$BUILDKITE_REPO, $CIRCLE_REPOSITORY_URL]
--git-ref-commit use the commit as deployment reference instead of branch
--github-token value Github Personal access token to interact with the Github API (default: <secret:github-token>) [$GITHUB_AUTH_TOKEN]
--github-token value Github Personal access token to interact with the Github API (default: <secret:github-token>) [$GITHUB_TOKEN]
--help, -h show help
--version, -v print the version
```
Expand Down Expand Up @@ -77,7 +77,7 @@ Go to https://github.com/settings/tokens/new

Select `repo`

export GITHUB_AUTH_TOKEN=<new-token>
export GITHUB_TOKEN=<new-token>

### Create the wrapper scripts

Expand Down
22 changes: 21 additions & 1 deletion command/please.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ func CmdPlease(c *cli.Context) (err error) {
commit := c.GlobalString("git-commit")
branch := c.GlobalString("git-branch")
commitRef := c.GlobalBool("git-ref-commit")
origin := c.GlobalString("git-origin")

// Compose the Git originl URL in the case of GitHub Actions
if origin == "" && os.Getenv("GITHUB_SERVER_URL") != "" {
origin = fmt.Sprintf(
"%s/%s.git",
os.Getenv("GITHUB_SERVER_URL"),
os.Getenv("GITHUB_REPOSITORY"),
)
}

// Compose the log URL in the case of GitHub Actions
if logURL == "" && os.Getenv("GITHUB_SERVER_URL") != "" {
logURL = fmt.Sprintf(
"%s/%s/actions/runs/%s",
os.Getenv("GITHUB_SERVER_URL"),
os.Getenv("GITHUB_REPOSITORY"),
os.Getenv("GITHUB_RUN_ID"),
)
}

ref := ""

Expand Down Expand Up @@ -63,7 +83,7 @@ func CmdPlease(c *cli.Context) (err error) {
gh := githubClient(ctx, c)

log.Println("deploy ref", ref)
log.Println("origin", c.GlobalString("git-origin"))
log.Println("origin", origin)

// First, declare the new deployment to GitHub

Expand Down
20 changes: 13 additions & 7 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ var GlobalFlags = []cli.Flag{
altsrc.NewStringFlag(cli.StringFlag{
Name: "git-commit",
Usage: "git commit ID",
EnvVar: "BUILDKITE_COMMIT,CIRCLE_SHA1,TRAVIS_PULL_REQUEST_SHA",
EnvVar: "GITHUB_SHA,BUILDKITE_COMMIT,CIRCLE_SHA1,TRAVIS_PULL_REQUEST_SHA",
}),
altsrc.NewStringFlag(cli.StringFlag{
Name: "git-branch",
Usage: "git branch",
EnvVar: "BUILDKITE_BRANCH,CIRCLE_BRANCH,TRAVIS_BRANCH",
EnvVar: "GITHUB_REF,BUILDKITE_BRANCH,CIRCLE_BRANCH,TRAVIS_BRANCH",
}),
altsrc.NewStringFlag(cli.StringFlag{
Name: "git-origin",
Usage: "URL of the repo",
Name: "git-origin",
Usage: "URL of the repo",
// NOTE: In the case of GitHub Actions, there is no env var that provides
// this directly.
EnvVar: "BUILDKITE_REPO,CIRCLE_REPOSITORY_URL", // Travis doesn't have an equivalent
}),
cli.BoolFlag{
Expand All @@ -34,7 +36,7 @@ var GlobalFlags = []cli.Flag{
cli.GenericFlag{
Name: "github-token",
Usage: "Github Personal access token to interact with the Github API",
EnvVar: "GITHUB_AUTH_TOKEN",
EnvVar: "GITHUB_TOKEN",
Value: &secretvalue.StringFlag{
SecretValue: secretvalue.New("github-token"),
},
Expand All @@ -52,8 +54,10 @@ var Commands = []cli.Command{
Usage: "Script that deploys the given PR",
},
cli.StringFlag{
Name: "pr, pull-request",
Usage: "Creates a temporary deployment for the give pull-request ID",
Name: "pr, pull-request",
Usage: "Creates a temporary deployment for the give pull-request ID",
// NOTE: GitHub Actions doesn't have an env var like that and the
// argument must be passed explicitly.
EnvVar: "BUILDKITE_PULL_REQUEST,CIRCLE_PULL_REQUEST,TRAVIS_PULL_REQUEST",
},
cli.StringFlag{
Expand All @@ -65,6 +69,8 @@ var Commands = []cli.Command{
Name: "build-url",
Usage: "URL to follow the build progress",
// NOTE: Travis doesn't have an equivalent
// NOTE: For GitHub Actions, the URL is composed later in the command
// if empty.
EnvVar: "BUILDKITE_BUILD_URL,CIRCLE_BUILD_URL",
},
},
Expand Down

0 comments on commit e56a399

Please sign in to comment.