Fix version
All checks were successful
/ build-container (push) Successful in 8m0s

This commit is contained in:
Finn 2024-11-23 17:01:50 -08:00
parent 13d8ead58b
commit 060b5705c8
4 changed files with 38 additions and 2 deletions

View file

@ -21,6 +21,8 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
build-args: |
VERSION_STRING=${{ env.GITHUB_REF_NAME }}
- name: update hassio-addons
if: startsWith(github.ref, 'refs/tags/v')
run: |

View file

@ -18,7 +18,8 @@ FROM alpine:latest AS build
RUN apk add --no-cache go
ADD . /go/lockserver
WORKDIR /go/lockserver
RUN CGO_ENABLED=0 go build ./cmd/lockserver
ARG VERSION_STRING
RUN CGO_ENABLED=0 go build -ldflags "-X git.devhack.net/devhack/member-services/config.Version=${VERSION_STRING}" ./cmd/lockserver
FROM scratch
COPY --from=build /go/lockserver/lockserver /lockserver

30
config/version.go Normal file
View file

@ -0,0 +1,30 @@
package config
import (
"runtime/debug"
"github.com/sirupsen/logrus"
)
var (
BuildInfo *debug.BuildInfo
Version string
)
func init() {
var ok bool
BuildInfo, ok = debug.ReadBuildInfo()
if !ok {
logrus.Error("failed to read build info")
return
}
if Version == "" {
for _, setting := range BuildInfo.Settings {
if setting.Key == "vcs.revision" {
Version = setting.Value
break
}
}
}
}

View file

@ -2,8 +2,11 @@ package frontend
import (
"embed"
"fmt"
"html/template"
"io/fs"
"git.janky.solutions/finn/lockserver/config"
)
var (
@ -16,7 +19,7 @@ var (
Templates *template.Template
funcs = template.FuncMap{
"version": func() string { return "better-zwave-locks v0.x.x aaaaaaaa" },
"version": func() string { return fmt.Sprintf("better-zwave-locks %s", config.Version) },
}
)