2015-11-23 00:07:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2020-12-11 21:33:26 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-08-26 08:38:22 +00:00
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/urfave/cli"
|
2015-11-23 00:07:57 +00:00
|
|
|
)
|
|
|
|
|
2018-03-15 19:43:32 +00:00
|
|
|
var (
|
2019-02-15 09:25:53 +00:00
|
|
|
version = "unknown"
|
2018-03-15 19:43:32 +00:00
|
|
|
)
|
2015-11-23 00:07:57 +00:00
|
|
|
|
|
|
|
func main() {
|
2016-08-26 08:38:22 +00:00
|
|
|
app := cli.NewApp()
|
2018-03-02 22:41:45 +00:00
|
|
|
app.Name = "gitea-release plugin"
|
|
|
|
app.Usage = "gitea-release plugin"
|
2016-08-26 08:38:22 +00:00
|
|
|
app.Action = run
|
2019-02-15 09:25:53 +00:00
|
|
|
app.Version = version
|
2016-08-26 08:38:22 +00:00
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "api-key",
|
2018-03-02 22:41:45 +00:00
|
|
|
Usage: "api key to access gitea api",
|
|
|
|
EnvVar: "PLUGIN_API_KEY,GITEA_RELEASE_API_KEY,GITEA_TOKEN",
|
2016-08-26 08:38:22 +00:00
|
|
|
},
|
|
|
|
cli.StringSliceFlag{
|
|
|
|
Name: "files",
|
|
|
|
Usage: "list of files to upload",
|
2018-03-02 22:41:45 +00:00
|
|
|
EnvVar: "PLUGIN_FILES,GITEA_RELEASE_FILES",
|
2016-08-26 08:38:22 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "file-exists",
|
|
|
|
Value: "overwrite",
|
|
|
|
Usage: "what to do if file already exist",
|
2018-03-02 22:41:45 +00:00
|
|
|
EnvVar: "PLUGIN_FILE_EXISTS,GITEA_RELEASE_FILE_EXISTS",
|
2016-08-26 08:38:22 +00:00
|
|
|
},
|
|
|
|
cli.StringSliceFlag{
|
|
|
|
Name: "checksum",
|
|
|
|
Usage: "generate specific checksums",
|
2018-03-02 22:41:45 +00:00
|
|
|
EnvVar: "PLUGIN_CHECKSUM,GITEA_RELEASE_CHECKSUM",
|
2016-08-26 08:38:22 +00:00
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "draft",
|
|
|
|
Usage: "create a draft release",
|
2018-03-02 22:41:45 +00:00
|
|
|
EnvVar: "PLUGIN_DRAFT,GITEA_RELEASE_DRAFT",
|
2016-08-26 08:38:22 +00:00
|
|
|
},
|
2018-03-28 01:55:21 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "insecure",
|
|
|
|
Usage: "visit base-url via insecure https protocol",
|
|
|
|
EnvVar: "PLUGIN_INSECURE,GITEA_RELEASE_INSECURE",
|
|
|
|
},
|
2017-03-13 23:07:52 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "prerelease",
|
|
|
|
Usage: "set the release as prerelease",
|
2018-03-02 22:41:45 +00:00
|
|
|
EnvVar: "PLUGIN_PRERELEASE,GITEA_RELEASE_PRERELEASE",
|
2017-03-13 23:07:52 +00:00
|
|
|
},
|
2016-08-26 08:38:22 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "base-url",
|
2018-03-02 22:41:45 +00:00
|
|
|
Usage: "url of the gitea instance",
|
|
|
|
EnvVar: "PLUGIN_BASE_URL,GITEA_RELEASE_BASE_URL",
|
2016-08-26 08:38:22 +00:00
|
|
|
},
|
2018-03-03 11:09:01 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "note",
|
|
|
|
Value: "",
|
|
|
|
Usage: "file or string with notes for the release (example: changelog)",
|
|
|
|
EnvVar: "PLUGIN_NOTE,GITEA_RELEASE_NOTE",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "title",
|
|
|
|
Value: "",
|
|
|
|
Usage: "file or string for the title shown in the gitea release",
|
|
|
|
EnvVar: "PLUGIN_TITLE,GITEA_RELEASE_TITLE",
|
|
|
|
},
|
2016-08-26 08:38:22 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "repo.owner",
|
|
|
|
Usage: "repository owner",
|
|
|
|
EnvVar: "DRONE_REPO_OWNER",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "repo.name",
|
|
|
|
Usage: "repository name",
|
|
|
|
EnvVar: "DRONE_REPO_NAME",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "build.event",
|
|
|
|
Value: "push",
|
|
|
|
Usage: "build event",
|
|
|
|
EnvVar: "DRONE_BUILD_EVENT",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "commit.ref",
|
|
|
|
Value: "refs/heads/master",
|
|
|
|
Usage: "git commit ref",
|
|
|
|
EnvVar: "DRONE_COMMIT_REF",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "env-file",
|
|
|
|
Usage: "source env file",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
logrus.Fatal(err)
|
2015-11-23 00:07:57 +00:00
|
|
|
}
|
2016-02-11 12:04:57 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 08:38:22 +00:00
|
|
|
func run(c *cli.Context) error {
|
|
|
|
if c.String("env-file") != "" {
|
|
|
|
_ = godotenv.Load(c.String("env-file"))
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin := Plugin{
|
|
|
|
Repo: Repo{
|
|
|
|
Owner: c.String("repo.owner"),
|
|
|
|
Name: c.String("repo.name"),
|
|
|
|
},
|
|
|
|
Build: Build{
|
|
|
|
Event: c.String("build.event"),
|
|
|
|
},
|
|
|
|
Commit: Commit{
|
2016-09-15 00:26:01 +00:00
|
|
|
Ref: c.String("commit.ref"),
|
2016-08-26 08:38:22 +00:00
|
|
|
},
|
|
|
|
Config: Config{
|
|
|
|
APIKey: c.String("api-key"),
|
2016-09-15 00:26:01 +00:00
|
|
|
Files: c.StringSlice("files"),
|
2016-08-26 08:38:22 +00:00
|
|
|
FileExists: c.String("file-exists"),
|
|
|
|
Checksum: c.StringSlice("checksum"),
|
|
|
|
Draft: c.Bool("draft"),
|
2018-03-03 11:09:01 +00:00
|
|
|
PreRelease: c.Bool("prerelease"),
|
2016-08-26 08:38:22 +00:00
|
|
|
BaseURL: c.String("base-url"),
|
2018-03-28 01:55:21 +00:00
|
|
|
Insecure: c.Bool("insecure"),
|
2018-03-03 11:09:01 +00:00
|
|
|
Title: c.String("title"),
|
|
|
|
Note: c.String("note"),
|
2016-08-26 08:38:22 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return plugin.Exec()
|
2016-01-15 16:46:00 +00:00
|
|
|
}
|