diff --git a/.goreleaser.yml b/.goreleaser.yml index b950a64..b893a4d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,7 @@ builds: - env: + ldflags: + - -s -w -X main.version={{.Version}} goos: - darwin - windows diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..ed18ba6 --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Get the latest tag +latestTag=$(git describe --tags) + +echo "latest tag: $latestTag" + +# Build the Go program, injecting the latest tag into the version variable +go build -ldflags "-X main.version=$latestTag" -o jinjafier + diff --git a/jinjafier.go b/jinjafier.go index a30709a..96596e8 100755 --- a/jinjafier.go +++ b/jinjafier.go @@ -11,7 +11,15 @@ import ( "gopkg.in/yaml.v3" ) +var version = "dev" + func main() { + + if os.Args[1] == "-v" { + fmt.Println("Jinjafier version:", version) + os.Exit(0) + } + if len(os.Args) != 2 { fmt.Println("Usage: jinjafier ") os.Exit(1)