diff --git a/go.mod b/go.mod index 56e11f948..862221cb3 100644 --- a/go.mod +++ b/go.mod @@ -46,6 +46,7 @@ require ( github.com/labstack/gommon v0.3.0 github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef github.com/lib/pq v1.8.0 + github.com/magefile/mage v1.10.0 github.com/mailru/easyjson v0.7.0 // indirect github.com/mattn/go-sqlite3 v1.14.0 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect diff --git a/go.sum b/go.sum index 94ce6675f..b037ee3a9 100644 --- a/go.sum +++ b/go.sum @@ -421,6 +421,8 @@ github.com/lib/pq v1.6.0 h1:I5DPxhYJChW9KYc66se+oKFFQX6VuQrKiprsX6ivRZc= github.com/lib/pq v1.6.0/go.mod h1:4vXEAYvW1fRQ2/FhZ78H73A60MHw1geSm145z2mdY1g= github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg= github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= +github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= diff --git a/magefile.go b/magefile.go new file mode 100644 index 000000000..a19679eab --- /dev/null +++ b/magefile.go @@ -0,0 +1,66 @@ +// Vikunja is a to-do list application to facilitate your life. +// Copyright 2018-2020 Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +build mage + +package main + +import ( + "fmt" + "os" + "os/exec" + "strings" + + "github.com/magefile/mage/mg" +) + +const ( + PACKAGE = `code.vikunja.io/api` + EXECUTABLE = `vikunja` +) + +var ( + Goflags = []string{ + "-v", + } + Ldflags = "" + Tags = "" + Version = "dev" +) + +func init() { + Tags = os.Getenv("Tags") + versionCmd := exec.Command("git", "describe", "--tags", "--always", "--abbrev=10") //, " | sed 's/-/+/'", " | sed 's/^v//'", " | sed 's/-g/-/'") + version, err := versionCmd.Output() + if err != nil { + fmt.Printf("Error getting version: %s\n", err) + os.Exit(1) + } + Version = strings.Trim(string(version), "\n") + fmt.Printf("Version: %s\n", Version) + Ldflags = `-X "` + PACKAGE + `/pkg/version.Version=` + Version + `" -X "main.Tags=` + Tags + `"` +} + +// Generates static content into the final binary +func Generate() error { + return exec.Command("go", "generate", PACKAGE+"/pkg/static").Run() +} + +func Build() error { + mg.Deps(Generate) + out, err := exec.Command("go", "build", Goflags[0], "-tags", Tags, "-ldflags", "-s -w "+Ldflags, "-o", EXECUTABLE).CombinedOutput() + fmt.Print(string(out)) + return err +} diff --git a/tools.go b/tools.go index 7939f705a..dc946db17 100644 --- a/tools.go +++ b/tools.go @@ -33,4 +33,6 @@ import ( _ "honnef.co/go/tools/cmd/staticcheck" _ "github.com/shurcooL/vfsgen" + + _ "github.com/magefile/mage" )