Add all variables based on the makefile
This commit is contained in:
parent
1ff0fc6085
commit
65cdb76d0f
54
magefile.go
54
magefile.go
|
@ -23,21 +23,26 @@ import (
|
|||
"github.com/magefile/mage/mg"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
PACKAGE = `code.vikunja.io/api`
|
||||
EXECUTABLE = `vikunja`
|
||||
PACKAGE = `code.vikunja.io/api`
|
||||
DIST = `dist`
|
||||
)
|
||||
|
||||
var (
|
||||
Goflags = []string{
|
||||
"-v",
|
||||
}
|
||||
Ldflags = ""
|
||||
Tags = ""
|
||||
Version = "dev"
|
||||
Executable = "vikunja"
|
||||
Ldflags = ""
|
||||
Tags = ""
|
||||
VersionNumber = "dev"
|
||||
Version = "master" // This holds the built version, master by default, when building from a tag or release branch, their name
|
||||
BinLocation = ""
|
||||
PkgVersion = "master"
|
||||
)
|
||||
|
||||
func setVersion() {
|
||||
|
@ -47,15 +52,44 @@ func setVersion() {
|
|||
fmt.Printf("Error getting version: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
Version = strings.Trim(string(version), "\n")
|
||||
Version = strings.Replace(Version, "-", "+", 1)
|
||||
Version = strings.Replace(Version, "-g", "-", 1)
|
||||
VersionNumber = strings.Trim(string(version), "\n")
|
||||
VersionNumber = strings.Replace(VersionNumber, "-", "+", 1)
|
||||
VersionNumber = strings.Replace(VersionNumber, "-g", "-", 1)
|
||||
|
||||
if os.Getenv("DRONE_TAG") != "" {
|
||||
Version = os.Getenv("DRONE_TAG")
|
||||
} else if os.Getenv("DRONE_BRANCH") != "" {
|
||||
Version = strings.Replace(os.Getenv("DRONE_BRANCH"), "release/v", "", 1)
|
||||
}
|
||||
}
|
||||
|
||||
func setBinLocation() {
|
||||
if os.Getenv("DRONE_WORKSPACE") != "" {
|
||||
BinLocation = DIST + `/binaries/` + Executable + `-` + Version + `-linux-amd64`
|
||||
} else {
|
||||
BinLocation = Executable
|
||||
}
|
||||
}
|
||||
|
||||
func setPkgVersion() {
|
||||
if Version == "master" {
|
||||
PkgVersion = VersionNumber
|
||||
}
|
||||
}
|
||||
|
||||
func setExecutable() {
|
||||
if runtime.GOOS == "windows" {
|
||||
Executable += ".exe"
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
Tags = os.Getenv("TAGS")
|
||||
setVersion()
|
||||
Ldflags = `-X "` + PACKAGE + `/pkg/version.Version=` + Version + `" -X "main.Tags=` + Tags + `"`
|
||||
setExecutable()
|
||||
setBinLocation()
|
||||
setPkgVersion()
|
||||
Ldflags = `-X "` + PACKAGE + `/pkg/version.VersionNumber=` + VersionNumber + `" -X "main.Tags=` + Tags + `"`
|
||||
}
|
||||
|
||||
// Generates static content into the final binary
|
||||
|
@ -66,7 +100,7 @@ func Generate() error {
|
|||
// Builds a vikunja binary, ready to run.
|
||||
func Build() error {
|
||||
mg.Deps(Generate)
|
||||
cmd := exec.Command("go", "build", Goflags[0], "-tags", Tags, "-ldflags", "-s -w "+Ldflags, "-o", EXECUTABLE)
|
||||
cmd := exec.Command("go", "build", Goflags[0], "-tags", Tags, "-ldflags", "-s -w "+Ldflags, "-o", Executable)
|
||||
fmt.Println(cmd.String())
|
||||
out, err := cmd.CombinedOutput()
|
||||
fmt.Print(string(out))
|
||||
|
|
|
@ -20,4 +20,4 @@ package version
|
|||
// It is an own package to avoid import cycles
|
||||
|
||||
// Version sets the version to be printed to the user. Gets overwritten by "make release" or "make build" with last git commit or tag.
|
||||
var Version = "0.7"
|
||||
var Version = "dev"
|
||||
|
|
Loading…
Reference in New Issue