Skip to content

Commit

Permalink
Add semantic version from git tag (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanb authored Oct 26, 2023
1 parent 25cbb49 commit 55f8e22
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push multi-arch container images
env:
VERSION_TAG: ${GITHUB_REF_NAME#v}
run: |
set -euo pipefail
tag="$(git describe --tag --always --dirty)"
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ builds:
- main: .
binary: grpc_health_probe
flags: ["-tags=netgo"] # sync changes to .ko.yml
ldflags: ["-w"] # sync changes to .ko.yml
ldflags: ["-w -X main.versionTag={{.Version}}"] # sync changes to .ko.yml
env:
- CGO_ENABLED=0
goos:
Expand Down
2 changes: 1 addition & 1 deletion .ko.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
builds:
- id: grpc_health_probe
flags: ["-tags=netgo"] # sync changes to .goreleaser.yml
ldflags: ["-w"] # sync changes to .goreleaser.yml
ldflags: ["-w -X main.versionTag={{.Env.VERSION_TAG}}"] # sync changes to .goreleaser.yml
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ func buildCredentials(skipVerify bool, caCerts, clientCert, clientKey, serverNam
return credentials.NewTLS(&cfg), nil
}

var versionTag = "" // set from git tag via ldflags during build

func probeVersion() string {
version := "vcs info was not included in build"
dirty := ""
Expand All @@ -232,6 +234,10 @@ func probeVersion() string {
if dirty == "true" {
version = version + " (dirty)"
}

if versionTag != "" {
version = fmt.Sprintf("%s; %s", versionTag, version)
}
return version
}

Expand Down

0 comments on commit 55f8e22

Please sign in to comment.