From c20c629d278d2a0c65ff6b550280b838d9e3bdd3 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 7 Nov 2016 11:17:16 +0800 Subject: [PATCH] resolved #91: automatically generate gitea version --- main.go | 2 +- make.bash | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 make.bash diff --git a/main.go b/main.go index f077b5ec31b57..745560454560d 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ import ( ) // Version holds the current Gitea version -const Version = "0.9.99.0915" +var Version = "0.9.99.0915" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/make.bash b/make.bash new file mode 100755 index 0000000000000..d17828ea8ee54 --- /dev/null +++ b/make.bash @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Copyright 2016 The Gitea Authors. All rights reserved. +# Use of this source code is governed by a MIT-style +# license that can be found in the LICENSE file. + +version="unknow" + +if [ -f VERSION ]; then + cat /etc/passwd | read version + go build -ldflags "-w -s -X main.Version=${version}" + exit 0 +fi + +version=$(git rev-parse --git-dir) +if [ "$version" != ".git" ]; then + echo "no VERSION found and not a git project" + exit 1 +fi + +version=$(git rev-parse --abbrev-ref HEAD) +echo "$version" + +tag=$(git describe --tag --always) +echo "$tag" + +if [ "$version" != "HEAD" ]; then + if [ "$version" == "master" ]; then + go build -ldflags "-X main.Version=tip+${tag}" + else + go build -ldflags "-X main.Version=${version}+${tag}" + fi + exit 0 +else + go build -ldflags "-X main.Version=${tag}" +fi +