From c63cd02100f6f73ff81da9968ee14a73d5ec7c0f Mon Sep 17 00:00:00 2001 From: Grant Arnold Date: Tue, 6 Dec 2022 18:11:43 -0800 Subject: [PATCH 1/2] Set version of app to tag when releasing automatically. --- .github/workflows/release.yaml | 5 ++++- cmd/root.go | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 832a7fa..2f715d4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,9 +18,12 @@ jobs: goos: windows steps: - uses: actions/checkout@v3 + - name: Set APP_VERSION env + run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV} - uses: wangyoucao577/go-release-action@v1.28 with: github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} - binary_name: "fmeserver" \ No newline at end of file + binary_name: "fmeserver" + ldflags: -X "github.com/safesoftare/fmeserver-cli/cmd.appVersion=${{ env.APP_VERSION }}" \ No newline at end of file diff --git a/cmd/root.go b/cmd/root.go index 374b247..9834414 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,6 +18,11 @@ var jsonOutput bool var outputType string var noHeaders bool +const notSet string = "not set" + +// this information will be collected at build time, by `-ldflags "-X github.com/safesoftare/fmeserver-cli/cmd.appVersion=0.1"` +var appVersion = notSet + var ErrSilent = errors.New("ErrSilent") // rootCmd represents the base command when called without any subcommands @@ -28,7 +33,7 @@ func NewRootCommand() *cobra.Command { Use: "fmeserver", Short: "A command line interface for interacting with FME Server.", Long: `A command line interface for interacting with FME Server.`, - Version: "0.4", + Version: appVersion, SilenceErrors: true, SilenceUsage: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { From 160e2f31e91565f684b9b9396edf2bdba84b2c26 Mon Sep 17 00:00:00 2001 From: Grant Arnold Date: Wed, 7 Dec 2022 13:45:33 -0800 Subject: [PATCH 2/2] Add build step for vscode. --- .vscode/tasks.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..e3e50dd --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build", + "type": "shell", + "windows": { + "command": "go", + "args": [ + "build", + "-ldflags=\\\"-X github.com/safesoftare/fmeserver-cli/cmd.appVersion=$(git rev-parse --short HEAD)\\\"", + "-o", + "fmeserver.exe" + ] + }, + "linux": { + "command": "go", + "args": [ + "build", + "-ldflags=\"-X github.com/safesoftare/fmeserver-cli/cmd.appVersion=$(git rev-parse --short HEAD)\"", + "-o", + "fmeserver" + ] + }, + "problemMatcher": [] + } + ] +}