From 57752af4050b68a02820cbfc4f09ebb7c134b609 Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Fri, 2 Apr 2021 12:36:59 +0200 Subject: [PATCH] Added go generate command for version number in templates --- .release/entrypoint.sh | 1 + Dockerfile | 2 +- Main.go | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.release/entrypoint.sh b/.release/entrypoint.sh index 712dd51..cfa00e2 100755 --- a/.release/entrypoint.sh +++ b/.release/entrypoint.sh @@ -6,6 +6,7 @@ set -e targets=${@-"darwin/amd64 linux/amd64 linux/386 linux/arm linux/arm64 windows/amd64 windows/386"} cd /usr/src/myapp +go generate for target in $targets; do os="$(echo $target | cut -d '/' -f1)" diff --git a/Dockerfile b/Dockerfile index ee6e479..cea1d71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN cd /compile && go mod download COPY . /compile -RUN cd /compile && CGO_ENABLED=0 go build -ldflags="-s -w -X 'Gokapi/src/environment.IsDocker=true' -X 'Gokapi/src/environment.Builder=Project Docker File' -X 'Gokapi/src/environment.BuildTime=$(date)'" -o /compile/gokapi +RUN cd /compile && go generate && CGO_ENABLED=0 go build -ldflags="-s -w -X 'Gokapi/src/environment.IsDocker=true' -X 'Gokapi/src/environment.Builder=Project Docker File' -X 'Gokapi/src/environment.BuildTime=$(date)'" -o /compile/gokapi FROM alpine:3.13 diff --git a/Main.go b/Main.go index 5ce62a9..e75e20c 100644 --- a/Main.go +++ b/Main.go @@ -16,8 +16,10 @@ import ( "time" ) -// needs to be changed in ./templates/string_constants.tmpl as well +// Current version in readable form. Needs to be changed in ./templates/string_constants.tmpl as well, +// which can be done with "go generate" const VERSION = "1.1.2" +//go:generate sed "-i" "s/{{define \"version\"}}.*{{end}}/{{define \"version\"}}1.1.2{{end}}/g" "./templates/string_constants.tmpl" // Main routine that is called on startup func main() {