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

feat: fill version with git and ldflags #180

Merged
merged 3 commits into from
May 14, 2024
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: 0 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
strategy:
matrix:
version: ['1.18']
env:
GORELEASER_CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ builds:
- linux
- windows
- darwin
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}}'
archives:
- name_template: >-
{{ .ProjectName }}_
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
.EXPORT_ALL_VARIABLES:

VERSION := $(shell git describe --abbrev=0 --tags | tr -d v)
COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS := -X 'main.version=$(VERSION)' \
-X 'main.commit=$(COMMIT)'

.PHONY: build
build:
go build -o dist/yamlfmt ./cmd/yamlfmt
go build -ldflags "$(LDFLAGS)" -o dist/yamlfmt ./cmd/yamlfmt

.PHONY: test
test:
Expand Down Expand Up @@ -43,7 +48,7 @@ endif

.PHONY: install
install:
go install ./cmd/yamlfmt
go install -ldflags "$(LDFLAGS)" ./cmd/yamlfmt

.PHONY: install_tools
install_tools:
Expand Down
7 changes: 5 additions & 2 deletions cmd/yamlfmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (
"github.com/google/yamlfmt/internal/logger"
)

var version string = "0.12.0"
var (
version = "dev"
commit = "none"
)

func main() {
if err := run(); err != nil {
Expand All @@ -41,7 +44,7 @@ func run() error {
flag.Parse()

if *flagVersion {
fmt.Printf("%s\n", version)
fmt.Printf("yamlfmt %s (%s)\n", version, commit)
return nil
}

Expand Down
Loading