Skip to content

Commit

Permalink
feat: Version command for CLI based on release builds
Browse files Browse the repository at this point in the history
Signed-off-by: John McBride <john@opensauced.pizza>
  • Loading branch information
jpmcb committed Aug 31, 2023
1 parent 6e76260 commit 731101f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
Expand Down
2 changes: 2 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions cmd/version/version.go
Original file line number Diff line number Diff line change
@@ -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)
},
}
}
6 changes: 6 additions & 0 deletions pkg/utils/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package utils

var (
Version = "dev"
Sha = "HEAD"
)

0 comments on commit 731101f

Please sign in to comment.