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 GitCommit string
func main() {
configPath := flag.String("config", "config.toml", "Path to the config file (defaults to config.toml)")
flag.Parse()
@ -40,7 +42,7 @@ func main() {
}
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.Notify(signal_chan,

View file

@ -27,6 +27,17 @@
</div>
{{ 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>
</body>
</html>

View file

@ -2,6 +2,7 @@ package web
import (
"fmt"
"html/template"
"io/ioutil"
"net/http"
"os"
@ -30,17 +31,18 @@ var (
)
type Web struct {
config *config.Config
api *osuapi.Osuapi
hc *http.Client
config *config.Config
api *osuapi.Osuapi
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{
Timeout: 10 * time.Second,
}
web := Web{config, api, hc}
web := Web{config, api, hc, version}
web.Run()
}
@ -58,6 +60,11 @@ func (web *Web) Run() {
Root: "web/templates",
Master: "master.html",
DisableCache: web.config.Debug,
Funcs: template.FuncMap{
"GitCommit": func() string {
return web.version
},
},
})
r.GET("/logout", web.logout)