diff --git a/.github/workflows/multi-arch-image-build.yaml b/.github/workflows/multi-arch-image-build.yaml index 61092ad..fc3a031 100644 --- a/.github/workflows/multi-arch-image-build.yaml +++ b/.github/workflows/multi-arch-image-build.yaml @@ -26,6 +26,9 @@ jobs: sed -i "s,FROM quay.io/konveyor/windup-shim\:latest,FROM quay.io/konveyor/windup-shim:${TAG}," Dockerfile sed -i "s,FROM quay.io/konveyor/static-report\:latest,FROM quay.io/konveyor/static-report:${TAG}," Dockerfile sed -i "s,FROM quay.io/konveyor/analyzer-lsp\:latest,FROM quay.io/konveyor/analyzer-lsp:${TAG}," Dockerfile + export BUILD_COMMIT=$(git rev-parse HEAD) + extra-args: | + --build-arg VERSION=${tag} --build-arg BUILD_COMMIT=${BUILD_COMMIT} secrets: registry_username: ${{ secrets.QUAY_PUBLISH_ROBOT }} registry_password: ${{ secrets.QUAY_PUBLISH_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 4ad825e..dda683e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,9 +24,11 @@ COPY main.go main.go COPY cmd/ cmd/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o kantra main.go -RUN CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -o darwin-kantra main.go -RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -o windows-kantra main.go +ARG VERSION +ARG BUILD_COMMIT +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT'" -a -o kantra main.go +RUN CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT'" -a -o darwin-kantra main.go +RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT'" -a -o windows-kantra main.go FROM quay.io/konveyor/analyzer-lsp:latest diff --git a/cmd/root.go b/cmd/root.go index dfedd58..299f53c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,7 +24,7 @@ var noCleanup bool // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Short: "A cli tool for analysis and transformation of applications", + Short: "A CLI tool for analysis and transformation of applications", Long: ``, SilenceUsage: true, PersistentPreRun: func(cmd *cobra.Command, args []string) { @@ -46,6 +46,7 @@ func init() { logger := logrusr.New(logrusLog) rootCmd.AddCommand(NewTransformCommand(logger)) rootCmd.AddCommand(NewAnalyzeCmd(logger)) + rootCmd.AddCommand(NewVersionCommand()) } // Execute adds all child commands to the root command and sets flags appropriately. diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..f553ca3 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + BuildCommit = "" + Version = "v99.0.0" +) + +// Use build flags to set correct Version and BuildCommit +// e.g.: +// --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=1.2.3' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$(git rev-parse HEAD)'" +func NewVersionCommand() *cobra.Command { + versionCmd := &cobra.Command{ + Use: "version", + Short: "Print the tool version", + Long: "Print this tool version number", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("version: %s\n", Version) + fmt.Printf("SHA: %s\n", BuildCommit) + }, + } + return versionCmd +}