1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

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.
This commit is contained in:
Harvey Tindall 2020-08-31 14:57:42 +01:00
parent 6e3d5dac19
commit 1b0ca34586
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
5 changed files with 28 additions and 2 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ jfa-go
build/ build/
pkg/ pkg/
old/ old/
version.go

View File

@ -16,6 +16,7 @@ before:
- python3 scss/get_node_deps.py - python3 scss/get_node_deps.py
- python3 scss/compile.py -y - python3 scss/compile.py -y
- python3 mail/generate.py -y - python3 mail/generate.py -y
- python3 version.py {{.Version}} version.go
builds: builds:
- dir: ./ - dir: ./
env: env:

View File

@ -28,6 +28,9 @@ mail:
echo "Generating email html" echo "Generating email html"
python3 mail/generate.py python3 mail/generate.py
version:
python3 version.py git version.go
compile: compile:
echo "Downloading deps" echo "Downloading deps"
go mod download go mod download
@ -42,8 +45,8 @@ copy:
install: install:
cp -r build $(DESTDIR)/jfa-go cp -r build $(DESTDIR)/jfa-go
all: configuration sass mail compile copy all: configuration sass mail version compile copy
headless: configuration sass-headless mail-headless copy headless: configuration sass-headless mail-headless version compile copy

View File

@ -95,6 +95,7 @@ func setGinLogger(router *gin.Engine, debugMode bool) {
} }
func main() { func main() {
fmt.Printf("jfa-go version: %s (%s)\n", VERSION, COMMIT)
// app encompasses essentially all useful functions. // app encompasses essentially all useful functions.
app := new(appContext) app := new(appContext)

20
version.py Normal file
View File

@ -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)