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 support for a version command to check the binary version #188

Merged
merged 1 commit into from
Oct 14, 2023

Conversation

iveelsm
Copy link

@iveelsm iveelsm commented Oct 13, 2023

Adds a simple semantic version configuration and flag to print the version and exit. Test coverage is present for the general additions to version info, however here are some additional test cases I ran manually.

Version on the current branch

; make out/main-darwin                          
CGO_ENABLED=0 GOOS=darwin go build -a -installsuffix cgo -ldflags="-s -w -X 'github.com/kuskoman/logstash-exporter/config.Version=mikey/version-command' -X 'github.com/kuskoman/logstash-exporter/config.SemanticVersion=v1.5.4-3-g5fd1' -X 'github.com/kuskoman/logstash-exporter/config.GitCommit=5fd14993d6e767e0ba81c4aac0bdeedc5658a6a0' -X 'github.com/kuskoman/logstash-exporter/config.BuildDate=2023-10-13T21:59:38UTC'" -o out/main-darwin cmd/exporter/main.go
; ./out/main-darwin -version
v1.5.4-3-g5fd1

Version when adding a tag

; git tag v1.5.5
; make out/main-darwin      
CGO_ENABLED=0 GOOS=darwin go build -a -installsuffix cgo -ldflags="-s -w -X 'github.com/kuskoman/logstash-exporter/config.Version=mikey/version-command' -X 'github.com/kuskoman/logstash-exporter/config.SemanticVersion=v1.5.5' -X 'github.com/kuskoman/logstash-exporter/config.GitCommit=5fd14993d6e767e0ba81c4aac0bdeedc5658a6a0' -X 'github.com/kuskoman/logstash-exporter/config.BuildDate=2023-10-13T22:01:19UTC'" -o out/main-darwin cmd/exporter/main.go
; ./out/main-darwin -version
v1.5.5

Version when the commit is dirty

; make out/main-darwin      
CGO_ENABLED=0 GOOS=darwin go build -a -installsuffix cgo -ldflags="-s -w -X 'github.com/kuskoman/logstash-exporter/config.Version=mikey/version-command' -X 'github.com/kuskoman/logstash-exporter/config.SemanticVersion=v1.5.4-3-g5fd1-dirty' -X 'github.com/kuskoman/logstash-exporter/config.GitCommit=5fd14993d6e767e0ba81c4aac0bdeedc5658a6a0' -X 'github.com/kuskoman/logstash-exporter/config.BuildDate=2023-10-13T22:00:34UTC'" -o out/main-darwin cmd/exporter/main.go
; ./out/main-darwin -version
v1.5.4-3-g5fd1-dirty

@iveelsm
Copy link
Author

iveelsm commented Oct 13, 2023

Closes #187

@iveelsm iveelsm force-pushed the mikey/version-command branch from 5fd1499 to e6e4e53 Compare October 13, 2023 22:03
Repository owner deleted a comment from sweep-ai bot Oct 13, 2023
@kuskoman
Copy link
Owner

That is a very elegant solution, I really like it. i approved the CI/CD pipeline and i will checkut the code locally to test it myself tommorow, then merge it to master. Thank you for your contribution!

@iveelsm iveelsm force-pushed the mikey/version-command branch from e6e4e53 to b3dc1a7 Compare October 13, 2023 22:13
@iveelsm
Copy link
Author

iveelsm commented Oct 13, 2023

Sounds good! I fixed the one unit test, so we should be good to go.

@codecov
Copy link

codecov bot commented Oct 14, 2023

Codecov Report

All modified lines are covered by tests ✅

Files Coverage Δ
config/version.go 100.00% <100.00%> (ø)

📢 Thoughts on this report? Let us know!.

@kuskoman
Copy link
Owner

I tested it locally and it works like a charm, merging

@kuskoman kuskoman merged commit afbd3d0 into kuskoman:master Oct 14, 2023
16 checks passed
@kuskoman kuskoman added the enhancement New feature or request label Oct 14, 2023
@kuskoman
Copy link
Owner

i released new tag, v1.5.5, it actually should be v1.6.0 i think but i released it without thinking and renaming a tag would cause more problems than leaving it as-is. thank you for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants