diff --git a/.goreleaser.yml b/.goreleaser.yml index e48c045..d3fc23b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 diff --git a/Makefile b/Makefile index a6fb79d..b765386 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/config.go b/config.go index ca1f847..5f9e725 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/main.go b/main.go index c7443b3..8477205 100644 --- a/main.go +++ b/main.go @@ -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() { diff --git a/views.go b/views.go index 65097e4..820947a 100644 --- a/views.go +++ b/views.go @@ -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,