This repository has been archived by the owner on May 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathmain.go
155 lines (146 loc) · 3.23 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
package main
import (
"os"
"time"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var (
version = "unknown"
)
func main() {
app := cli.NewApp()
app.Name = "git plugin"
app.Usage = "git plugin"
app.Action = run
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "remote",
Usage: "git remote url",
EnvVar: "PLUGIN_REMOTE,DRONE_REMOTE_URL",
},
cli.StringFlag{
Name: "path",
Usage: "git clone path",
EnvVar: "PLUGIN_PATH,DRONE_WORKSPACE",
},
cli.StringFlag{
Name: "sha",
Usage: "git commit sha",
EnvVar: "PLUGIN_SHA,DRONE_COMMIT_SHA",
},
cli.StringFlag{
Name: "ref",
Value: "refs/heads/master",
Usage: "git commit ref",
EnvVar: "PLUGIN_REF,DRONE_COMMIT_REF",
},
cli.StringFlag{
Name: "event",
Value: "push",
Usage: "build event",
EnvVar: "DRONE_BUILD_EVENT",
},
cli.StringFlag{
Name: "netrc.machine",
Usage: "netrc machine",
EnvVar: "DRONE_NETRC_MACHINE",
},
cli.StringFlag{
Name: "netrc.username",
Usage: "netrc username",
EnvVar: "DRONE_NETRC_USERNAME",
},
cli.StringFlag{
Name: "netrc.password",
Usage: "netrc password",
EnvVar: "DRONE_NETRC_PASSWORD",
},
cli.IntFlag{
Name: "depth",
Usage: "clone depth",
EnvVar: "PLUGIN_DEPTH",
},
cli.BoolTFlag{
Name: "recursive",
Usage: "clone submodules",
EnvVar: "PLUGIN_RECURSIVE",
},
cli.BoolFlag{
Name: "tags",
Usage: "clone tags",
EnvVar: "PLUGIN_TAGS",
},
cli.BoolFlag{
Name: "skip-verify",
Usage: "skip tls verification",
EnvVar: "PLUGIN_SKIP_VERIFY",
},
cli.BoolFlag{
Name: "submodule-update-remote",
Usage: "update remote submodules",
EnvVar: "PLUGIN_SUBMODULES_UPDATE_REMOTE,PLUGIN_SUBMODULE_UPDATE_REMOTE",
},
cli.GenericFlag{
Name: "submodule-override",
Usage: "json map of submodule overrides",
EnvVar: "PLUGIN_SUBMODULE_OVERRIDE",
Value: &MapFlag{},
},
cli.DurationFlag{
Name: "backoff",
Usage: "backoff duration",
EnvVar: "PLUGIN_BACKOFF",
Value: 5 * time.Second,
},
cli.IntFlag{
Name: "backoff-attempts",
Usage: "backoff attempts",
EnvVar: "PLUGIN_ATTEMPTS",
Value: 5,
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
plugin := Plugin{
Repo: Repo{
Clone: c.String("remote"),
},
Build: Build{
Commit: c.String("sha"),
Event: c.String("event"),
Path: c.String("path"),
Ref: c.String("ref"),
},
Netrc: Netrc{
Login: c.String("netrc.username"),
Machine: c.String("netrc.machine"),
Password: c.String("netrc.password"),
},
Config: Config{
Depth: c.Int("depth"),
Tags: c.Bool("tags"),
Recursive: c.BoolT("recursive"),
SkipVerify: c.Bool("skip-verify"),
SubmoduleRemote: c.Bool("submodule-update-remote"),
Submodules: c.Generic("submodule-override").(*MapFlag).Get(),
},
Backoff: Backoff{
Attempts: c.Int("backoff-attempts"),
Duration: c.Duration("backoff"),
},
}
return plugin.Exec()
}