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

Add SemVer struct

This commit is contained in:
Don 2019-09-09 14:26:56 -07:00
parent 364de76c24
commit 353ef0da17
2 changed files with 61 additions and 0 deletions

View File

@ -88,6 +88,27 @@ const (
StepNameEnvVar = "DRONE_STEP_NAME" StepNameEnvVar = "DRONE_STEP_NAME"
// StepNumberEnvVar corresponds to Step.Number. // StepNumberEnvVar corresponds to Step.Number.
StepNumberEnvVar = "DRONE_STEP_NUMBER" StepNumberEnvVar = "DRONE_STEP_NUMBER"
//---------------------------------------------------------------------
// SemVer Variables
//---------------------------------------------------------------------
// SemVerBuildEnvVar corresponds to SemVer.Build.
SemVerBuildEnvVar = "DRONE_SEMVER_BUILD"
// SemVerErrorEnvVar corresponds to SemVer.Error.
SemVerErrorEnvVar = "DRONE_SEMVER_ERROR"
// SemVerMajorEnvVar corresponds to SemVer.Major.
SemVerMajorEnvVar = "DRONE_SEMVER_MAJOR"
// SemVerMinorEnvVar corresponds to SemVer.Minor.
SemVerMinorEnvVar = "DRONE_SEMVER_MINOR"
// SemVerPatchEnvVar corresponds to SemVer.Patch.
SemVerPatchEnvVar = "DRONE_SEMVER_PATCH"
// SemVerPrereleaseEnvVar corresponds to SemVer.Prerelease
SemVerPrereleaseEnvVar = "DRONE_SEMVER_PRERELEASE"
// SemVerShortEnvVar corresponds to SemVer.Short.
SemVerShortEnvVar = "DRONE_SEMVER_SHORT"
// SemVerVersionEnvVar corresponds to SemVer.Version
SemVerVersionEnvVar = "DRONE_SEMVER"
) )
// StringEnvVar gets the environment variable's value. // StringEnvVar gets the environment variable's value.

View File

@ -99,6 +99,32 @@ type (
Name string Name string
Number int Number int
} }
// SemVer represents the semantic version of the currently running build.
//
// This value is only applicable for tags. If the tag cannot be parsed into
// a semantic version then SemVer.Error will have the reason.
SemVer struct {
// Build version number.
//
// This is signified by a + at the end of the tag.
Build string
// Error is the semantic version parsing error if the tag was invalid.
Error string
// Major version number.
Major string
// Minor version number.
Minor string
// Patch version number.
Patch string
// Prerelease version.
Prerelease string
// Short version of the semantic version string where labels and
// metadata are truncated.
Short string
// Version is the full semantic version.
Version string
}
) )
// RepoFromEnv creates a Repo from the environment variables used by Drone. // RepoFromEnv creates a Repo from the environment variables used by Drone.
@ -142,3 +168,17 @@ func StepFromEnv() Step {
Number: IntEnvVar(StepNumberEnvVar), Number: IntEnvVar(StepNumberEnvVar),
} }
} }
// SemVerFromEnv creates a SemVer from the environment variables used by Drone.
func SemVerFromEnv() SemVer {
return SemVer{
Build: StringEnvVar(SemVerBuildEnvVar),
Error: StringEnvVar(SemVerErrorEnvVar),
Major: StringEnvVar(SemVerMajorEnvVar),
Minor: StringEnvVar(SemVerMinorEnvVar),
Patch: StringEnvVar(SemVerPatchEnvVar),
Prerelease: StringEnvVar(SemVerPrereleaseEnvVar),
Short: StringEnvVar(SemVerShortEnvVar),
Version: StringEnvVar(SemVerVersionEnvVar),
}
}