Fix Version

This commit is contained in:
kolaente 2020-08-18 21:06:57 +02:00
parent fb8ac67d45
commit feacc1a323
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 11 additions and 6 deletions

View File

@ -13,17 +13,17 @@
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// +build mage
package main
import (
"fmt"
"github.com/magefile/mage/mg"
"os"
"os/exec"
"strings"
"github.com/magefile/mage/mg"
)
const (
@ -40,16 +40,21 @@ var (
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/-/'")
func setVersion() {
versionCmd := exec.Command("git", "describe", "--tags", "--always", "--abbrev=10")
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)
Version = strings.Replace(Version, "-", "+", 1)
Version = strings.Replace(Version, "-g", "-", 1)
}
func init() {
Tags = os.Getenv("TAGS")
setVersion()
Ldflags = `-X "` + PACKAGE + `/pkg/version.Version=` + Version + `" -X "main.Tags=` + Tags + `"`
}