move version to package

This commit is contained in:
Brad Rydzewski 2016-03-30 00:48:47 -07:00
parent 8a6857a74b
commit f9bba48e19
4 changed files with 25 additions and 14 deletions

View file

@ -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)

View file

@ -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_),

View file

@ -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)
func Version(c *gin.Context) {
c.Header("X-DRONE-VERSION", version.Version)
c.Next()
}
}

19
version/version.go Normal file
View file

@ -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)