2019-09-06 23:34:27 +00:00
|
|
|
// Copyright (c) 2019, the Drone Plugins project authors.
|
|
|
|
// Please see the AUTHORS file for details. All rights reserved.
|
|
|
|
// Use of this source code is governed by an Apache 2.0 license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Package urfave provides helpers for interacting with the `urfave/cli`
|
|
|
|
// package when creating plugins for use by the Drone CI/CD service.
|
|
|
|
//
|
|
|
|
// Drone communicates to plugins by passing in environment variables that have
|
|
|
|
// information on the currently executing build. The `urfave/cli` package can
|
|
|
|
// read these environment variables and extract them into structs.
|
|
|
|
//
|
|
|
|
// import(
|
|
|
|
// "github.com/drone-plugins/drone-plugin-lib/pkg/urfave"
|
|
|
|
// "github.com/urfave/cli"
|
|
|
|
// )
|
|
|
|
//
|
|
|
|
// func main() {
|
|
|
|
// app := cli.New()
|
|
|
|
// app.Name = "my awesome Drone plugin"
|
|
|
|
// app.Run = run
|
|
|
|
// app.Flags = []cli.Flags{
|
|
|
|
// // All my plugin flags
|
|
|
|
// }
|
|
|
|
// app.Flags = append(
|
|
|
|
// app.Flags,
|
2019-10-10 20:42:02 +00:00
|
|
|
// urfave.PipelineFlags()...,
|
2019-09-06 23:34:27 +00:00
|
|
|
// )
|
|
|
|
// }
|
2019-10-10 20:42:02 +00:00
|
|
|
//
|
|
|
|
// func run(ctx *cli.Context) {
|
|
|
|
// pipeline := urfave.PipelineFromContext(ctx)
|
|
|
|
// ....
|
|
|
|
// }
|
2019-09-06 23:34:27 +00:00
|
|
|
package urfave
|
|
|
|
|
|
|
|
import (
|
2019-09-07 00:13:21 +00:00
|
|
|
"time"
|
|
|
|
|
2019-09-06 23:34:27 +00:00
|
|
|
"github.com/urfave/cli"
|
2019-10-10 19:59:12 +00:00
|
|
|
|
|
|
|
"github.com/drone-plugins/drone-plugin-lib/internal/environ"
|
|
|
|
"github.com/drone-plugins/drone-plugin-lib/pkg/plugin"
|
2019-09-06 23:34:27 +00:00
|
|
|
)
|
|
|
|
|
2019-09-10 00:03:55 +00:00
|
|
|
//---------------------------------------------------------------------
|
2019-10-10 20:05:11 +00:00
|
|
|
// Pipeline
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
// PipelineFlags has the cli.Flags for the plugin.Pipeline.
|
|
|
|
func PipelineFlags() []cli.Flag {
|
|
|
|
flags := []cli.Flag{}
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
flags = append(flags, buildFlags()...)
|
|
|
|
flags = append(flags, repoFlags()...)
|
|
|
|
flags = append(flags, commitFlags()...)
|
|
|
|
flags = append(flags, stageFlags()...)
|
|
|
|
flags = append(flags, stepFlags()...)
|
|
|
|
flags = append(flags, semVerFlags()...)
|
2019-10-10 20:05:11 +00:00
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
// PipelineFromContext creates a plugin.Pipeline from the cli.Context.
|
2019-10-10 20:36:20 +00:00
|
|
|
func PipelineFromContext(ctx *cli.Context) plugin.Pipeline {
|
2019-10-10 20:05:11 +00:00
|
|
|
return plugin.Pipeline{
|
2019-10-10 20:36:20 +00:00
|
|
|
Build: buildFromContext(ctx),
|
|
|
|
Repo: repoFromContext(ctx),
|
|
|
|
Commit: commitFromContext(ctx),
|
|
|
|
Stage: stageFromContext(ctx),
|
|
|
|
Step: stepFromContext(ctx),
|
|
|
|
SemVer: semVerFromContext(ctx),
|
2019-10-10 20:05:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
2019-09-10 00:03:55 +00:00
|
|
|
// Build Flags
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
const (
|
2019-10-10 20:36:20 +00:00
|
|
|
buildActionFlag = "build.action"
|
|
|
|
buildCreatedFlag = "build.created"
|
|
|
|
buildDeployToFlag = "build.deploy-to"
|
|
|
|
buildEventFlag = "build.event"
|
|
|
|
buildFailedStagesFlag = "build.failed-stages"
|
|
|
|
buildFailedStepsFlag = "build.failed-steps"
|
|
|
|
buildFinishedFlag = "build.finished"
|
|
|
|
buildNumberFlag = "build.number"
|
|
|
|
buildParentFlag = "build.parent"
|
|
|
|
buildPullRequestFlag = "build.pull-request"
|
|
|
|
buildSourceBranchFlag = "build.source-branch"
|
|
|
|
buildStartedFlag = "build.started"
|
|
|
|
buildStatusFlag = "build.status"
|
|
|
|
buildTagFlag = "build.tag"
|
|
|
|
buildTargetBranchFlag = "build.target-branch"
|
2019-09-10 00:03:55 +00:00
|
|
|
)
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// buildFlags has the cli.Flags for the plugin.Build.
|
|
|
|
func buildFlags() []cli.Flag {
|
2019-09-10 00:03:55 +00:00
|
|
|
return []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildActionFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build action",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildActionEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildCreatedFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build created",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildCreatedEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildDeployToFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build deploy to",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildDeployToEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildEventFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build event",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildEventEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringSliceFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildFailedStagesFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build failed stages",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildFailedStagesEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringSliceFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildFailedStepsFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build failed steps",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildFailedStepsEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildFinishedFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build finished",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildFinishedEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.IntFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildNumberFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build number",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildNumberEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.IntFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildParentFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build parent",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildParentEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.IntFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildPullRequestFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build pull request",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildPullRequestEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildSourceBranchFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build source branch",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildSourceBranchEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildStartedFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build started",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildStartedEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildStatusFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build status",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildStatusEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildTagFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build tag",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildTagEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: buildTargetBranchFlag,
|
2019-09-10 00:03:55 +00:00
|
|
|
Usage: "build target branch",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.BuildTargetBranchEnvVar,
|
2019-09-10 00:03:55 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// buildFromContext creates a plugin.Build from the cli.Context.
|
|
|
|
func buildFromContext(ctx *cli.Context) plugin.Build {
|
2019-09-10 00:03:55 +00:00
|
|
|
return plugin.Build{
|
2019-10-10 20:36:20 +00:00
|
|
|
Action: ctx.String(buildActionFlag),
|
|
|
|
Created: time.Unix(ctx.Int64(buildCreatedFlag), 0),
|
|
|
|
DeployTo: ctx.String(buildDeployToFlag),
|
|
|
|
Event: ctx.String(buildEventFlag),
|
|
|
|
FailedStages: ctx.StringSlice(buildFailedStagesFlag),
|
|
|
|
FailedSteps: ctx.StringSlice(buildFailedStepsFlag),
|
|
|
|
Finished: time.Unix(ctx.Int64(buildFinishedFlag), 0),
|
|
|
|
Number: ctx.Int(buildNumberFlag),
|
|
|
|
Parent: ctx.Int(buildParentFlag),
|
|
|
|
PullRequest: ctx.Int(buildPullRequestFlag),
|
|
|
|
SourceBranch: ctx.String(buildSourceBranchFlag),
|
|
|
|
Started: time.Unix(ctx.Int64(buildStartedFlag), 0),
|
|
|
|
Status: ctx.String(buildStatusFlag),
|
|
|
|
Tag: ctx.String(buildTagFlag),
|
|
|
|
TargetBranch: ctx.String(buildTargetBranchFlag),
|
2019-09-10 00:03:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 21:02:13 +00:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// Repo Flags
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
const (
|
2019-10-10 20:36:20 +00:00
|
|
|
repoDefaultBranchFlag = "repo.branch"
|
|
|
|
repoFullNameFlag = "repo.full-name"
|
|
|
|
repoLinkFlag = "repo.link"
|
|
|
|
repoNameFlag = "repo.name"
|
|
|
|
repoOwnerFlag = "repo.owner"
|
|
|
|
repoPrivateFlag = "repo.private"
|
|
|
|
repoRemoteURLFlag = "repo.remote-url"
|
|
|
|
repoSCMFlag = "repo.scm"
|
|
|
|
repoVisibilityFlag = "repo.visibility"
|
2019-09-09 21:02:13 +00:00
|
|
|
)
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// repoFlags has the cli.Flags for the plugin.Repo
|
|
|
|
func repoFlags() []cli.Flag {
|
2019-09-09 21:02:13 +00:00
|
|
|
return []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoDefaultBranchFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo default branch",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoDefaultBranchEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoFullNameFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo full name",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoFullNameEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoLinkFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo link",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoLinkEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoNameFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo name",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoNameEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoOwnerFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo owner",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoOwnerEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoPrivateFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo private",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoPrivateEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoRemoteURLFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo remote url",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoRemoteURLEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoSCMFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo scm",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoSCMEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: repoVisibilityFlag,
|
2019-09-09 21:02:13 +00:00
|
|
|
Usage: "repo visibility",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.RepoVisibilityEnvVar,
|
2019-09-09 21:02:13 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// repoFromContext creates a plugin.Repo from the cli.Context.
|
|
|
|
func repoFromContext(ctx *cli.Context) plugin.Repo {
|
2019-09-09 21:02:13 +00:00
|
|
|
return plugin.Repo{
|
2019-10-10 20:36:20 +00:00
|
|
|
DefaultBranch: ctx.String(repoDefaultBranchFlag),
|
|
|
|
FullName: ctx.String(repoFullNameFlag),
|
|
|
|
Link: ctx.String(repoLinkFlag),
|
|
|
|
Name: ctx.String(repoNameFlag),
|
|
|
|
Owner: ctx.String(repoOwnerFlag),
|
|
|
|
Private: ctx.Bool(repoPrivateFlag),
|
|
|
|
RemoteURL: ctx.String(repoRemoteURLFlag),
|
|
|
|
SCM: ctx.String(repoSCMFlag),
|
|
|
|
Visibility: ctx.String(repoVisibilityFlag),
|
2019-09-09 21:02:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 23:27:59 +00:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// Commit Flags
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
const (
|
2019-10-10 20:36:20 +00:00
|
|
|
commitAfterFlag = "commit.after"
|
|
|
|
commitAuthorFlag = "commit.author"
|
|
|
|
commitAuthorAvatarFlag = "commit.author-avatar"
|
|
|
|
commitAuthorEmailFlag = "commit.author-email"
|
|
|
|
commitAuthorNameFlag = "commit.author-name"
|
|
|
|
commitBeforeFlag = "commit.before"
|
|
|
|
commitBranchFlag = "commit.branch"
|
|
|
|
commitLinkFlag = "commit.link"
|
|
|
|
commitMessageFlag = "commit.message"
|
|
|
|
commitRefFlag = "commit.ref"
|
|
|
|
commitSHAFlag = "commit.sha"
|
2019-09-09 23:27:59 +00:00
|
|
|
)
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// commitFlags has the cli.Flags for the plugin.Commit.
|
|
|
|
func commitFlags() []cli.Flag {
|
2019-09-09 23:27:59 +00:00
|
|
|
return []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitAfterFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit after",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitAfterEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitAuthorFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit author",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitAuthorEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitAuthorAvatarFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit author avatar",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitAuthorAvatarEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitAuthorEmailFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit author email",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitAuthorEmailEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitAuthorNameFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit author name",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitAuthorNameEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitBeforeFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit before",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitBeforeEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitBranchFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit branch",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitBranchEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitLinkFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit link",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitLinkEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitMessageFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit message",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitMessageEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitRefFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit ref",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitRefEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: commitSHAFlag,
|
2019-09-09 23:27:59 +00:00
|
|
|
Usage: "commit sha",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.CommitSHAEnvVar,
|
2019-09-09 23:27:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// commitFromContext creates a plugin.Commit from the cli.Context.
|
|
|
|
func commitFromContext(ctx *cli.Context) plugin.Commit {
|
2019-09-09 23:27:59 +00:00
|
|
|
return plugin.Commit{
|
2019-10-10 20:36:20 +00:00
|
|
|
After: ctx.String(commitAfterFlag),
|
|
|
|
Author: ctx.String(commitAuthorFlag),
|
|
|
|
AuthorAvatar: ctx.String(commitAuthorAvatarFlag),
|
|
|
|
AuthorEmail: ctx.String(commitAuthorEmailFlag),
|
|
|
|
AuthorName: ctx.String(commitAuthorNameFlag),
|
|
|
|
Before: ctx.String(commitBeforeFlag),
|
|
|
|
Branch: ctx.String(commitBranchFlag),
|
|
|
|
Link: ctx.String(commitLinkFlag),
|
|
|
|
Message: ctx.String(commitMessageFlag),
|
|
|
|
Ref: ctx.String(commitRefFlag),
|
|
|
|
SHA: ctx.String(commitSHAFlag),
|
2019-09-09 23:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-07 00:13:21 +00:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// Stage Flags
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
const (
|
2019-10-10 20:36:20 +00:00
|
|
|
stageArchFlag = "stage.arch"
|
|
|
|
stageDependsOnFlag = "stage.depends-on"
|
|
|
|
stageFinishedFlag = "stage.finished"
|
|
|
|
stageKindFlag = "stage.kind"
|
|
|
|
stageMachineFlag = "stage.machine"
|
|
|
|
stageNameFlag = "stage.name"
|
|
|
|
stageNumberFlag = "stage.number"
|
|
|
|
stageOSFlag = "stage.os"
|
|
|
|
stageStartedFlag = "stage.started"
|
|
|
|
stageStatusFlag = "stage.status"
|
|
|
|
stageTypeFlag = "stage.type"
|
|
|
|
stageVariantFlag = "stage.variant"
|
|
|
|
stageVersionFlag = "stage.version"
|
2019-09-07 00:13:21 +00:00
|
|
|
)
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// stageFlags has the cli.Flags for the plugin.Stage
|
|
|
|
func stageFlags() []cli.Flag {
|
2019-09-07 00:13:21 +00:00
|
|
|
return []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageArchFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage arch",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageArchEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
},
|
|
|
|
cli.StringSliceFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageDependsOnFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage depends on",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageDependsOnEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
},
|
|
|
|
cli.Int64Flag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageFinishedFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage finished",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageFinishedEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageKindFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage kind",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageKindEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageMachineFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage machine",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageMachineEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageNameFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage name",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageNameEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.IntFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageNumberFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage number",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageNumberEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageOSFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage os",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageOSEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.Int64Flag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageStartedFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage started",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageStartedEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageStatusFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage status",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageStatusEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageTypeFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage type",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageTypeEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageVariantFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage variant",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageVariantEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
}, cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stageVersionFlag,
|
2019-09-07 00:13:21 +00:00
|
|
|
Usage: "stage version",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StageVersionEnvVar,
|
2019-09-07 00:13:21 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// stageFromContext creates a plugin.Stage from the cli.Context.
|
|
|
|
func stageFromContext(ctx *cli.Context) plugin.Stage {
|
2019-09-07 00:13:21 +00:00
|
|
|
return plugin.Stage{
|
2019-10-10 20:36:20 +00:00
|
|
|
Arch: ctx.String(stageArchFlag),
|
|
|
|
DependsOn: ctx.StringSlice(stageDependsOnFlag),
|
|
|
|
Finished: time.Unix(ctx.Int64(stageFinishedFlag), 0),
|
|
|
|
Kind: ctx.String(stageKindFlag),
|
|
|
|
Machine: ctx.String(stageMachineFlag),
|
|
|
|
Name: ctx.String(stageNameFlag),
|
|
|
|
Number: ctx.Int(stageNumberFlag),
|
|
|
|
OS: ctx.String(stageOSFlag),
|
|
|
|
Started: time.Unix(ctx.Int64(stageStartedFlag), 0),
|
|
|
|
Status: ctx.String(stageStatusFlag),
|
|
|
|
Type: ctx.String(stageTypeFlag),
|
|
|
|
Variant: ctx.String(stageVariantFlag),
|
|
|
|
Version: ctx.String(stageVersionFlag),
|
2019-09-07 00:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 23:34:27 +00:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// Step Flags
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
const (
|
2019-10-10 20:36:20 +00:00
|
|
|
// stepNameFlag corresponds to plugin.Step.Name.
|
|
|
|
stepNameFlag = "step.name"
|
|
|
|
// stepNumberFlag corresponds to plugin.Step.Number.
|
|
|
|
stepNumberFlag = "step.number"
|
2019-09-06 23:34:27 +00:00
|
|
|
)
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// stepFlags has the cli.Flags for the plugin.Step.
|
|
|
|
func stepFlags() []cli.Flag {
|
2019-09-06 23:34:27 +00:00
|
|
|
return []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stepNameFlag,
|
2019-09-06 23:34:27 +00:00
|
|
|
Usage: "step name",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StepNameEnvVar,
|
2019-09-06 23:34:27 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: stepNumberFlag,
|
2019-09-06 23:34:27 +00:00
|
|
|
Usage: "step number",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.StepNumberEnvVar,
|
2019-09-06 23:34:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// stepFromContext creates a plugin.Step from the cli.Context.
|
|
|
|
func stepFromContext(ctx *cli.Context) plugin.Step {
|
2019-09-06 23:34:27 +00:00
|
|
|
return plugin.Step{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: ctx.String(stepNameFlag),
|
|
|
|
Number: ctx.Int(stepNumberFlag),
|
2019-09-06 23:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-09 21:27:12 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
// SemVer Flags
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
|
|
|
|
const (
|
2019-10-10 20:36:20 +00:00
|
|
|
semVerBuildFlag = "semver.build"
|
|
|
|
semVerErrorFlag = "semver.error"
|
|
|
|
semVerMajorFlag = "semver.major"
|
|
|
|
semVerMinorFlag = "semver.minor"
|
|
|
|
semVerPatchFlag = "semver.patch"
|
|
|
|
semVerPrereleaseFlag = "semver.prerelease"
|
|
|
|
semVerShortFlag = "semver.short"
|
|
|
|
semVerVersionFlag = "semver.version"
|
2019-09-09 21:27:12 +00:00
|
|
|
)
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// semVerFlags has the cli.Flags for the plugin.SemVer.
|
|
|
|
func semVerFlags() []cli.Flag {
|
2019-09-09 21:27:12 +00:00
|
|
|
return []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: semVerBuildFlag,
|
2019-09-09 21:27:12 +00:00
|
|
|
Usage: "semver build",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.SemVerBuildEnvVar,
|
2019-09-09 21:27:12 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: semVerErrorFlag,
|
2019-09-09 21:27:12 +00:00
|
|
|
Usage: "semver error",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.SemVerErrorEnvVar,
|
2019-09-09 21:27:12 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: semVerMajorFlag,
|
2019-09-09 21:27:12 +00:00
|
|
|
Usage: "semver major",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.SemVerMajorEnvVar,
|
2019-09-09 21:27:12 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: semVerMinorFlag,
|
2019-09-09 21:27:12 +00:00
|
|
|
Usage: "semver minor",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.SemVerMinorEnvVar,
|
2019-09-09 21:27:12 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: semVerPatchFlag,
|
2019-09-09 21:27:12 +00:00
|
|
|
Usage: "semver patch",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.SemVerPatchEnvVar,
|
2019-09-09 21:27:12 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: semVerPrereleaseFlag,
|
2019-09-09 21:27:12 +00:00
|
|
|
Usage: "semver prerelease",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.SemVerPrereleaseEnvVar,
|
2019-09-09 21:27:12 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: semVerShortFlag,
|
2019-09-09 21:27:12 +00:00
|
|
|
Usage: "semver short",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.SemVerShortEnvVar,
|
2019-09-09 21:27:12 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2019-10-10 20:36:20 +00:00
|
|
|
Name: semVerVersionFlag,
|
2019-09-09 21:27:12 +00:00
|
|
|
Usage: "semver version",
|
2019-10-10 19:59:12 +00:00
|
|
|
EnvVar: environ.SemVerVersionEnvVar,
|
2019-09-09 21:27:12 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 20:36:20 +00:00
|
|
|
// semVerFromContext creates a plugin.Step from the cli.Context.
|
|
|
|
func semVerFromContext(ctx *cli.Context) plugin.SemVer {
|
2019-09-09 21:27:12 +00:00
|
|
|
return plugin.SemVer{
|
2019-10-10 20:36:20 +00:00
|
|
|
Build: ctx.String(semVerBuildFlag),
|
|
|
|
Error: ctx.String(semVerErrorFlag),
|
|
|
|
Major: ctx.String(semVerMajorFlag),
|
|
|
|
Minor: ctx.String(semVerMinorFlag),
|
|
|
|
Patch: ctx.String(semVerPatchFlag),
|
|
|
|
Prerelease: ctx.String(semVerPrereleaseFlag),
|
|
|
|
Short: ctx.String(semVerShortFlag),
|
|
|
|
Version: ctx.String(semVerVersionFlag),
|
2019-09-09 21:27:12 +00:00
|
|
|
}
|
|
|
|
}
|