version with ldflags instead of script

This commit is contained in:
Harvey Tindall 2021-02-22 01:23:42 +00:00
parent 027cf19d0f
commit b3fa667db1
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
5 changed files with 16 additions and 14 deletions

View File

@ -20,7 +20,6 @@ before:
- python3 scripts/enumerate_config.py -i config/config-base.json -o data/config-base.json
- python3 scripts/generate_ini.py -i config/config-base.json -o data/config-default.ini
- python3 scripts/compile_mjml.py -o data/
- python3 scripts/version.py {{.Version}}
- npx esbuild --bundle ts/admin.ts --outfile=./data/web/js/admin.js --minify
- npx esbuild --bundle ts/form.ts --outfile=./data/web/js/form.js --minify
- npx esbuild --bundle ts/setup.ts --outfile=./data/web/js/setup.js --minify

View File

@ -6,6 +6,10 @@ else
endif
GOBINARY ?= go
VERSION ?= $(shell git describe --exact-match HEAD &> /dev/null || echo vgit)
VERSION := $(shell echo $(VERSION) | sed 's/v//g')
COMMIT ?= $(shell git rev-parse --short HEAD || echo unknown)
npm:
$(info installing npm dependencies)
npm install
@ -47,22 +51,19 @@ swagger:
$(GOBINARY) get github.com/swaggo/swag/cmd/swag
swag init -g main.go
version:
python3 scripts/version.py auto
compile:
$(info Downloading deps)
$(GOBINARY) mod download
$(info Building)
mkdir -p build
cd build && CGO_ENABLED=0 $(GOBINARY) build -ldflags="-s -w" -o ./jfa-go ../*.go
cd build && CGO_ENABLED=0 $(GOBINARY) build -ldflags="-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT)" -o ./jfa-go ../*.go
compile-debug:
$(info Downloading deps)
$(GOBINARY) mod download
$(info Building)
mkdir -p build
cd build && CGO_ENABLED=0 $(GOBINARY) build -o ./jfa-go ../*.go
cd build && CGO_ENABLED=0 $(GOBINARY) build -o ./jfa-go ../*.go -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT)"
compress:
upx --lzma build/jfa-go
@ -95,6 +96,6 @@ external-files:
install:
cp -r build $(DESTDIR)/jfa-go
all: configuration npm email version typescript bundle-css swagger copy internal-files compile
all-external: configuration npm email version typescript bundle-css swagger copy external-files compile
debug: configuration npm email version ts-debug bundle-css swagger copy external-files compile-debug
all: configuration npm email typescript bundle-css swagger copy internal-files compile
all-external: configuration npm email typescript bundle-css swagger copy external-files compile
debug: configuration npm email ts-debug bundle-css swagger copy external-files compile-debug

View File

@ -67,9 +67,9 @@ func (app *appContext) loadConfig() error {
app.config.Section("template_email").Key("email_html").SetValue(app.config.Section("template_email").Key("email_html").MustString("jfa-go:" + "template.html"))
app.config.Section("template_email").Key("email_text").SetValue(app.config.Section("template_email").Key("email_text").MustString("jfa-go:" + "template.txt"))
app.config.Section("jellyfin").Key("version").SetValue(VERSION)
app.config.Section("jellyfin").Key("version").SetValue(version)
app.config.Section("jellyfin").Key("device").SetValue("jfa-go")
app.config.Section("jellyfin").Key("device_id").SetValue(fmt.Sprintf("jfa-go-%s-%s", VERSION, COMMIT))
app.config.Section("jellyfin").Key("device_id").SetValue(fmt.Sprintf("jfa-go-%s-%s", version, commit))
if app.config.Section("email").Key("method").MustString("") == "" {
emailEnabled = false

View File

@ -44,6 +44,8 @@ var (
info = color.New(color.FgMagenta).SprintfFunc()
hiwhite = color.New(color.FgHiWhite).SprintfFunc()
white = color.New(color.FgWhite).SprintfFunc()
version string
commit string
)
var serverTypes = map[string]string{
@ -624,7 +626,7 @@ func flagPassed(name string) (found bool) {
// @tag.description Things that dont fit elsewhere.
func printVersion() {
fmt.Println(info("jfa-go version: %s (%s)\n", hiwhite(VERSION), white(COMMIT)))
fmt.Println(info("jfa-go version: %s (%s)\n", hiwhite(version), white(commit)))
}
func main() {

View File

@ -74,8 +74,8 @@ func (app *appContext) AdminPage(gc *gin.Context) {
"contactMessage": "",
"email_enabled": emailEnabled,
"notifications": notificationsEnabled,
"version": VERSION,
"commit": COMMIT,
"version": version,
"commit": commit,
"ombiEnabled": ombiEnabled,
"username": !app.config.Section("email").Key("no_username").MustBool(false),
"strings": app.storage.lang.Admin[lang].Strings,