build git commit hash into project

This commit is contained in:
Michael Zhang 2020-10-14 16:14:57 -05:00
parent 28b9e32f43
commit 5ef2803075
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 35 additions and 6 deletions

9
Makefile Normal file
View file

@ -0,0 +1,9 @@
GIT_COMMIT = $(shell git rev-list -1 HEAD)
SOURCES = $(shell find . -type f -and -name "*.go" -or -name "*.html")
all: subscribe-bot
subscribe-bot: $(SOURCES)
go build -o $@ -ldflags "-X main.GitCommit=$(GIT_COMMIT)"
.PHONY: all

View file

@ -17,6 +17,8 @@ import (
var exit_chan = make(chan int) var exit_chan = make(chan int)
var GitCommit string
func main() { func main() {
configPath := flag.String("config", "config.toml", "Path to the config file (defaults to config.toml)") configPath := flag.String("config", "config.toml", "Path to the config file (defaults to config.toml)")
flag.Parse() flag.Parse()
@ -40,7 +42,7 @@ func main() {
} }
go scrape.RunScraper(&config, bot, db, api) go scrape.RunScraper(&config, bot, db, api)
go web.RunWeb(&config, api) go web.RunWeb(&config, api, GitCommit)
signal_chan := make(chan os.Signal, 1) signal_chan := make(chan os.Signal, 1)
signal.Notify(signal_chan, signal.Notify(signal_chan,

View file

@ -27,6 +27,17 @@
</div> </div>
{{ template "content" . }} {{ template "content" . }}
<footer>
<hr />
<small>
Maintained by <a href="https://osu.ppy.sh/u/2688103" target="_blank">IOException</a>
&middot;
<a href="https://git.mzhang.io/osu/subscribe-bot" target="_blank">Source code</a>
&middot;
subscribe-bot v{{ GitCommit }}
</small>
</footer>
</div> </div>
</body> </body>
</html> </html>

View file

@ -2,6 +2,7 @@ package web
import ( import (
"fmt" "fmt"
"html/template"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
@ -33,14 +34,15 @@ type Web struct {
config *config.Config config *config.Config
api *osuapi.Osuapi api *osuapi.Osuapi
hc *http.Client hc *http.Client
version string
} }
func RunWeb(config *config.Config, api *osuapi.Osuapi) { func RunWeb(config *config.Config, api *osuapi.Osuapi, version string) {
hc := &http.Client{ hc := &http.Client{
Timeout: 10 * time.Second, Timeout: 10 * time.Second,
} }
web := Web{config, api, hc} web := Web{config, api, hc, version}
web.Run() web.Run()
} }
@ -58,6 +60,11 @@ func (web *Web) Run() {
Root: "web/templates", Root: "web/templates",
Master: "master.html", Master: "master.html",
DisableCache: web.config.Debug, DisableCache: web.config.Debug,
Funcs: template.FuncMap{
"GitCommit": func() string {
return web.version
},
},
}) })
r.GET("/logout", web.logout) r.GET("/logout", web.logout)