Skip to content

Commit

Permalink
include version and commit hash at compile time
Browse files Browse the repository at this point in the history
when using makefile, version is set to "git". Currently  printed on
start, but an about page in the web UI will be added.
  • Loading branch information
hrfee committed Aug 31, 2020
1 parent 6e3d5da commit 1b0ca34
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ jfa-go
build/
pkg/
old/
version.go
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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



1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 20 additions & 0 deletions version.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 1b0ca34

Please sign in to comment.