From 74a840f5299a76942d33fa491fcae2de1e831a34 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 14 Feb 2025 14:11:27 +0800 Subject: *: Use Makefile, and generate a version --- .gitignore | 1 + Makefile | 11 +++++++++++ README.md | 2 +- http_global.go | 1 + resources.go | 1 + templates/_footer.html.tmpl | 2 +- 6 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index e90b0c9..324f5c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /forge +/version.go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..227cef9 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.PHONY: clean + +forge: $(filter-out forge,$(wildcard *)) version.go + go build -o $@ + +version.go: + printf 'package main\nconst VERSION="%s"\n' $(shell git describe --tags --long --always --dirty) > $@ + +clean: + $(RM) forge version.go + diff --git a/README.md b/README.md index 0082f68..f8ab85d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ primarily designed for self-hosting by small organizations and individuals. ## Setup -* Clone the source code and build a binary with `go build`. +* Clone the source code and build a binary with GNU make. * Generate an SSH key pair with `ssh-keygen`. * Create a PostgreSQL database and run `schema.sql`. * Set up reverse proxies, etc., if desired. diff --git a/http_global.go b/http_global.go index b1e5585..e007490 100644 --- a/http_global.go +++ b/http_global.go @@ -3,5 +3,6 @@ package main var global_data = map[string]any{ "server_public_key_string": &server_public_key_string, "server_public_key_fingerprint": &server_public_key_fingerprint, + "forge_version": VERSION, // Some other ones are populated after config parsing } diff --git a/resources.go b/resources.go index 12acb8f..44d685f 100644 --- a/resources.go +++ b/resources.go @@ -10,6 +10,7 @@ import ( //go:embed .gitignore LICENSE README.md //go:embed *.go go.mod go.sum //go:embed *.scfg +//go:embed Makefile //go:embed schema.sql //go:embed static/* templates/* var source_fs embed.FS diff --git a/templates/_footer.html.tmpl b/templates/_footer.html.tmpl index 7d9072b..b4cce19 100644 --- a/templates/_footer.html.tmpl +++ b/templates/_footer.html.tmpl @@ -1,3 +1,3 @@ {{- define "footer" -}} -Lindenii Forge (source, upstream) +Lindenii Forge {{ .global.forge_version }} (source, upstream) {{- end -}} -- cgit v1.2.3