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.
This commit is contained in:
parent
8a387ff834
commit
84c4c45d5b
4 changed files with 2 additions and 6 deletions
|
@ -11,7 +11,6 @@ sources:
|
|||
tasks:
|
||||
- test: |
|
||||
cd ntfy-alertmanager
|
||||
go generate ./...
|
||||
go test -v ./...
|
||||
- lint: |
|
||||
cd ntfy-alertmanager
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
|||
/ntfy-alertmanager
|
||||
version.txt
|
||||
|
|
|
@ -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
|
||||
|
|
4
main.go
4
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
|
||||
|
|
Loading…
Reference in a new issue