From 17d11decaa0a546c7af50a3aa9fa3756ed439cd3 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Sun, 3 Aug 2025 12:17:15 +0200 Subject: [PATCH] version build --- .github/workflows/go.yml | 30 +++++++++++++++--------------- TODO.md | 4 ++-- handler/home_handler.go | 7 +++++-- handler/incident_handler.go | 3 +++ handler/login_handler.go | 7 +++++-- handler/monitor_handler.go | 13 +++++++++++-- handler/setup_handler.go | 7 +++++-- handler/sponsor_handler.go | 7 ++++++- html/layout.html | 10 +++++----- pkg/version/version.go | 3 +++ 10 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 pkg/version/version.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index aa1a8b8..616b28b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -9,22 +9,22 @@ jobs: contents: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.24' + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.24" - - name: Build - run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o uptimemonitor ./cmd/uptimemonitor + - name: Build + run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o uptimemonitor -ldflags "-X version.Version=$(git describe --tags)" ./cmd/uptimemonitor - - name: Release - uses: softprops/action-gh-release@v2 - if: github.ref_type == 'tag' - with: - files: - uptimemonitor + - name: Release + uses: softprops/action-gh-release@v2 + if: github.ref_type == 'tag' + with: + files: + uptimemonitor - - name: Test - run: go run gotest.tools/gotestsum@latest --format testdox -- ./test \ No newline at end of file + - name: Test + run: go run gotest.tools/gotestsum@latest --format testdox -- ./test diff --git a/TODO.md b/TODO.md index 430b958..8b4e57a 100644 --- a/TODO.md +++ b/TODO.md @@ -2,11 +2,11 @@ What's left to do: -- [ ] Add sponsors badges (sponsors.uptimemonitor.dev api) +- [ ] Get app version from git tag - [ ] Add documentation - [ ] Document how to install - [ ] Document webhook parsing and available variables -- [ ] Get app version from git tag +- [ ] Release 🎉 Optional: diff --git a/handler/home_handler.go b/handler/home_handler.go index 52b034b..f43ff3c 100644 --- a/handler/home_handler.go +++ b/handler/home_handler.go @@ -5,13 +5,15 @@ import ( "net/http" "uptimemonitor" "uptimemonitor/html" + "uptimemonitor/pkg/version" ) func (h *Handler) HomePage() http.HandlerFunc { tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "app.html", "home.html")) type data struct { - User uptimemonitor.User + Version string + User uptimemonitor.User } return func(w http.ResponseWriter, r *http.Request) { @@ -22,7 +24,8 @@ func (h *Handler) HomePage() http.HandlerFunc { } tmpl.Execute(w, data{ - User: getUserFromRequest(r), + Version: version.Version, + User: getUserFromRequest(r), }) } } diff --git a/handler/incident_handler.go b/handler/incident_handler.go index ed9062b..46f7e24 100644 --- a/handler/incident_handler.go +++ b/handler/incident_handler.go @@ -7,6 +7,7 @@ import ( "strconv" "uptimemonitor" "uptimemonitor/html" + "uptimemonitor/pkg/version" ) func (h *Handler) ListIncidents() http.HandlerFunc { @@ -53,6 +54,7 @@ func (h *Handler) IncidentPage() http.HandlerFunc { tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "app.html", "incident.html")) type data struct { + Version string User uptimemonitor.User Incident uptimemonitor.Incident Monitor uptimemonitor.Monitor @@ -72,6 +74,7 @@ func (h *Handler) IncidentPage() http.HandlerFunc { } tmpl.Execute(w, data{ + Version: version.Version, User: getUserFromRequest(r), Incident: incident, Monitor: incident.Monitor, diff --git a/handler/login_handler.go b/handler/login_handler.go index ca57e52..75a8daa 100644 --- a/handler/login_handler.go +++ b/handler/login_handler.go @@ -7,20 +7,23 @@ import ( "uptimemonitor" "uptimemonitor/form" "uptimemonitor/html" + "uptimemonitor/pkg/version" "golang.org/x/crypto/bcrypt" ) func (h *Handler) LoginPage() http.HandlerFunc { type data struct { - Form form.LoginForm + Version string + Form form.LoginForm } tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "login.html")) return func(w http.ResponseWriter, r *http.Request) { tmpl.Execute(w, data{ - Form: form.LoginForm{}, + Version: version.Version, + Form: form.LoginForm{}, }) } } diff --git a/handler/monitor_handler.go b/handler/monitor_handler.go index 24af048..ed76de7 100644 --- a/handler/monitor_handler.go +++ b/handler/monitor_handler.go @@ -8,6 +8,7 @@ import ( "uptimemonitor" "uptimemonitor/form" "uptimemonitor/html" + "uptimemonitor/pkg/version" ) func (h *Handler) ListMonitors() http.HandlerFunc { @@ -36,12 +37,14 @@ func (h *Handler) CreateMonitorPage() http.HandlerFunc { tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "app.html", "new.html")) type data struct { - Form form.MonitorForm - User uptimemonitor.User + Version string + Form form.MonitorForm + User uptimemonitor.User } return func(w http.ResponseWriter, r *http.Request) { tmpl.Execute(w, data{ + Version: version.Version, Form: form.MonitorForm{ HttpHeaders: `{ "Content-Type": "application/json" @@ -124,6 +127,7 @@ func (h *Handler) MonitorPage() http.HandlerFunc { tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "app.html", "monitor.html")) type data struct { + Version string Monitor uptimemonitor.Monitor Skeletons []int User uptimemonitor.User @@ -137,6 +141,7 @@ func (h *Handler) MonitorPage() http.HandlerFunc { } tmpl.Execute(w, data{ + Version: version.Version, Monitor: m, Skeletons: make([]int, 60), User: getUserFromRequest(r), @@ -220,6 +225,7 @@ func (h *Handler) EditMonitorPage() http.HandlerFunc { tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "app.html", "edit.html")) type data struct { + Version string Form form.MonitorForm User uptimemonitor.User Monitor uptimemonitor.Monitor @@ -255,6 +261,7 @@ func (h *Handler) EditMonitorPage() http.HandlerFunc { } tmpl.Execute(w, data{ + Version: version.Version, Monitor: m, Form: f, User: getUserFromRequest(r), @@ -362,6 +369,7 @@ func (h *Handler) DeleteMonitorPage() http.HandlerFunc { tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "app.html", "delete.html")) type data struct { + Version string User uptimemonitor.User Monitor uptimemonitor.Monitor } @@ -375,6 +383,7 @@ func (h *Handler) DeleteMonitorPage() http.HandlerFunc { } tmpl.Execute(w, data{ + Version: version.Version, User: getUserFromRequest(r), Monitor: m, }) diff --git a/handler/setup_handler.go b/handler/setup_handler.go index f4139df..9024e04 100644 --- a/handler/setup_handler.go +++ b/handler/setup_handler.go @@ -7,13 +7,15 @@ import ( "uptimemonitor" "uptimemonitor/form" "uptimemonitor/html" + "uptimemonitor/pkg/version" "golang.org/x/crypto/bcrypt" ) func (h *Handler) SetupPage() http.HandlerFunc { type data struct { - Form form.SetupForm + Version string + Form form.SetupForm } tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "setup.html")) @@ -31,7 +33,8 @@ func (h *Handler) SetupPage() http.HandlerFunc { } tmpl.Execute(w, data{ - Form: form.SetupForm{}, + Version: version.Version, + Form: form.SetupForm{}, }) } } diff --git a/handler/sponsor_handler.go b/handler/sponsor_handler.go index 5e8a482..f74f7ba 100644 --- a/handler/sponsor_handler.go +++ b/handler/sponsor_handler.go @@ -8,6 +8,7 @@ import ( "time" "uptimemonitor" "uptimemonitor/html" + "uptimemonitor/pkg/version" ) var initialSponsors = []uptimemonitor.Sponsor{ @@ -61,7 +62,11 @@ func (*Handler) ListSponsors() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.Header.Get("HX-Request") != "true" { - layout.ExecuteTemplate(w, "sponsors", nil) + layout.ExecuteTemplate(w, "sponsors", struct { + Version string + }{ + Version: version.Version, + }) return } diff --git a/html/layout.html b/html/layout.html index f4054df..8649e9b 100644 --- a/html/layout.html +++ b/html/layout.html @@ -31,15 +31,15 @@ - UM {{ template "version" . }} + UM + + {{ with .Version }} + {{ . }} + {{ end }} {{ end }} -{{ define "version" }} -v0.5.0-alpha -{{ end }} - {{ define "sponsors" }}
{{ end }} \ No newline at end of file diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 0000000..aa2cbb5 --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,3 @@ +package version + +var Version string = "dev"