From 1b0ca34586311805493047f3d583f7d823c2b402 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 31 Aug 2020 14:57:42 +0100 Subject: [PATCH] include version and commit hash at compile time when using makefile, version is set to "git". Currently printed on start, but an about page in the web UI will be added. --- .gitignore | 1 + .goreleaser.yml | 1 + Makefile | 7 +++++-- main.go | 1 + version.py | 20 ++++++++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 version.py diff --git a/.gitignore b/.gitignore index 5763668..a1b30c1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ jfa-go build/ pkg/ old/ +version.go diff --git a/.goreleaser.yml b/.goreleaser.yml index 1932d24..0cfe1f8 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -16,6 +16,7 @@ before: - python3 scss/get_node_deps.py - python3 scss/compile.py -y - python3 mail/generate.py -y + - python3 version.py {{.Version}} version.go builds: - dir: ./ env: diff --git a/Makefile b/Makefile index e08553a..5167ced 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ mail: echo "Generating email html" python3 mail/generate.py +version: + python3 version.py git version.go + compile: echo "Downloading deps" go mod download @@ -42,8 +45,8 @@ copy: install: cp -r build $(DESTDIR)/jfa-go -all: configuration sass mail compile copy -headless: configuration sass-headless mail-headless copy +all: configuration sass mail version compile copy +headless: configuration sass-headless mail-headless version compile copy diff --git a/main.go b/main.go index 0ff2b4a..d80f4d7 100644 --- a/main.go +++ b/main.go @@ -95,6 +95,7 @@ func setGinLogger(router *gin.Engine, debugMode bool) { } func main() { + fmt.Printf("jfa-go version: %s (%s)\n", VERSION, COMMIT) // app encompasses essentially all useful functions. app := new(appContext) diff --git a/version.py b/version.py new file mode 100644 index 0000000..0b861b5 --- /dev/null +++ b/version.py @@ -0,0 +1,20 @@ +import subprocess +import sys +import os +try: + version = sys.argv[1].replace('v', '') +except IndexError: + version = "git" + +commit = subprocess.check_output("git rev-parse --short HEAD".split()).decode("utf-8").rstrip() + +file = f'package main; const VERSION = "{version}"; const COMMIT = "{commit}";' + +try: + writeto = sys.argv[2] +except IndexError: + writeto = "version.go" + +with open(writeto, 'w') as f: + f.write(file) +