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:
|
tasks:
|
||||||
- test: |
|
- test: |
|
||||||
cd ntfy-alertmanager
|
cd ntfy-alertmanager
|
||||||
go generate ./...
|
|
||||||
go test -v ./...
|
go test -v ./...
|
||||||
- lint: |
|
- lint: |
|
||||||
cd ntfy-alertmanager
|
cd ntfy-alertmanager
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
||||||
/ntfy-alertmanager
|
/ntfy-alertmanager
|
||||||
version.txt
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ WORKDIR /app
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN apk add --no-cache git
|
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
|
FROM alpine:latest
|
||||||
|
|
4
main.go
4
main.go
|
@ -19,9 +19,7 @@ import (
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate sh -c "git describe --long > version.txt"
|
var version = "dev"
|
||||||
//go:embed version.txt
|
|
||||||
var version string
|
|
||||||
|
|
||||||
type receiver struct {
|
type receiver struct {
|
||||||
cfg *config
|
cfg *config
|
||||||
|
|
Loading…
Reference in a new issue