Skip to content

Commit e56a399

Browse files
committed
add support for GitHub Actions
1 parent 3be7626 commit e56a399

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ GLOBAL OPTIONS:
4141
--git-branch value git branch [$BUILDKITE_BRANCH, $CIRCLE_BRANCH, $TRAVIS_BRANCH]
4242
--git-origin value URL of the repo [$BUILDKITE_REPO, $CIRCLE_REPOSITORY_URL]
4343
--git-ref-commit use the commit as deployment reference instead of branch
44-
--github-token value Github Personal access token to interact with the Github API (default: <secret:github-token>) [$GITHUB_AUTH_TOKEN]
44+
--github-token value Github Personal access token to interact with the Github API (default: <secret:github-token>) [$GITHUB_TOKEN]
4545
--help, -h show help
4646
--version, -v print the version
4747
```
@@ -77,7 +77,7 @@ Go to https://github.com/settings/tokens/new
7777

7878
Select `repo`
7979

80-
export GITHUB_AUTH_TOKEN=<new-token>
80+
export GITHUB_TOKEN=<new-token>
8181

8282
### Create the wrapper scripts
8383

command/please.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ func CmdPlease(c *cli.Context) (err error) {
2525
commit := c.GlobalString("git-commit")
2626
branch := c.GlobalString("git-branch")
2727
commitRef := c.GlobalBool("git-ref-commit")
28+
origin := c.GlobalString("git-origin")
29+
30+
// Compose the Git originl URL in the case of GitHub Actions
31+
if origin == "" && os.Getenv("GITHUB_SERVER_URL") != "" {
32+
origin = fmt.Sprintf(
33+
"%s/%s.git",
34+
os.Getenv("GITHUB_SERVER_URL"),
35+
os.Getenv("GITHUB_REPOSITORY"),
36+
)
37+
}
38+
39+
// Compose the log URL in the case of GitHub Actions
40+
if logURL == "" && os.Getenv("GITHUB_SERVER_URL") != "" {
41+
logURL = fmt.Sprintf(
42+
"%s/%s/actions/runs/%s",
43+
os.Getenv("GITHUB_SERVER_URL"),
44+
os.Getenv("GITHUB_REPOSITORY"),
45+
os.Getenv("GITHUB_RUN_ID"),
46+
)
47+
}
2848

2949
ref := ""
3050

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

6585
log.Println("deploy ref", ref)
66-
log.Println("origin", c.GlobalString("git-origin"))
86+
log.Println("origin", origin)
6787

6888
// First, declare the new deployment to GitHub
6989

commands.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ var GlobalFlags = []cli.Flag{
1515
altsrc.NewStringFlag(cli.StringFlag{
1616
Name: "git-commit",
1717
Usage: "git commit ID",
18-
EnvVar: "BUILDKITE_COMMIT,CIRCLE_SHA1,TRAVIS_PULL_REQUEST_SHA",
18+
EnvVar: "GITHUB_SHA,BUILDKITE_COMMIT,CIRCLE_SHA1,TRAVIS_PULL_REQUEST_SHA",
1919
}),
2020
altsrc.NewStringFlag(cli.StringFlag{
2121
Name: "git-branch",
2222
Usage: "git branch",
23-
EnvVar: "BUILDKITE_BRANCH,CIRCLE_BRANCH,TRAVIS_BRANCH",
23+
EnvVar: "GITHUB_REF,BUILDKITE_BRANCH,CIRCLE_BRANCH,TRAVIS_BRANCH",
2424
}),
2525
altsrc.NewStringFlag(cli.StringFlag{
26-
Name: "git-origin",
27-
Usage: "URL of the repo",
26+
Name: "git-origin",
27+
Usage: "URL of the repo",
28+
// NOTE: In the case of GitHub Actions, there is no env var that provides
29+
// this directly.
2830
EnvVar: "BUILDKITE_REPO,CIRCLE_REPOSITORY_URL", // Travis doesn't have an equivalent
2931
}),
3032
cli.BoolFlag{
@@ -34,7 +36,7 @@ var GlobalFlags = []cli.Flag{
3436
cli.GenericFlag{
3537
Name: "github-token",
3638
Usage: "Github Personal access token to interact with the Github API",
37-
EnvVar: "GITHUB_AUTH_TOKEN",
39+
EnvVar: "GITHUB_TOKEN",
3840
Value: &secretvalue.StringFlag{
3941
SecretValue: secretvalue.New("github-token"),
4042
},
@@ -52,8 +54,10 @@ var Commands = []cli.Command{
5254
Usage: "Script that deploys the given PR",
5355
},
5456
cli.StringFlag{
55-
Name: "pr, pull-request",
56-
Usage: "Creates a temporary deployment for the give pull-request ID",
57+
Name: "pr, pull-request",
58+
Usage: "Creates a temporary deployment for the give pull-request ID",
59+
// NOTE: GitHub Actions doesn't have an env var like that and the
60+
// argument must be passed explicitly.
5761
EnvVar: "BUILDKITE_PULL_REQUEST,CIRCLE_PULL_REQUEST,TRAVIS_PULL_REQUEST",
5862
},
5963
cli.StringFlag{
@@ -65,6 +69,8 @@ var Commands = []cli.Command{
6569
Name: "build-url",
6670
Usage: "URL to follow the build progress",
6771
// NOTE: Travis doesn't have an equivalent
72+
// NOTE: For GitHub Actions, the URL is composed later in the command
73+
// if empty.
6874
EnvVar: "BUILDKITE_BUILD_URL,CIRCLE_BUILD_URL",
6975
},
7076
},

0 commit comments

Comments
 (0)