-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommands.go
108 lines (103 loc) · 2.99 KB
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"fmt"
"os"
command "github.com/zimbatm/github-deploy/command"
secretvalue "github.com/zimbatm/go-secretvalue"
cli "gopkg.in/urfave/cli.v1"
"gopkg.in/urfave/cli.v1/altsrc"
)
var GlobalFlags = []cli.Flag{
// This is only really needed for the "please" command
altsrc.NewStringFlag(cli.StringFlag{
Name: "git-commit",
Usage: "git commit ID",
EnvVar: "GITHUB_SHA,BUILDKITE_COMMIT,CIRCLE_SHA1,TRAVIS_PULL_REQUEST_SHA",
}),
altsrc.NewStringFlag(cli.StringFlag{
Name: "git-branch",
Usage: "git branch",
EnvVar: "GITHUB_REF,BUILDKITE_BRANCH,CIRCLE_BRANCH,TRAVIS_BRANCH",
}),
altsrc.NewStringFlag(cli.StringFlag{
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{
Name: "git-ref-commit",
Usage: "use the commit as deployment reference instead of branch",
},
cli.GenericFlag{
Name: "github-token",
Usage: "Github Personal access token to interact with the Github API",
EnvVar: "GITHUB_TOKEN",
Value: &secretvalue.StringFlag{
SecretValue: secretvalue.New("github-token"),
},
},
}
var Commands = []cli.Command{
{
Name: "please",
Usage: "Initiates a deployment",
Action: command.CmdPlease,
Flags: []cli.Flag{
cli.StringFlag{
Name: "deploy-script",
Usage: "DEPRECATED. Use a positional argument instead.",
},
cli.StringFlag{
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{
Name: "environment",
Value: "production",
Usage: "Sets the target environment, ignored if pull-request is passed",
},
cli.StringFlag{
Name: "environment-url",
Value: "",
Usage: "Optional url to access your environment",
},
cli.StringFlag{
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",
},
},
},
{
Name: "cleanup",
Usage: "Removes deployments",
Action: command.CmdCleanup,
Flags: []cli.Flag{
cli.StringFlag{
Name: "list-script",
Usage: "Script that lists the deployed PRs",
Value: "",
},
cli.StringSliceFlag{
Name: "pr, pull-request",
Usage: "Limit cleanup to one or more PRs",
},
cli.BoolFlag{
Name: "ignore-missing",
Usage: "Don't consider it a failure if no deployment is found",
},
},
},
}
func CommandNotFound(c *cli.Context, cmd string) {
fmt.Fprintf(os.Stderr, "%s: '%s' is not a %s command. See '%s --help'.", c.App.Name, cmd, c.App.Name, c.App.Name)
os.Exit(2)
}