forked from drone-plugins/drone-downstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (71 loc) · 1.69 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
package main
import (
"fmt"
"os"
"time"
"github.com/Sirupsen/logrus"
"github.com/joho/godotenv"
"github.com/urfave/cli"
)
var build = "0" // build number set at compile-time
func main() {
app := cli.NewApp()
app.Name = "downstream plugin"
app.Usage = "downstream plugin"
app.Action = run
app.Version = fmt.Sprintf("1.0.%s", build)
app.Flags = []cli.Flag{
cli.StringSliceFlag{
Name: "repositories",
Usage: "List of repositories to trigger",
EnvVar: "PLUGIN_REPOSITORIES",
},
cli.StringFlag{
Name: "server",
Usage: "Trigger a drone build on a custom server",
EnvVar: "DOWNSTREAM_SERVER,PLUGIN_SERVER",
},
cli.StringFlag{
Name: "token",
Usage: "Drone API token from your user settings",
EnvVar: "DRONE_TOKEN,DOWNSTREAM_TOKEN,PLUGIN_TOKEN",
},
cli.BoolFlag{
Name: "fork",
Usage: "Trigger a new build for a repository",
EnvVar: "PLUGIN_FORK",
},
cli.BoolFlag{
Name: "wait",
Usage: "Wait for any currently running builds to finish",
EnvVar: "PLUGIN_WAIT",
},
cli.DurationFlag{
Name: "timeout",
Value: time.Duration(60) * time.Second,
Usage: "How long to wait on any currently running builds",
EnvVar: "PLUGIN_WAIT_TIMEOUT",
},
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{
Repos: c.StringSlice("repositories"),
Server: c.String("server"),
Token: c.String("token"),
Fork: c.Bool("fork"),
Wait: c.Bool("wait"),
Timeout: c.Duration("timeout"),
}
return plugin.Exec()
}