0
0
mirror of https://github.com/thegeeklab/wp-plugin-go.git synced 2024-11-22 00:20:38 +00:00

Add CalVer support (#18)

This commit is contained in:
Don 2020-09-11 06:36:36 -07:00 committed by GitHub
parent 5113109fd1
commit 0ce4bf8655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 0 deletions

36
drone/calver.go Normal file
View File

@ -0,0 +1,36 @@
// Copyright (c) 2020, 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 drone
// CalVer represents the calendar version of the currently running build.
//
// This value is only applicable for tags. If the tag cannot be parsed into
// a calendar version then the value will be empty.
type CalVer struct {
// Version is the full calendar version.
Version string
// Major is the major version.
Major string
// Minor is the minor version.
Minor string
// Micro is the micro version.
Micro string
// Modifier is a modifier for the version.
Modifier string
// Short is the short version.
//
// This does not include the modifier.
Short string
}
func (c CalVer) String() string {
return c.Version
}

View File

@ -15,5 +15,6 @@ type Pipeline struct {
Stage Stage Stage Stage
Step Step Step Step
SemVer SemVer SemVer SemVer
CalVer CalVer
System System System System
} }

71
urfave/calver.go Normal file
View File

@ -0,0 +1,71 @@
// Copyright (c) 2020, 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
import (
"github.com/drone-plugins/drone-plugin-lib/drone"
"github.com/urfave/cli/v2"
)
// calVerFlags has the cli.Flags for the drone.CalVer.
func calVerFlags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "calver.version",
Usage: "calver version",
EnvVars: []string{
"DRONE_CALVER",
},
},
&cli.StringFlag{
Name: "calver.major",
Usage: "calver major",
EnvVars: []string{
"DRONE_CALVER_MAJOR",
},
},
&cli.StringFlag{
Name: "calver.minor",
Usage: "calver minor",
EnvVars: []string{
"DRONE_CALVER_MINOR",
},
},
&cli.StringFlag{
Name: "calver.micro",
Usage: "calver micro",
EnvVars: []string{
"DRONE_CALVER_MICRO",
},
},
&cli.StringFlag{
Name: "calver.modifier",
Usage: "calver modifier",
EnvVars: []string{
"DRONE_CALVER_MODIFIER",
},
},
&cli.StringFlag{
Name: "calver.short",
Usage: "calver short",
EnvVars: []string{
"DRONE_CALVER_SHORT",
},
},
}
}
// calVerFromContext creates a drone.CalVer from the cli.Context.
func calVerFromContext(ctx *cli.Context) drone.CalVer {
return drone.CalVer{
Version: ctx.String("calver.version"),
Major: ctx.String("calver.major"),
Minor: ctx.String("calver.minor"),
Micro: ctx.String("calver.micro"),
Modifier: ctx.String("calver.modifier"),
Short: ctx.String("calver.short"),
}
}

View File

@ -20,6 +20,7 @@ func Flags() []cli.Flag {
flags = append(flags, stageFlags()...) flags = append(flags, stageFlags()...)
flags = append(flags, stepFlags()...) flags = append(flags, stepFlags()...)
flags = append(flags, semVerFlags()...) flags = append(flags, semVerFlags()...)
flags = append(flags, calVerFlags()...)
flags = append(flags, systemFlags()...) flags = append(flags, systemFlags()...)
flags = append(flags, networkFlags()...) flags = append(flags, networkFlags()...)
flags = append(flags, loggingFlags()...) flags = append(flags, loggingFlags()...)
@ -36,6 +37,7 @@ func PipelineFromContext(ctx *cli.Context) drone.Pipeline {
Stage: stageFromContext(ctx), Stage: stageFromContext(ctx),
Step: stepFromContext(ctx), Step: stepFromContext(ctx),
SemVer: semVerFromContext(ctx), SemVer: semVerFromContext(ctx),
CalVer: calVerFromContext(ctx),
System: systemFromContext(ctx), System: systemFromContext(ctx),
} }
} }