Skip to content

Commit 3b971e3

Browse files
committed
Replace commit.txt with ldflags value
1 parent ca4ff63 commit 3b971e3

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

.github/workflows/test-build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
- name: Go Generate
3636
run: |
3737
go generate ./...
38-
cat tracing/commit.txt
3938
4039
- name: Validate Docs Data
4140
run: |

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ vendor
77
Gopkg.lock
88
build/compiled
99
.idea
10-
commit.txt
1110
.envrc
1211
.golangci.yml

build/package/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ COPY . .
2323
RUN --mount=type=cache,target=/go/pkg \
2424
--mount=type=cache,target=/root/.cache/go-build \
2525
go generate ./... \
26-
&& GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -trimpath -o source main.go
26+
&& GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w -X github.com/overmindtech/aws-source/tracing.ServiceVersion=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD)" -trimpath -o source main.go
2727

2828
FROM alpine:3.21
2929
WORKDIR /

tracing/tracing.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ import (
2222
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
2323
)
2424

25-
//go:generate sh -c "echo -n $(git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD) > commit.txt"
26-
//go:embed commit.txt
27-
var ServiceVersion string
25+
// ServiceVersion is the version of the service. This will be overridden by the
26+
// build system, using:
27+
// go build -ldflags "-X github.com/overmindtech/api-server/tracing.ServiceVersion=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD)" -o your-app
28+
//
29+
// This allows our change detection workflow to work correctly. If we were
30+
// embedding the version here each time we would always produce a slightly
31+
// different compiled binary, and therefore it would look like there was a
32+
// change each time
33+
var ServiceVersion = "dev"
2834

2935
func tracingResource() *resource.Resource {
3036
// Identify your application using resource detection

0 commit comments

Comments
 (0)