Version is now a string coming from ldlags and git tags

This commit is contained in:
Laszlo Fogas 2019-11-12 21:08:17 +01:00
parent e509012e11
commit 8dee34878d
12 changed files with 42 additions and 49 deletions

View file

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

16
.vscode/launch.json vendored Normal file
View file

@ -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}"
}
]
}

View file

@ -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?=

View file

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

1
go.mod
View file

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

2
go.sum
View file

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

View file

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

View file

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

View file

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

View file

@ -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(),
})
}

View file

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

View file

@ -168,16 +168,13 @@ const LOGO = (
<div className={style.brand}>
<DroneIcon />
<p>
Woodpecker<br />
Woodpecker<span style="margin-left: 4px;">v0.10.0</span><br />
<span>
yes,&nbsp;
<a
href="https://github.com/laszlocph/drone-oss-08/"
<a
href="https://github.com/laszlocph/woodpecker/blob/master/docs/usage/pipeline.md"
target="_blank"
rel="noopener noreferrer"
>
it&#39;s a fork
</a>
>Docs</a>
</span>
</p>
</div>