diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56968a2..61ddefd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,7 @@ jobs: - id: vars run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" - run: mkdir -p ${{ matrix.goos }}/${{ matrix.goarch }} - - run: env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-X 'github.com/datarootsio/cheek/pkg.Version=${{ steps.vars.outputs.sha_short }}'" -o ${{ matrix.goos }}/${{ matrix.goarch }} + - run: env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-X 'github.com/datarootsio/cheek/pkg.Version=${{ needs.version_tag.outputs.new_tag }}' -X 'github.com/datarootsio/cheek/pkg.CommitSHA=${{ steps.vars.outputs.sha_short }}'" -o ${{ matrix.goos }}/${{ matrix.goarch }} - run: cp ${{ matrix.goos }}/${{ matrix.goarch }}/cheek ${{ matrix.goos }}/${{ matrix.goarch }}/cheek-${{ steps.vars.outputs.sha_short }} - run: cp ${{ matrix.goos }}/${{ matrix.goarch }}/cheek ${{ matrix.goos }}/${{ matrix.goarch }}/cheek-${{ needs.version_tag.outputs.new_tag }} ## upload binary to google storage diff --git a/go.mod b/go.mod index bbcaf71..a6e3b12 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-sqlite3 v1.14.23 + github.com/mattn/go-sqlite3 v1.14.24 github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect diff --git a/go.sum b/go.sum index 1ec48b9..1914672 100644 --- a/go.sum +++ b/go.sum @@ -50,10 +50,9 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= -github.com/mattn/go-sqlite3 v1.14.23 h1:gbShiuAP1W5j9UOksQ06aiiqPMxYecovVGwmTxWtuw0= -github.com/mattn/go-sqlite3 v1.14.23/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= +github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= diff --git a/pkg/http.go b/pkg/http.go index 2eb56a7..495b18f 100644 --- a/pkg/http.go +++ b/pkg/http.go @@ -23,6 +23,17 @@ type Response struct { Type string `json:"type,omitempty"` } +// This will be injected at build time +var ( + version string + commitSHA string +) + +type VersionResponse struct { + Version string `json:"version"` + CommitSHA string `json:"commit_sha"` +} + type ScheduleStatusResponse struct { Status map[string]int `json:"status,omitempty"` FailedRunCount int `json:"failed_run_count,omitempty"` @@ -57,6 +68,7 @@ func setupRouter(s *Schedule) *httprouter.Router { router.POST("/api/jobs/:jobId/trigger", postTrigger(s)) router.GET("/api/core/logs", getCoreLogs(s)) router.GET("/api/schedule/status", getScheduleStatus(s)) + router.GET("/api/version", getVersion) // Add version endpoint fileServer := http.FileServer(http.FS(fsys())) router.GET("/static/*filepath", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { @@ -82,6 +94,7 @@ func getCoreLogsPage() httprouter.Handle { } func getHomePage() httprouter.Handle { + tmpl, err := template.ParseFS(fsys(), "templates/overview.html", "templates/base.html") if err != nil { panic(err) @@ -287,3 +300,11 @@ func postTrigger(s *Schedule) httprouter.Handle { } } } + +func getVersion(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { + versionResponse := VersionResponse{Version: version, CommitSHA: commitSHA} + w.Header().Set("Content-Type", "application/json") + if err := json.NewEncoder(w).Encode(versionResponse); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} diff --git a/pkg/web_assets/static/script.js b/pkg/web_assets/static/script.js index e0e71a2..ffbe3f0 100644 --- a/pkg/web_assets/static/script.js +++ b/pkg/web_assets/static/script.js @@ -75,6 +75,28 @@ document.addEventListener('alpine:init', () => { }, }) + // New version store + Alpine.store('version', { + version: null, + + fetchVersion: async function () { + try { + const response = await fetch('/api/version'); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + const data = await response.json(); + this.version = data.version; + } catch (error) { + console.error('Fetch error:', error); + } + }, + + init() { + this.fetchVersion(); + } + }) + // alpine data component Alpine.data('coreLogs', () => ({ @@ -95,6 +117,7 @@ document.addEventListener('alpine:init', () => { } })) + }) diff --git a/pkg/web_assets/templates/base.html b/pkg/web_assets/templates/base.html index ef51586..ea13f0a 100644 --- a/pkg/web_assets/templates/base.html +++ b/pkg/web_assets/templates/base.html @@ -1,51 +1,40 @@ - - - - - cheek - - - - - - - - -
-
- cheek -
-
- - - logo-github - - - - - - - + + + + cheek + + + + + + + +
+ +
+ _ +
+ +
+
+ {{block "content" .}}{{end}}
-
- _ - -
- - {{block "content" .}}{{end}} - -
- - - + \ No newline at end of file diff --git a/pkg/web_assets/templates/overview.html b/pkg/web_assets/templates/overview.html index 30cec7f..f8c3d08 100644 --- a/pkg/web_assets/templates/overview.html +++ b/pkg/web_assets/templates/overview.html @@ -9,7 +9,7 @@ :title="`${truncateDateTime(run.triggered_at)}`"> + :class="run.status === 0 ? 'fill-emerald-600' : run.status === undefined ? 'fill-orange-300' : 'fill-red-600'"> @@ -24,5 +24,10 @@
-

shows statuses up until the last 10 runs

+
+

+ shows statuses up until the last 10 runs (running cheek v) +

+
+ {{ end }} \ No newline at end of file