From 731101f82e1c715bd855603c9ec38bab6dff71e9 Mon Sep 17 00:00:00 2001 From: John McBride Date: Mon, 28 Aug 2023 09:53:06 -0600 Subject: [PATCH] feat: Version command for CLI based on release builds Signed-off-by: John McBride --- .github/workflows/release.yaml | 2 ++ README.md | 8 +++++++- cmd/root/root.go | 2 ++ cmd/version/version.go | 18 ++++++++++++++++++ pkg/utils/version.go | 6 ++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 cmd/version/version.go create mode 100644 pkg/utils/version.go diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6adb8d1..e994b1f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -71,5 +71,7 @@ jobs: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \ -ldflags="-s -w" \ -ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${{ secrets.POSTHOG_WRITE_PUBLIC_KEY }}'" \ + -ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version={{ needs.release.outputs.release-tag }}'" \ + -ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \ -o build/pizza-${{ matrix.goos }}-${{ matrix.goarch }} gh release upload ${{ needs.release.outputs.release-tag }} build/pizza-${{ matrix.goos }}-${{ matrix.goarch }} diff --git a/README.md b/README.md index e0aba3f..75c2ea2 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,15 @@ Available Commands: help Help about any command login Log into the CLI application via GitHub repo-query Ask questions about a GitHub repository + version Displays the build version of the CLI Flags: - -h, --help help for pizza + --beta Shorthand for using the beta OpenSauced API endpoint + ("https://beta.api.opensauced.pizza/v1"). Superceds the + '--endpoint' flag + -e, --endpoint string The API endpoint to send requests to (default + "https://api.opensauced.pizza/v1") + -h, --help help for pizza Use "pizza [command] --help" for more information about a command. ``` diff --git a/cmd/root/root.go b/cmd/root/root.go index fbb71e5..e19a6da 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -9,6 +9,7 @@ import ( "github.com/open-sauced/pizza-cli/cmd/auth" "github.com/open-sauced/pizza-cli/cmd/bake" repoquery "github.com/open-sauced/pizza-cli/cmd/repo-query" + "github.com/open-sauced/pizza-cli/cmd/version" "github.com/open-sauced/pizza-cli/pkg/api" ) @@ -28,6 +29,7 @@ func NewRootCommand() (*cobra.Command, error) { cmd.AddCommand(bake.NewBakeCommand()) cmd.AddCommand(repoquery.NewRepoQueryCommand()) cmd.AddCommand(auth.NewLoginCommand()) + cmd.AddCommand(version.NewVersionCommand()) return cmd, nil } diff --git a/cmd/version/version.go b/cmd/version/version.go new file mode 100644 index 0000000..87871e1 --- /dev/null +++ b/cmd/version/version.go @@ -0,0 +1,18 @@ +package version + +import ( + "fmt" + + "github.com/open-sauced/pizza-cli/pkg/utils" + "github.com/spf13/cobra" +) + +func NewVersionCommand() *cobra.Command { + return &cobra.Command{ + Use: "version", + Short: "Displays the build version of the CLI", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("Version: %s\nSha: %s\n", utils.Version, utils.Sha) + }, + } +} diff --git a/pkg/utils/version.go b/pkg/utils/version.go new file mode 100644 index 0000000..2630970 --- /dev/null +++ b/pkg/utils/version.go @@ -0,0 +1,6 @@ +package utils + +var ( + Version = "dev" + Sha = "HEAD" +)