From 74a840f5299a76942d33fa491fcae2de1e831a34 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 14 Feb 2025 14:11:27 +0800 Subject: [PATCH] *: 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 +- diff --git a/.gitignore b/.gitignore index e90b0c91bd05d6ddde2627d6a24494acce8ac04b..324f5c6c6531eec42316c52c6e4e433d924d88c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /forge +/version.go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..227cef9faeaed628c93fdf566a96cb5c3ab8d322 --- /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 0082f6803c88b140b585bc8de1933efce1e39494..f8ab85d0ca4e786c29d4670f9d529000de695b0f 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 b1e55853a3892375f72621d12e5827f5885ae815..e007490a89a04b0cce04a517ccf2b94d0968f6cd 100644 --- a/http_global.go +++ b/http_global.go @@ -3,5 +3,6 @@ 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 12acb8fab5d0ff76a288d76b02cc710329e5d4fb..44d685f9729943542c8351b269fbc92218bf5c19 100644 --- a/resources.go +++ b/resources.go @@ -10,6 +10,7 @@ //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 7d9072b7b2d329281c94281e224377b9d2ecd52a..b4cce1953057f3a4bf136115acbe8afae3d594c5 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 -}} -- 2.48.1