Add additional check that checks that the version is valid per semver

This commit is contained in:
David Dworken 2023-11-05 00:38:21 -07:00
parent acf46893e9
commit 29142df382
No known key found for this signature in database
2 changed files with 6 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import (
"github.com/ddworken/hishtory/client/lib" "github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/shared" "github.com/ddworken/hishtory/shared"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/mod/semver"
) )
var updateCmd = &cobra.Command{ var updateCmd = &cobra.Command{
@ -36,7 +37,10 @@ var validateBinaryCmd = &cobra.Command{
Args: cobra.ExactArgs(3), Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext() ctx := hctx.MakeContext()
version := args[0] version := strings.TrimSpace(args[0])
if !semver.IsValid(version) {
lib.CheckFatalError(fmt.Errorf("specified version %#v is not a valid version", version))
}
binaryPath := args[1] binaryPath := args[1]
attestationPath := args[2] attestationPath := args[2]
isMacOs, err := cmd.Flags().GetBool("is_macos") isMacOs, err := cmd.Flags().GetBool("is_macos")

View File

@ -36,6 +36,7 @@ func checkForDowngrade(currentVersionS, newVersionS string) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to parse updated version %#v", newVersionS) return fmt.Errorf("failed to parse updated version %#v", newVersionS)
} }
// TODO: migrate this to the version parser struct
if currentVersion > newVersion { if currentVersion > newVersion {
return fmt.Errorf("failed to update because the new version (%#v) is a downgrade compared to the current version (%#v)", newVersionS, currentVersionS) return fmt.Errorf("failed to update because the new version (%#v) is a downgrade compared to the current version (%#v)", newVersionS, currentVersionS)
} }