From 3915f7ce4d35ab24c4b3af97854f1b13e9d59253 Mon Sep 17 00:00:00 2001 From: V Date: Sat, 16 May 2026 20:38:13 +0100 Subject: [PATCH] Version bump --- Dockerfile | 1 + VERSION | 1 + cmd/server/main.go | 17 +++++++++++++++++ internal/app/app.go | 4 +++- internal/app/app_test.go | 3 ++- web/templates/admin.html | 3 +++ 6 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 VERSION diff --git a/Dockerfile b/Dockerfile index a867512..0cbba49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ WORKDIR /app COPY --from=build /out/archi-folio /usr/local/bin/archi-folio COPY --chown=nonroot:nonroot web ./web +COPY --chown=nonroot:nonroot VERSION ./VERSION COPY --chown=nonroot:nonroot data/uploads/.gitkeep ./data/uploads/.gitkeep EXPOSE 8080 diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/cmd/server/main.go b/cmd/server/main.go index a139fe8..3e77fdb 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -17,6 +17,10 @@ func main() { if err := loadDotEnv(".env"); err != nil { log.Fatal(err) } + version, err := readVersion("VERSION") + if err != nil { + log.Fatal(err) + } cfg := app.Config{ Addr: requiredEnv("ADDR"), @@ -25,6 +29,7 @@ func main() { AdminUsername: requiredEnv("ADMIN_USERNAME"), AdminPassword: requiredEnv("ADMIN_PASSWORD"), UploadDir: requiredEnv("UPLOAD_DIR"), + Version: version, } db, err := store.Open(cfg.DatabasePath) @@ -94,3 +99,15 @@ func requiredEnv(key string) string { } return value } + +func readVersion(path string) (string, error) { + data, err := os.ReadFile(path) + if err != nil { + return "", err + } + version := strings.TrimSpace(string(data)) + if version == "" { + return "", fmt.Errorf("%s is empty", path) + } + return version, nil +} diff --git a/internal/app/app.go b/internal/app/app.go index 26ba7ea..c88d8df 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -35,6 +35,7 @@ type Config struct { AdminUsername string AdminPassword string UploadDir string + Version string } type Server struct { @@ -56,6 +57,7 @@ type pageData struct { Error string Success string CurrentPath string + Version string } func New(cfg Config, st *store.Store) (*Server, error) { @@ -493,7 +495,7 @@ func (s *Server) adminData(r *http.Request, tab string) (pageData, error) { if err != nil { return pageData{}, err } - data := pageData{Title: "Admin", Admin: true, AdminTab: tab, Content: content, Success: r.URL.Query().Get("ok"), Error: r.URL.Query().Get("err")} + data := pageData{Title: "Admin", Admin: true, AdminTab: tab, Content: content, Success: r.URL.Query().Get("ok"), Error: r.URL.Query().Get("err"), Version: s.cfg.Version} if tab == "projects" { projects, err := s.store.Projects(r.Context(), false) if err != nil { diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 6d87e46..41a4aab 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -32,6 +32,7 @@ func newTestServer(t *testing.T) *Server { AdminUsername: "admin", AdminPassword: "changeme", UploadDir: filepath.Join(dir, "uploads"), + Version: "test-version", }, st) if err != nil { t.Fatal(err) @@ -119,7 +120,7 @@ func TestAdminTabs(t *testing.T) { t.Fatalf("%s returned %d", test.path, rec.Code) } body, _ := io.ReadAll(rec.Result().Body) - if !strings.Contains(string(body), test.want) || !strings.Contains(string(body), "") { + if !strings.Contains(string(body), test.want) || !strings.Contains(string(body), "") || !strings.Contains(string(body), "Version test-version") { t.Fatalf("%s did not render full tab page: %s", test.path, body) } } diff --git a/web/templates/admin.html b/web/templates/admin.html index 325591f..21f53db 100644 --- a/web/templates/admin.html +++ b/web/templates/admin.html @@ -22,6 +22,9 @@ {{define "admin_shell_end"}} + {{end}}