diff --git a/drone/calver.go b/drone/calver.go new file mode 100644 index 0000000..208a535 --- /dev/null +++ b/drone/calver.go @@ -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 +} diff --git a/drone/pipeline.go b/drone/pipeline.go index d072823..17f1fa1 100644 --- a/drone/pipeline.go +++ b/drone/pipeline.go @@ -15,5 +15,6 @@ type Pipeline struct { Stage Stage Step Step SemVer SemVer + CalVer CalVer System System } diff --git a/urfave/calver.go b/urfave/calver.go new file mode 100644 index 0000000..69e9709 --- /dev/null +++ b/urfave/calver.go @@ -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"), + } +} diff --git a/urfave/urfave.go b/urfave/urfave.go index 58aba2f..370d087 100644 --- a/urfave/urfave.go +++ b/urfave/urfave.go @@ -20,6 +20,7 @@ func Flags() []cli.Flag { flags = append(flags, stageFlags()...) flags = append(flags, stepFlags()...) flags = append(flags, semVerFlags()...) + flags = append(flags, calVerFlags()...) flags = append(flags, systemFlags()...) flags = append(flags, networkFlags()...) flags = append(flags, loggingFlags()...) @@ -36,6 +37,7 @@ func PipelineFromContext(ctx *cli.Context) drone.Pipeline { Stage: stageFromContext(ctx), Step: stepFromContext(ctx), SemVer: semVerFromContext(ctx), + CalVer: calVerFromContext(ctx), System: systemFromContext(ctx), } }