From 8dee34878d1df0592c03d1ddd964aebf65dda99e Mon Sep 17 00:00:00 2001 From: Laszlo Fogas Date: Tue, 12 Nov 2019 21:08:17 +0100 Subject: [PATCH] Version is now a string coming from ldlags and git tags --- .drone.sh | 8 ++++---- .vscode/launch.json | 16 ++++++++++++++++ Makefile | 2 +- cmd/drone-server/main.go | 4 +++- go.mod | 1 - go.sum | 2 -- router/middleware/header/header.go | 9 --------- router/middleware/version.go | 2 +- server/web/web.go | 4 ++-- server/z.go | 2 +- version/version.go | 30 ++++++++++-------------------- web/src/screens/feed/index.js | 11 ++++------- 12 files changed, 42 insertions(+), 49 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.drone.sh b/.drone.sh index 029a2a7f3..19197831e 100755 --- a/.drone.sh +++ b/.drone.sh @@ -3,7 +3,7 @@ set -e set -x -go build -ldflags '-extldflags "-static" -X github.com/laszlocph/woodpecker/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/drone-server github.com/laszlocph/woodpecker/cmd/drone-server -GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-X github.com/laszlocph/woodpecker/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/drone-agent github.com/laszlocph/woodpecker/cmd/drone-agent -GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags '-X github.com/laszlocph/woodpecker/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/linux/arm64/drone-agent github.com/laszlocph/woodpecker/cmd/drone-agent -GOOS=linux GOARCH=arm CGO_ENABLED=0 GOARM=7 go build -ldflags '-X github.com/laszlocph/woodpecker/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/linux/arm/drone-agent github.com/laszlocph/woodpecker/cmd/drone-agent +go build -ldflags '-extldflags "-static" -X github.com/laszlocph/woodpecker/version.Version='${DRONE_TAG} -o release/drone-server github.com/laszlocph/woodpecker/cmd/drone-server +GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-X github.com/laszlocph/woodpecker/version.Version='${DRONE_TAG} -o release/drone-agent github.com/laszlocph/woodpecker/cmd/drone-agent +GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags '-X github.com/laszlocph/woodpecker/version.Version='${DRONE_TAG} -o release/linux/arm64/drone-agent github.com/laszlocph/woodpecker/cmd/drone-agent +GOOS=linux GOARCH=arm CGO_ENABLED=0 GOARM=7 go build -ldflags '-X github.com/laszlocph/woodpecker/version.Version='${DRONE_TAG} -o release/linux/arm/drone-agent github.com/laszlocph/woodpecker/cmd/drone-agent diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..5708cfcfa --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Woodpecker", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}/cmd/drone-server/main.go", + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index cbfa938b2..422e1569b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ GO_VERSION=1.12.4 -export GO111MODULE=off +export GO111MODULE=on GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*") DOCKER_RUN?= diff --git a/cmd/drone-server/main.go b/cmd/drone-server/main.go index 0548e9875..ecba5dce7 100644 --- a/cmd/drone-server/main.go +++ b/cmd/drone-server/main.go @@ -20,14 +20,16 @@ import ( "github.com/laszlocph/woodpecker/version" + "github.com/joho/godotenv" _ "github.com/joho/godotenv/autoload" "github.com/urfave/cli" ) func main() { + godotenv.Load(".env") app := cli.NewApp() app.Name = "drone-server" - app.Version = version.Version.String() + app.Version = version.String() app.Usage = "drone server" app.Action = server app.Flags = flags diff --git a/go.mod b/go.mod index 00e4be179..b888b69e7 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/Microsoft/go-winio v0.4.14 // indirect github.com/Sirupsen/logrus v0.10.0 github.com/beorn7/perks v1.0.0 // indirect - github.com/coreos/go-semver v0.0.0-20170209201757-5e3acbb5668c github.com/dgrijalva/jwt-go v0.0.0-20150904212456-c1da56349675 github.com/dimfeld/httptreemux v0.0.0-20170728181113-4faa6bbd32f9 github.com/docker/distribution v2.6.0-rc.1.0.20170112224556-c965e24c8cd2+incompatible // indirect diff --git a/go.sum b/go.sum index d3fcb7606..2b2445597 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/coreos/go-semver v0.0.0-20170209201757-5e3acbb5668c h1:+wuUamXDDSjSegI1+8PkeQ0oY7azHxu0jlLJ9Cc/oLE= -github.com/coreos/go-semver v0.0.0-20170209201757-5e3acbb5668c/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/router/middleware/header/header.go b/router/middleware/header/header.go index cfa29e2e7..571354604 100644 --- a/router/middleware/header/header.go +++ b/router/middleware/header/header.go @@ -19,7 +19,6 @@ import ( "time" "github.com/gin-gonic/gin" - "github.com/laszlocph/woodpecker/version" ) // NoCache is a middleware function that appends headers @@ -61,11 +60,3 @@ func Secure(c *gin.Context) { // Also consider adding Content-Security-Policy headers // c.Header("Content-Security-Policy", "script-src 'self' https://cdnjs.cloudflare.com") } - -// Version is a middleware function that appends the Drone -// version information to the HTTP response. This is intended -// for debugging and troubleshooting. -func Version(c *gin.Context) { - c.Header("X-DRONE-VERSION", version.Version.String()) - c.Next() -} diff --git a/router/middleware/version.go b/router/middleware/version.go index a7b7c6bc6..1a3c566c9 100644 --- a/router/middleware/version.go +++ b/router/middleware/version.go @@ -22,5 +22,5 @@ import ( // Version is a middleware function that appends the Drone version information // to the HTTP response. This is intended for debugging and troubleshooting. func Version(c *gin.Context) { - c.Header("X-DRONE-VERSION", version.Version.String()) + c.Header("X-DRONE-VERSION", version.String()) } diff --git a/server/web/web.go b/server/web/web.go index 9cc6aef51..995e31d3f 100644 --- a/server/web/web.go +++ b/server/web/web.go @@ -24,10 +24,10 @@ import ( "path/filepath" "time" - "github.com/laszlocph/woodpecker/web/dist" "github.com/laszlocph/woodpecker/model" "github.com/laszlocph/woodpecker/shared/token" "github.com/laszlocph/woodpecker/version" + "github.com/laszlocph/woodpecker/web/dist" "github.com/dimfeld/httptreemux" ) @@ -104,7 +104,7 @@ func (w *website) handleIndex(rw http.ResponseWriter, r *http.Request) { "user": user, "csrf": csrf, "syncing": syncing, - "version": version.Version.String(), + "version": version.String(), } rw.Header().Set("Content-Type", "text/html; charset=UTF-8") diff --git a/server/z.go b/server/z.go index 6dd9ea5f2..e7e35ced0 100644 --- a/server/z.go +++ b/server/z.go @@ -33,6 +33,6 @@ func Health(c *gin.Context) { func Version(c *gin.Context) { c.JSON(200, gin.H{ "source": "https://github.com/laszlocph/woodpecker", - "version": version.Version.String(), + "version": version.String(), }) } diff --git a/version/version.go b/version/version.go index a4353004d..12311591d 100644 --- a/version/version.go +++ b/version/version.go @@ -1,4 +1,4 @@ -// Copyright 2018 Drone.IO Inc. +// Copyright 2019 Laszlo Fogas // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,26 +14,16 @@ package version -import "github.com/coreos/go-semver/semver" - var ( - // VersionMajor is for an API incompatible changes. - VersionMajor int64 - // VersionMinor is for functionality in a backwards-compatible manner. - VersionMinor int64 = 8 - // VersionPatch is for backwards-compatible bug fixes. - VersionPatch int64 = 9 - // VersionPre indicates prerelease. - VersionPre string - // VersionDev indicates development branch. Releases will be empty string. - VersionDev string + // Version of Woodpecker, set with ldflags, from Git tag + Version string ) -// Version is the specification version that the package types support. -var Version = semver.Version{ - Major: VersionMajor, - Minor: VersionMinor, - Patch: VersionPatch, - PreRelease: semver.PreRelease(VersionPre), - Metadata: VersionDev, +// String returns the Version set at build time or "dev" +func String() string { + if Version == "" { + return "dev" + } + + return Version } diff --git a/web/src/screens/feed/index.js b/web/src/screens/feed/index.js index db9b866c5..71ac969b2 100644 --- a/web/src/screens/feed/index.js +++ b/web/src/screens/feed/index.js @@ -168,16 +168,13 @@ const LOGO = (

- Woodpecker
+ Woodpeckerv0.10.0
- yes,  - - it's a fork - + >Docs