From e91ff311a2a4d33caef9486793cece5227f47833 Mon Sep 17 00:00:00 2001 From: Surendra Pathak Date: Thu, 13 Jul 2023 01:50:35 -0700 Subject: [PATCH] [NO-TKT] Version for containerized app --- Dockerfile | 2 +- cmd/root.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 53f76f7..6f69d95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.20-alpine AS builder LABEL org.opencontainers.image.source="https://github.com/interlynk-io/sbomasm" -RUN apk add --no-cache make +RUN apk add --no-cache make git WORKDIR /app COPY go.mod go.sum ./ RUN go mod download diff --git a/cmd/root.go b/cmd/root.go index be0b50b..7baf831 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,6 +18,7 @@ import ( "fmt" "os" + "github.com/Masterminds/semver/v3" "github.com/google/go-github/v52/github" "github.com/spf13/cobra" version "sigs.k8s.io/release-utils/version" @@ -26,7 +27,7 @@ import ( // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "sbomasm", - Short: "sbomasm is your primary tool to assemble SBOMs, for easy management and distribution.", + Short: "sbomasm is your primary tool to assemble SBOMs, for easy management and distribution.", Long: `sbomasm is your primary tool to assemble SBOMs, for easy management and distribution. The tool can process both spdx and cyclonedx input sboms, it autotects the file formats for input sboms. The tool can output both spdx and cyclonedx sboms. Multiple algorithms are supported for assembling component sboms @@ -74,7 +75,18 @@ func checkIfLatestRelease() { return } - if rr.GetTagName() != version.GetVersionInfo().GitVersion { + verLatest, err := semver.NewVersion(version.GetVersionInfo().GitVersion) + if err != nil { + return + } + + verInstalled, err := semver.NewVersion(rr.GetTagName()) + if err != nil { + return + } + + result := verInstalled.Compare(verLatest) + if result < 0 { fmt.Printf("\nA new version of sbomasm is available %s.\n\n", rr.GetTagName()) } }