Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semantic version from git tag #164

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also default to eg. "development":

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

and remove the condition lower to keep code simpler and provide consistent output structure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sounds good. I initially deemed tag is not so useful and anyone who needs can derive it from commit ID.

Copy link
Contributor Author

@stefanb stefanb Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Sounds good" as in omiting the tag if not set via ldflags (as currently implemented) or showing the "development" in such cases (as suggested as an option in this comment thread)?


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
Loading