From d4116baa22c995b7ba4449863e21f1e2231efdb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20L=C3=B6sche?= Date: Wed, 24 Apr 2024 23:47:45 +0200 Subject: [PATCH] Add tag as version number --- .github/workflows/release.yml | 4 ++-- main.go | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 22c9efd..4f97201 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,11 +35,11 @@ jobs: echo "OS_NAME=$OS_NAME" >> $GITHUB_ENV - name: Build Binary (amd64) run: | - GOARCH=amd64 go build -ldflags "-s -w" -o "${{ github.workspace }}/release/fixctl-$OS_NAME-amd64-${{ github.ref_name }}$SUFFIX" + GOARCH=amd64 go build -ldflags "-s -w -X main.version=v${{ github.ref_name }}" -o "${{ github.workspace }}/release/fixctl-$OS_NAME-amd64-${{ github.ref_name }}$SUFFIX" shell: bash - name: Build Binary (arm64) run: | - GOARCH=arm64 go build -ldflags "-s -w" -o "${{ github.workspace }}/release/fixctl-$OS_NAME-arm64-${{ github.ref_name }}$SUFFIX" + GOARCH=arm64 go build -ldflags "-s -w -X main.version=v${{ github.ref_name }}" -o "${{ github.workspace }}/release/fixctl-$OS_NAME-arm64-${{ github.ref_name }}$SUFFIX" shell: bash - name: Generate Universal Binary (macOS) if: matrix.os == 'macos-latest' diff --git a/main.go b/main.go index 13cdaf1..e95722d 100644 --- a/main.go +++ b/main.go @@ -11,8 +11,10 @@ import ( "github.com/someengineering/fixctl/utils" ) +var version = "development" + func customUsage() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0]) + fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s (%s):\n", os.Args[0], version) flag.VisitAll(func(f *flag.Flag) { fmt.Fprintf(flag.CommandLine.Output(), " --%s: %s (default %q)\n", f.Name, f.Usage, f.DefValue) })