version build

This commit is contained in:
Krzysztof
2025-08-03 12:17:15 +02:00
parent 27e89b297a
commit 17d11decaa
10 changed files with 60 additions and 31 deletions

View File

@@ -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
- name: Test
run: go run gotest.tools/gotestsum@latest --format testdox -- ./test

View File

@@ -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:

View File

@@ -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),
})
}
}

View File

@@ -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,

View File

@@ -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{},
})
}
}

View File

@@ -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,
})

View File

@@ -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{},
})
}
}

View File

@@ -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
}

View File

@@ -31,15 +31,15 @@
</svg>
<span class="">
UM {{ template "version" . }}
UM
{{ with .Version }}
<span class="text-neutral-400 text-xs font-normal truncate">{{ . }}</span>
{{ end }}
</span>
</a>
{{ end }}
{{ define "version" }}
<span class="text-neutral-400 text-xs font-normal truncate">v0.5.0-alpha</span>
{{ end }}
{{ define "sponsors" }}
<div hx-get="/sponsors" hx-trigger="intersect" hx-swap="outerHTML"></div>
{{ end }}

3
pkg/version/version.go Normal file
View File

@@ -0,0 +1,3 @@
package version
var Version string = "dev"