From 84c4c45d5b3b2c690d5be4f06004b96abfd15ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Thu, 16 Feb 2023 13:06:21 +0100 Subject: [PATCH] version: Use linker flag Embedding the version file is slightly annoying for packaging, because the release tarball is not a git repository and so "go generate" would fail. Instead a packager would have to manually create the version.txt file. With using a linker flag, the version string has a graceful fallback. --- .build.yml | 1 - .gitignore | 1 - docker/Dockerfile-dev | 2 +- main.go | 4 +--- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.build.yml b/.build.yml index 1e22572..698ed39 100644 --- a/.build.yml +++ b/.build.yml @@ -11,7 +11,6 @@ sources: tasks: - test: | cd ntfy-alertmanager - go generate ./... go test -v ./... - lint: | cd ntfy-alertmanager diff --git a/.gitignore b/.gitignore index 2b0be1e..6948ee2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /ntfy-alertmanager -version.txt diff --git a/docker/Dockerfile-dev b/docker/Dockerfile-dev index fe5031e..5c340b2 100644 --- a/docker/Dockerfile-dev +++ b/docker/Dockerfile-dev @@ -3,7 +3,7 @@ WORKDIR /app COPY . . RUN apk add --no-cache git -RUN go generate ./... && go build -o /app/ntfy-alertmanager +RUN go build -ldflags="-X main.version=$(git describe --long)" -o /app/ntfy-alertmanager FROM alpine:latest diff --git a/main.go b/main.go index cd0500c..6958636 100644 --- a/main.go +++ b/main.go @@ -19,9 +19,7 @@ import ( "golang.org/x/text/language" ) -//go:generate sh -c "git describe --long > version.txt" -//go:embed version.txt -var version string +var version = "dev" type receiver struct { cfg *config