Skip to content

Commit

Permalink
Merge pull request #217 from datarootsio/adding-in-progress-status
Browse files Browse the repository at this point in the history
Added the version info
  • Loading branch information
bart6114 authored Oct 9, 2024
2 parents abdddf7 + 8b4b794 commit f85d635
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
21 changes: 21 additions & 0 deletions pkg/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}
23 changes: 23 additions & 0 deletions pkg/web_assets/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({

Expand All @@ -95,6 +117,7 @@ document.addEventListener('alpine:init', () => {
}

}))



})
Expand Down
81 changes: 35 additions & 46 deletions pkg/web_assets/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>cheek</title>
<link rel="icon" type="image/x-icon" href="https://storage.googleapis.com/cheek-scheduler/cheek-64.png">
<link rel="stylesheet" href="/static/styles.css" />
<link rel="stylesheet" href="/static/tailwind.css" />
<script src="//unpkg.com/alpinejs" defer></script>
<script type="text/javascript" src="/static/script.js"></script>
</head>

<body class="bg-slate-800">
<div class="max-w-4xl mx-auto">
<div class="flex pt-6 items-end">
<a class="drop-shadow-md text-3xl font-extrabold text-center bg-gradient-to-r from-lime-200 to-blue-400 bg-clip-text text-transparent hover:from-red-400 hover:via-yellow-300 hover:via-green-500 hover:to-lime-200 hover:bg-gradient-to-l hover:animate-pulse"
href="/">cheek</a>
<div class="grow"></div>
<div class="col is-vertical-align is-right">
<a class="icon-ahref fill-lime-200 hover:fill-slate-200" href="https://github.com/datarootsio/cheek">
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>logo-github</title>
<g>
<path fill-rule="evenodd" clip-rule="evenodd"
d="M16,0.4c-8.8,0-16,7.2-16,16c0,7.1,4.6,13.1,10.9,15.2 c0.8,0.1,1.1-0.3,1.1-0.8c0-0.4,0-1.4,0-2.7c-4.5,1-5.4-2.1-5.4-2.1c-0.7-1.8-1.8-2.3-1.8-2.3c-1.5-1,0.1-1,0.1-1 c1.6,0.1,2.5,1.6,2.5,1.6c1.4,2.4,3.7,1.7,4.7,1.3c0.1-1,0.6-1.7,1-2.1c-3.6-0.4-7.3-1.8-7.3-7.9c0-1.7,0.6-3.2,1.6-4.3 c-0.2-0.4-0.7-2,0.2-4.2c0,0,1.3-0.4,4.4,1.6c1.3-0.4,2.6-0.5,4-0.5c1.4,0,2.7,0.2,4,0.5C23.1,6.6,24.4,7,24.4,7 c0.9,2.2,0.3,3.8,0.2,4.2c1,1.1,1.6,2.5,1.6,4.3c0,6.1-3.7,7.5-7.3,7.9c0.6,0.5,1.1,1.5,1.1,3c0,2.1,0,3.9,0,4.4 c0,0.4,0.3,0.9,1.1,0.8C27.4,29.5,32,23.5,32,16.4C32,7.6,24.8,0.4,16,0.4z">
</path>
</g>
</svg>
</a>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>cheek</title>
<link rel="icon" type="image/x-icon" href="https://storage.googleapis.com/cheek-scheduler/cheek-64.png">
<link rel="stylesheet" href="/static/styles.css" />
<link rel="stylesheet" href="/static/tailwind.css" />
<script src="//unpkg.com/alpinejs" defer></script>
<script type="text/javascript" src="/static/script.js"></script>
</head>
<body class="bg-slate-800">
<div class="max-w-4xl mx-auto">
<div class="flex pt-6 items-end">
<a class="drop-shadow-md text-3xl font-extrabold text-center bg-gradient-to-r from-lime-200 to-blue-400 bg-clip-text text-transparent hover:from-red-400 hover:via-yellow-300 hover:via-green-500 hover:to-lime-200 hover:bg-gradient-to-l hover:animate-pulse" href="/">cheek</a>
<div class="grow"></div>
<div class="col is-vertical-align is-right">
<a class="icon-ahref fill-lime-200 hover:fill-slate-200" href="https://github.com/datarootsio/cheek">
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>logo-github</title>
<g>
<path fill-rule="evenodd" clip-rule="evenodd" d="M16,0.4c-8.8,0-16,7.2-16,16c0,7.1,4.6,13.1,10.9,15.2 c0.8,0.1,1.1-0.3,1.1-0.8c0-0.4,0-1.4,0-2.7c-4.5,1-5.4-2.1-5.4-2.1c-0.7-1.8-1.8-2.3-1.8-2.3c-1.5-1,0.1-1,0.1-1 c1.6,0.1,2.5,1.6,2.5,1.6c1.4,2.4,3.7,1.7,4.7,1.3c0.1-1,0.6-1.7,1-2.1c-3.6-0.4-7.3-1.8-7.3-7.9c0-1.7,0.6-3.2,1.6-4.3 c-0.2-0.4-0.7-2,0.2-4.2c0,0,1.3-0.4,4.4,1.6c1.3-0.4,2.6-0.5,4-0.5c1.4,0,2.7,0.2,4,0.5C23.1,6.6,24.4,7,24.4,7 c0.9,2.2,0.3,3.8,0.2,4.2c1,1.1,1.6,2.5,1.6,4.3c0,6.1-3.7,7.5-7.3,7.9c0.6,0.5,1.1,1.5,1.1,3c0,2.1,0,3.9,0,4.4 c0,0.4,0.3,0.9,1.1,0.8C27.4,29.5,32,23.5,32,16.4C32,7.6,24.8,0.4,16,0.4z"></path>
</g>
</svg>
</a>
</div>
</div>
<div class="flex flex-wrap gap-x-2 gap-y-2" x-data>
<a class="text-gray-400 hover:text-lime-200'" href="/core/logs">_</a>
<div class="text-xs">
<template x-for="job in $store.jobs.jobs">
<a :class="job.name === $store.job.jobName ? 'text-lime-200' : 'text-gray-200 hover:text-lime-200'" :href="`/jobs/${job.name}/latest`" x-text="job.name"></a>
</template>
</div>
</div>
{{block "content" .}}{{end}}
</div>
<div class="flex flex-wrap gap-x-2 gap-y-2" x-data>
<a class="text-gray-400 hover:text-lime-200'"
href="/core/logs">_</a>
<template x-for="job in $store.jobs.jobs">
<a :class="job.name === $store.job.jobName ? 'text-lime-200' : 'text-gray-200 hover:text-lime-200'"
:href="`/jobs/${job.name}/latest`" x-text="job.name"></a>

</template>
</div>

{{block "content" .}}{{end}}

</div>
</body>


</body>
</html>
9 changes: 7 additions & 2 deletions pkg/web_assets/templates/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:title="`${truncateDateTime(run.triggered_at)}`">

<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"
:class="run.status === 0 ? 'fill-emerald-500' : run.status === undefined ? 'fill-orange-500' : 'fill-red-500'">
:class="run.status === 0 ? 'fill-emerald-600' : run.status === undefined ? 'fill-orange-300' : 'fill-red-600'">
<g>
<path
d="M6.03 1.01c-2.78 0-5.03 2.24-5.03 5.02s2.24 5.03 5.03 5.03 5.03-2.24 5.02-5.03-2.24-5.03-5.02-5.02z">
Expand All @@ -24,5 +24,10 @@
</template>
</div>

<p class="pt-2 text-xs text-slate-400">shows statuses up until the last 10 runs</p>
<div x-data x-init="$store.version.init()">
<p class="pt-2 text-xs text-slate-400">
shows statuses up until the last 10 runs (running cheek v<span x-text="$store.version.version" class="text-gray-500"></span>)
</p>
</div>

{{ end }}

0 comments on commit f85d635

Please sign in to comment.