show version in cli and web

This commit is contained in:
sentriz
2019-11-27 15:32:51 +00:00
parent 2b3825b24d
commit fd098f60d6
8 changed files with 84 additions and 19 deletions

50
_do_bump_version Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/sh
# safety checks
if [[ $# -ne 1 ]]; then
echo "usage: $0 <major|minor|patch>" >&2
exit 1
fi
if [[ -n "$(git status --porcelain)" ]]; then
echo "working directory is dirty" >&2
exit 1
fi
# get the current verison from last git tag into array and
# inc the provided part
semver_expression='s/^v([0-9]+)\.([0-9]+)\.([0-9]+).*$/\1 \2 \3/'
version=( $(git describe --tags | sed -E -e "$semver_expression" ) )
case "$1" in
major)
((version[0]++))
version[1]=0
version[2]=0
;;
minor)
((version[1]++))
version[2]=0
;;
patch)
((version[2]++))
;;
*)
echo 'please provide a valid version in increment' >&2
exit 1
esac
new_version="v${version[0]}.${version[1]}.${version[2]}"
# write version to go
mkdir version >/dev/null 2>&1
cat > version/version.go << EOL
// generated by \`_do_bump_version\` script in project root
// $(date)
// DO NOT EDIT
package version
const VERSION = "$new_version"
EOL
# create and tag single commit with a change to the version file
git commit --all --message "bump to $new_version"
git tag "$new_version"

View File

@@ -10824,7 +10824,7 @@ var Bytes = map[string]*EmbeddedAsset{
0x7d,0x7d,0x0a,
}},
"layouts/base.tmpl": &EmbeddedAsset{
ModTime: time.Unix(1574821176, 0),
ModTime: time.Unix(1574868606, 0),
Bytes: []byte{
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x6c,0x61,0x79,0x6f,0x75,0x74,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x21,
0x64,0x6f,0x63,0x74,0x79,0x70,0x65,0x20,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x3c,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x20,0x20,0x20,
@@ -10846,20 +10846,23 @@ var Bytes = map[string]*EmbeddedAsset{
0x20,0x20,0x20,0x20,0x20,0x3c,0x69,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x6d,0x64,0x69,0x20,0x6d,0x64,0x69,0x2d,0x61,
0x6c,0x65,0x72,0x74,0x2d,0x63,0x69,0x72,0x63,0x6c,0x65,0x22,0x3e,0x3c,0x2f,0x69,0x3e,0x20,0x7b,0x7b,0x20,0x24,0x66,0x6c,
0x61,0x73,0x68,0x2e,0x4d,0x65,0x73,0x73,0x61,0x67,0x65,0x20,0x7d,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x3c,0x2f,0x64,0x69,0x76,0x3e,0x0a,0x09,0x20,0x20,0x20,0x20,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x7b,0x20,0x74,0x65,0x6d,0x70,0x6c,0x61,0x74,0x65,
0x20,0x22,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x22,0x20,0x2e,0x20,0x7d,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x3c,0x64,0x69,0x76,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x73,0x69,0x64,0x65,0x2d,0x70,0x61,0x64,
0x64,0x65,0x64,0x20,0x74,0x65,0x78,0x74,0x2d,0x72,0x69,0x67,0x68,0x74,0x22,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x65,0x6e,0x61,0x6e,0x20,0x6b,0x65,0x6c,0x6c,0x79,0x2c,0x20,0x32,0x30,
0x31,0x39,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x73,0x70,0x61,0x6e,
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x6c,0x69,0x67,0x68,0x74,0x22,0x3e,0x26,0x23,0x31,0x32,0x34,0x3b,0x3c,0x2f,0x73,
0x70,0x61,0x6e,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x61,0x20,
0x68,0x72,0x65,0x66,0x3d,0x22,0x68,0x74,0x74,0x70,0x73,0x3a,0x2f,0x2f,0x73,0x65,0x6e,0x61,0x6e,0x2e,0x78,0x79,0x7a,0x2f,
0x67,0x2f,0x67,0x6f,0x6e,0x69,0x63,0x22,0x3e,0x67,0x69,0x74,0x68,0x75,0x62,0x3c,0x2f,0x61,0x3e,0x0a,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x2f,0x64,0x69,0x76,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,
0x2f,0x64,0x69,0x76,0x3e,0x0a,0x20,0x20,0x20,0x20,0x3c,0x2f,0x62,0x6f,0x64,0x79,0x3e,0x0a,0x3c,0x2f,0x68,0x74,0x6d,0x6c,
0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
0x20,0x20,0x20,0x3c,0x2f,0x64,0x69,0x76,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x7b,
0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x7b,0x20,0x74,
0x65,0x6d,0x70,0x6c,0x61,0x74,0x65,0x20,0x22,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x22,0x20,0x2e,0x20,0x7d,0x7d,0x0a,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x64,0x69,0x76,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x73,
0x69,0x64,0x65,0x2d,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x74,0x65,0x78,0x74,0x2d,0x72,0x69,0x67,0x68,0x74,0x22,0x3e,0x0a,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x73,0x70,0x61,0x6e,0x20,0x63,0x6c,
0x61,0x73,0x73,0x3d,0x22,0x6c,0x69,0x67,0x68,0x74,0x22,0x3e,0x7b,0x7b,0x20,0x2e,0x56,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,
0x7d,0x7d,0x3c,0x2f,0x73,0x70,0x61,0x6e,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x73,0x65,0x6e,0x61,0x6e,0x20,0x6b,0x65,0x6c,0x6c,0x79,0x2c,0x20,0x32,0x30,0x31,0x39,0x0a,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x73,0x70,0x61,0x6e,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,
0x22,0x6c,0x69,0x67,0x68,0x74,0x22,0x3e,0x26,0x23,0x31,0x32,0x34,0x3b,0x3c,0x2f,0x73,0x70,0x61,0x6e,0x3e,0x0a,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x61,0x20,0x68,0x72,0x65,0x66,0x3d,0x22,0x68,
0x74,0x74,0x70,0x73,0x3a,0x2f,0x2f,0x73,0x65,0x6e,0x61,0x6e,0x2e,0x78,0x79,0x7a,0x2f,0x67,0x2f,0x67,0x6f,0x6e,0x69,0x63,
0x22,0x3e,0x67,0x69,0x74,0x68,0x75,0x62,0x3c,0x2f,0x61,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x3c,0x2f,0x64,0x69,0x76,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x2f,0x64,0x69,0x76,0x3e,0x0a,0x20,
0x20,0x20,0x20,0x3c,0x2f,0x62,0x6f,0x64,0x79,0x3e,0x0a,0x3c,0x2f,0x68,0x74,0x6d,0x6c,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,
0x64,0x20,0x7d,0x7d,0x0a,
}},
"layouts/user.tmpl": &EmbeddedAsset{
ModTime: time.Unix(1565384362, 0),

View File

@@ -18,6 +18,7 @@
{{ end }}
{{ template "content" . }}
<div class="side-padded text-right">
<span class="light">{{ .Version }}</span>
senan kelly, 2019
<span class="light">&#124;</span>
<a href="https://senan.xyz/g/gonic">github</a>

View File

@@ -11,6 +11,7 @@ import (
"senan.xyz/g/gonic/db"
"senan.xyz/g/gonic/server"
"senan.xyz/g/gonic/version"
)
const (
@@ -19,6 +20,8 @@ const (
)
func main() {
log.Println("starting gonic")
log.Printf("version %q\n", version.VERSION)
set := flag.NewFlagSet(programName, flag.ExitOnError)
listenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)")
musicPath := set.String("music-path", "", "path to music")

1
go.mod
View File

@@ -14,7 +14,6 @@ require (
github.com/imdario/mergo v0.3.7 // indirect
github.com/jinzhu/gorm v1.9.9
github.com/josephburnett/jd v0.0.0-20190531151850-1f9071c800e7
github.com/justinas/alice v0.0.0-20171023064455-03f45bd4b7da
github.com/karrick/godirwalk v1.10.12
github.com/kr/pretty v0.1.0 // indirect
github.com/nicksellen/audiotags v0.0.0-20160226222119-94015fa599bd

3
go.sum
View File

@@ -85,8 +85,6 @@ github.com/josephburnett/jd v0.0.0-20190531151850-1f9071c800e7 h1:/sW5BavO4uIUSq
github.com/josephburnett/jd v0.0.0-20190531151850-1f9071c800e7/go.mod h1:aeV+6oc13ogwzcRNHBe4vbyLmoQxMfEDoqyqCU9oE30=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/justinas/alice v0.0.0-20171023064455-03f45bd4b7da h1:5y58+OCjoHCYB8182mpf/dEsq0vwTKPOo4zGfH0xW9A=
github.com/justinas/alice v0.0.0-20171023064455-03f45bd4b7da/go.mod h1:oLH0CmIaxCGXD67VKGR5AacGXZSMznlmeqM8RzPrcY8=
github.com/karrick/godirwalk v1.10.12 h1:BqUm+LuJcXjGv1d2mj3gBiQyrQ57a0rYoAmhvJQ7RDU=
github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
@@ -227,5 +225,6 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a h1:LJwr7TCTghdatWv40WobzlKXc9c4s8oGa7QKJUtHhWA=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

View File

@@ -20,6 +20,7 @@ import (
"senan.xyz/g/gonic/model"
"senan.xyz/g/gonic/server/ctrlbase"
"senan.xyz/g/gonic/server/key"
"senan.xyz/g/gonic/version"
)
func init() {
@@ -88,6 +89,7 @@ type templateData struct {
// common
Flashes []interface{}
User *model.User
Version string
// home
AlbumCount int
ArtistCount int
@@ -146,6 +148,7 @@ func (c *Controller) H(h adminHandler) http.Handler {
if resp.data == nil {
resp.data = &templateData{}
}
resp.data.Version = version.VERSION
if session != nil {
resp.data.Flashes = session.Flashes()
if err := session.Save(r, w); err != nil {

7
version/version.go Normal file
View File

@@ -0,0 +1,7 @@
// generated by `_do_build_server` script in project root
// Wed Nov 27 15:19:12 GMT 2019
// DO NOT EDIT
package version
const VERSION = "v0.3.0-1-g2b3825b"