diff --git a/.forgejo/workflows/build-and-release.yaml b/.forgejo/workflows/build-and-release.yaml index 83131e2..3351bbe 100644 --- a/.forgejo/workflows/build-and-release.yaml +++ b/.forgejo/workflows/build-and-release.yaml @@ -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: | diff --git a/Containerfile b/Containerfile index 35afa7a..67272bd 100644 --- a/Containerfile +++ b/Containerfile @@ -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 diff --git a/config/version.go b/config/version.go new file mode 100644 index 0000000..d611b7c --- /dev/null +++ b/config/version.go @@ -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 + } + } + } +} diff --git a/frontend/frontend.go b/frontend/frontend.go index eb6b1f2..a57ea99 100644 --- a/frontend/frontend.go +++ b/frontend/frontend.go @@ -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) }, } )