Add all variables based on the makefile
This commit is contained in:
parent
1ff0fc6085
commit
65cdb76d0f
48
magefile.go
48
magefile.go
|
@ -23,21 +23,26 @@ import (
|
||||||
"github.com/magefile/mage/mg"
|
"github.com/magefile/mage/mg"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PACKAGE = `code.vikunja.io/api`
|
PACKAGE = `code.vikunja.io/api`
|
||||||
EXECUTABLE = `vikunja`
|
DIST = `dist`
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Goflags = []string{
|
Goflags = []string{
|
||||||
"-v",
|
"-v",
|
||||||
}
|
}
|
||||||
|
Executable = "vikunja"
|
||||||
Ldflags = ""
|
Ldflags = ""
|
||||||
Tags = ""
|
Tags = ""
|
||||||
Version = "dev"
|
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() {
|
func setVersion() {
|
||||||
|
@ -47,15 +52,44 @@ func setVersion() {
|
||||||
fmt.Printf("Error getting version: %s\n", err)
|
fmt.Printf("Error getting version: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
Version = strings.Trim(string(version), "\n")
|
VersionNumber = strings.Trim(string(version), "\n")
|
||||||
Version = strings.Replace(Version, "-", "+", 1)
|
VersionNumber = strings.Replace(VersionNumber, "-", "+", 1)
|
||||||
Version = strings.Replace(Version, "-g", "-", 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() {
|
func init() {
|
||||||
Tags = os.Getenv("TAGS")
|
Tags = os.Getenv("TAGS")
|
||||||
setVersion()
|
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
|
// Generates static content into the final binary
|
||||||
|
@ -66,7 +100,7 @@ func Generate() error {
|
||||||
// Builds a vikunja binary, ready to run.
|
// Builds a vikunja binary, ready to run.
|
||||||
func Build() error {
|
func Build() error {
|
||||||
mg.Deps(Generate)
|
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())
|
fmt.Println(cmd.String())
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
fmt.Print(string(out))
|
fmt.Print(string(out))
|
||||||
|
|
|
@ -20,4 +20,4 @@ package version
|
||||||
// It is an own package to avoid import cycles
|
// 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.
|
// 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
Block a user