From f9bba48e19d60ec42873ed8236c7549dc340c313 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 30 Mar 2016 00:48:47 -0700 Subject: [PATCH] move version to package --- Makefile | 2 +- drone.go | 6 +----- router/middleware/header/header.go | 12 ++++-------- version/version.go | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 version/version.go diff --git a/Makefile b/Makefile index 35db24485..3e40fc790 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ build: go build build_static: - go build --ldflags '-extldflags "-static" -X main.build=$(CI_BUILD_NUMBER)' -o drone_static + go build --ldflags '-extldflags "-static" -X github.com/drone/drone/version.VersionDev=$(CI_BUILD_NUMBER)' -o drone_static test: go test -cover $(PACKAGES) diff --git a/drone.go b/drone.go index 60237765c..c92281aab 100644 --- a/drone.go +++ b/drone.go @@ -16,10 +16,6 @@ import ( "github.com/Sirupsen/logrus" ) -// build revision number populated by the continuous -// integration server at compile time. -var build string = "custom" - var ( dotenv = flag.String("config", ".env", "") debug = flag.Bool("debug", false, "") @@ -49,7 +45,7 @@ func main() { server_ := server.Load(env) server_.Run( router.Load( - header.Version(build), + header.Version, cache.Default(), context.SetStore(store_), context.SetRemote(remote_), diff --git a/router/middleware/header/header.go b/router/middleware/header/header.go index 577d7a7db..d259431c7 100644 --- a/router/middleware/header/header.go +++ b/router/middleware/header/header.go @@ -4,11 +4,10 @@ import ( "net/http" "time" + "github.com/drone/drone/version" "github.com/gin-gonic/gin" ) -var version string - // NoCache is a middleware function that appends headers // to prevent the client from caching the HTTP response. func NoCache(c *gin.Context) { @@ -52,10 +51,7 @@ func Secure(c *gin.Context) { // Version is a middleware function that appends the Drone // version information to the HTTP response. This is intended // for debugging and troubleshooting. -func Version(version string) gin.HandlerFunc { - return func(c *gin.Context) { - c.Set("version", "0.4.0-beta+"+version) - c.Header("X-DRONE-VERSION", "0.4.0-beta+"+version) - c.Next() - } +func Version(c *gin.Context) { + c.Header("X-DRONE-VERSION", version.Version) + c.Next() } diff --git a/version/version.go b/version/version.go new file mode 100644 index 000000000..4a15c723b --- /dev/null +++ b/version/version.go @@ -0,0 +1,19 @@ +package version + +import "fmt" + +const ( + // VersionMajor is for an API incompatible changes + VersionMajor = 0 + // VersionMinor is for functionality in a backwards-compatible manner + VersionMinor = 4 + // VersionPatch is for backwards-compatible bug fixes + VersionPatch = 1 + + // VersionDev indicates development branch. Releases will be empty string. + VersionDev = "dev" +) + +// Version is the specification version that the package types support. +var Version = fmt.Sprintf("%d.%d.%d+%s", + VersionMajor, VersionMinor, VersionPatch, VersionDev)