Browse Source

Merge pull request #354 from eyakubovich/git-describe-version

build: use `git describe` output in version
Eugene Yakubovich 9 years ago
parent
commit
73863e6649
4 changed files with 25 additions and 7 deletions
  1. 18 1
      build
  2. 3 3
      dist/bump-release.sh
  3. 2 1
      main.go
  4. 2 2
      version/version.go

+ 18 - 1
build

@@ -1,7 +1,24 @@
 #!/bin/bash -e
 
+function linker_dashX {
+	local version=$(go version)
+	local regex="go([0-9]+).([0-9]+)."
+	if [[ $version =~ $regex ]]; then
+		if [ ${BASH_REMATCH[1]} -eq "1" -a ${BASH_REMATCH[2]} -le "4" ]; then
+			echo "$1 \"$2\""
+		else
+			echo "$1=$2"
+		fi
+	else
+		echo "could not determine Go version"
+		exit 1
+	fi
+}
+
 ORG_PATH="github.com/coreos"
 REPO_PATH="${ORG_PATH}/flannel"
+VERSION=$(git describe --dirty)
+GLDFLAGS="-X $(linker_dashX github.com/coreos/flannel/version.Version ${VERSION})"
 
 if [ ! -h gopath/src/${REPO_PATH} ]; then
 	mkdir -p gopath/src/${ORG_PATH}
@@ -15,7 +32,7 @@ eval $(go env)
 
 if [ ${GOOS} = "linux" ]; then
 	echo "Building flanneld..."
-	go build -o ${GOBIN}/flanneld ${REPO_PATH}
+	go build -o ${GOBIN}/flanneld -ldflags "${GLDFLAGS}" ${REPO_PATH}
 else
 	echo "Not on Linux - skipping flanneld build"
 fi

+ 3 - 3
dist/bump-release.sh

@@ -13,8 +13,8 @@ VERSIONTAG="v${VERSION}"
 TAGBR="v${VERSION}-tag"
 
 replace_version() {
-	sed -i -e "s/const Version.*/const Version = \"$1\"/" ../version.go
-	git commit -m "version: bump to v$1" ../version.go
+	sed -i -e "s/const Version.*/const Version = \"$1\"/" version/version.go
+	git commit -m "version: bump to v$1" version/version.go
 }
 
 # make sure we're up to date
@@ -24,7 +24,7 @@ git pull --ff-only ${ORIGIN} master
 replace_version ${VERSION}
 git tag -a -m "${VERSIONTAG}" "${VERSIONTAG}"
 
-# bump ver to +git and push to origin
+# bump ver to placeholder and push to origin
 replace_version "${VERSION}+git"
 git push "${ORIGIN}" master
 

+ 2 - 1
main.go

@@ -30,6 +30,7 @@ import (
 	"github.com/coreos/flannel/network"
 	"github.com/coreos/flannel/remote"
 	"github.com/coreos/flannel/subnet"
+	"github.com/coreos/flannel/version"
 
 	// Backends need to be imported for their init() to get executed and them to register
 	_ "github.com/coreos/flannel/backend/alloc"
@@ -103,7 +104,7 @@ func main() {
 	}
 
 	if opts.version {
-		fmt.Fprintln(os.Stderr, Version)
+		fmt.Fprintln(os.Stderr, version.Version)
 		os.Exit(0)
 	}
 

+ 2 - 2
version.go → version/version.go

@@ -12,6 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package main
+package version
 
-const Version = "0.5.3+git"
+var Version = "0.5.3+git"