-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.go
175 lines (164 loc) · 4.43 KB
/
main.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"log"
"os"
"github.com/joho/godotenv"
"github.com/urfave/cli/v2"
)
// Version set at compile-time
var (
Version string
BuildNum string
)
func main() {
// Load env-file if it exists first
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
_ = godotenv.Load(filename)
}
if _, err := os.Stat("/run/drone/env"); err == nil {
_ = godotenv.Overload("/run/drone/env")
}
app := cli.NewApp()
app.Name = "git-push plugin"
app.Usage = "git-push plugin"
app.Action = run
app.Version = Version
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "commit.author.name",
Usage: "git author name",
EnvVars: []string{"PLUGIN_AUTHOR_NAME", "DRONE_COMMIT_AUTHOR"},
},
&cli.StringFlag{
Name: "commit.author.email",
Usage: "git author email",
EnvVars: []string{"PLUGIN_AUTHOR_EMAIL", "DRONE_COMMIT_AUTHOR_EMAIL"},
},
&cli.StringFlag{
Name: "netrc.machine",
Usage: "netrc machine",
EnvVars: []string{"PLUGIN_NETRC_MACHINE,DRONE_NETRC_MACHINE"},
},
&cli.StringFlag{
Name: "netrc.username",
Usage: "netrc username",
EnvVars: []string{"PLUGIN_USERNAME,DRONE_NETRC_USERNAME,GITHUB_USERNAME"},
},
&cli.StringFlag{
Name: "netrc.password",
Usage: "netrc password",
EnvVars: []string{"PLUGIN_PASSWORD,DRONE_NETRC_PASSWORD,GITHUB_PASSWORD"},
},
&cli.StringFlag{
Name: "ssh-key",
Usage: "private ssh key",
EnvVars: []string{"PLUGIN_SSH_KEY", "GIT_PUSH_SSH_KEY"},
},
&cli.StringFlag{
Name: "remote",
Usage: "url of the remote repo",
EnvVars: []string{"PLUGIN_REMOTE", "GIT_PUSH_REMOTE"},
},
&cli.StringFlag{
Name: "remote-name",
Usage: "name of the remote repo",
Value: "deploy",
EnvVars: []string{"PLUGIN_REMOTE_NAME", "GIT_PUSH_REMOTE_NAME"},
},
&cli.StringFlag{
Name: "branch",
Usage: "name of remote branch",
EnvVars: []string{"PLUGIN_BRANCH", "GIT_PUSH_BRANCH"},
Value: "master",
},
&cli.StringFlag{
Name: "local-branch",
Usage: "name of local branch",
Value: "HEAD",
EnvVars: []string{"PLUGIN_LOCAL_BRANCH", "GIT_PUSH_LOCAL_BRANCH"},
},
&cli.StringFlag{
Name: "path",
Usage: "path to git repo",
EnvVars: []string{"PLUGIN_PATH"},
},
&cli.BoolFlag{
Name: "force",
Usage: "force push to remote",
EnvVars: []string{"PLUGIN_FORCE", "GIT_PUSH_FORCE"},
},
&cli.BoolFlag{
Name: "followtags",
Usage: "push to remote with tags",
EnvVars: []string{"PLUGIN_FOLLOWTAGS", "GIT_PUSH_FOLLOWTAGS"},
},
&cli.BoolFlag{
Name: "skip-verify",
Usage: "skip ssl verification",
EnvVars: []string{"PLUGIN_SKIP_VERIFY", "GIT_PUSH_SKIP_VERIFY"},
},
&cli.BoolFlag{
Name: "commit",
Usage: "commit dirty changes",
EnvVars: []string{"PLUGIN_COMMIT", "GIT_PUSH_COMMIT"},
},
&cli.StringFlag{
Name: "commit-message",
Usage: "commit message",
EnvVars: []string{"PLUGIN_COMMIT_MESSAGE", "GIT_PUSH_COMMIT_MESSAGE"},
},
&cli.StringFlag{
Name: "tag",
Usage: "tag to add to the commit",
EnvVars: []string{"PLUGIN_TAG", "GIT_PUSH_TAG"},
},
&cli.BoolFlag{
Name: "empty-commit",
Usage: "empty commit",
EnvVars: []string{"PLUGIN_EMPTY_COMMIT", "GIT_PUSH_EMPTY_COMMIT"},
},
&cli.BoolFlag{
Name: "no-verify",
Usage: "bypasses the pre-commit and commit-msg hooks",
EnvVars: []string{"PLUGIN_NO_VERIFY", "GIT_PUSH_NO_VERIFY"},
},
}
if BuildNum != "" {
app.Version = app.Version + "+" + BuildNum
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
plugin := Plugin{
Netrc: Netrc{
Login: c.String("netrc.username"),
Machine: c.String("netrc.machine"),
Password: c.String("netrc.password"),
},
Commit: Commit{
Author: Author{
Name: c.String("commit.author.name"),
Email: c.String("commit.author.email"),
},
},
Config: Config{
Key: c.String("ssh-key"),
Remote: c.String("remote"),
RemoteName: c.String("remote-name"),
Branch: c.String("branch"),
LocalBranch: c.String("local-branch"),
Path: c.String("path"),
Force: c.Bool("force"),
FollowTags: c.Bool("followtags"),
SkipVerify: c.Bool("skip-verify"),
Commit: c.Bool("commit"),
CommitMessage: c.String("commit-message"),
Tag: c.String("tag"),
EmptyCommit: c.Bool("empty-commit"),
NoVerify: c.Bool("no-verify"),
},
}
return plugin.Exec()
}