Skip to content

Commit b52c879

Browse files
CR-6448-install-only-with-latest (#128)
* init commit * bump * removed redundant * status code error and using store * naming and removed comment * tidy * typo fix * tested through changing makefile version * cli - waiting for merged ap * added comment * added comment * added comment * without params getgitprovider * removed redundant and changed comment * removed redundant arg * verification in all commands using platform * bump sdk * removed redundant * getting string instead of release model * remove local go mod * bump * without local sdk * tidy * return err instead of additional log * return err instead of additional log
1 parent 6039477 commit b52c879

File tree

11 files changed

+89
-12
lines changed

11 files changed

+89
-12
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.121
1+
VERSION=v0.0.122
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/common.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
package commands
1616

1717
import (
18+
"context"
1819
_ "embed"
1920
"fmt"
2021
"os"
2122
"regexp"
2223

24+
"github.com/Masterminds/semver/v3"
2325
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
2426
"github.com/codefresh-io/cli-v2/pkg/config"
27+
"github.com/codefresh-io/cli-v2/pkg/store"
2528
"github.com/codefresh-io/cli-v2/pkg/util"
2629

2730
"github.com/spf13/cobra"
@@ -61,12 +64,12 @@ func IsValid(s string) (bool, error) {
6164
return regexp.MatchString(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`, s)
6265
}
6366

64-
func ensureRepo(cmd *cobra.Command, args []string, cloneOpts *git.CloneOptions) error {
67+
func ensureRepo(cmd *cobra.Command, args []string, cloneOpts *git.CloneOptions) error {
6568
ctx := cmd.Context()
6669
if cloneOpts.Repo == "" {
6770
runtimeData, err := cfConfig.NewClient().V2().Runtime().Get(ctx, args[0])
6871
if err != nil {
69-
return fmt.Errorf("Failed getting runtime repo information: %w", err)
72+
return fmt.Errorf("failed getting runtime repo information: %w", err)
7073
}
7174
if runtimeData.Repo != nil {
7275
cloneOpts.Repo = *runtimeData.Repo
@@ -75,3 +78,19 @@ func ensureRepo(cmd *cobra.Command, args []string, cloneOpts *git.CloneOptions)
7578
}
7679
return nil
7780
}
81+
82+
func verifyLatestVersion(ctx context.Context) error {
83+
latestVersionString, err := cfConfig.NewClient().V2().CliReleases().GetLatest(ctx)
84+
if err != nil {
85+
return fmt.Errorf("failed getting latest cli release: %w", err)
86+
}
87+
88+
latestVersionSemver := semver.MustParse(latestVersionString)
89+
currentVersion := store.Get().Version.Version
90+
91+
if currentVersion.LessThan(latestVersionSemver) {
92+
return fmt.Errorf("please upgrade to the latest cli version: %s", latestVersionString)
93+
}
94+
95+
return nil
96+
}

cmd/commands/component.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func NewComponentListCommand() *cobra.Command {
5959
RunE: func(cmd *cobra.Command, args []string) error {
6060
ctx := cmd.Context()
6161

62+
if err := verifyLatestVersion(ctx); err != nil {
63+
return err
64+
}
65+
6266
return RunComponentList(ctx, args[0])
6367
},
6468
}

cmd/commands/git-source.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
133133
if gsCloneOpts.Repo == "" {
134134
log.G(ctx).Fatal("must enter a valid value to --git-src-repo. Example: https://github.com/owner/repo-name/path/to/workflow")
135135
}
136-
136+
137137
err := ensureRepo(cmd, args, insCloneOpts)
138138
if err != nil {
139139
return err
@@ -159,6 +159,10 @@ func NewGitSourceCreateCommand() *cobra.Command {
159159
RunE: func(cmd *cobra.Command, args []string) error {
160160
ctx := cmd.Context()
161161

162+
if err := verifyLatestVersion(ctx); err != nil {
163+
return err
164+
}
165+
162166
return RunGitSourceCreate(ctx, &GitSourceCreateOptions{
163167
InsCloneOpts: insCloneOpts,
164168
GsCloneOpts: gsCloneOpts,
@@ -372,7 +376,13 @@ func NewGitSourceListCommand() *cobra.Command {
372376
}
373377
},
374378
RunE: func(cmd *cobra.Command, args []string) error {
375-
return RunGitSourceList(cmd.Context(), args[0])
379+
ctx := cmd.Context()
380+
381+
if err := verifyLatestVersion(ctx); err != nil {
382+
return err
383+
}
384+
385+
return RunGitSourceList(ctx, args[0])
376386
},
377387
}
378388
return cmd
@@ -468,6 +478,10 @@ func NewGitSourceDeleteCommand() *cobra.Command {
468478
RunE: func(cmd *cobra.Command, args []string) error {
469479
ctx := cmd.Context()
470480

481+
if err := verifyLatestVersion(ctx); err != nil {
482+
return err
483+
}
484+
471485
return RunGitSourceDelete(ctx, &GitSourceDeleteOptions{
472486
RuntimeName: args[0],
473487
GsName: args[1],
@@ -538,6 +552,10 @@ func NewGitSourceEditCommand() *cobra.Command {
538552
RunE: func(cmd *cobra.Command, args []string) error {
539553
ctx := cmd.Context()
540554

555+
if err := verifyLatestVersion(ctx); err != nil {
556+
return err
557+
}
558+
541559
return RunGitSourceEdit(ctx, &GitSourceEditOptions{
542560
RuntimeName: args[0],
543561
GsName: args[1],

cmd/commands/pipeline.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func NewPipelineGetCommand() *cobra.Command {
6262
RunE: func(cmd *cobra.Command, args []string) error {
6363
ctx := cmd.Context()
6464

65+
if err := verifyLatestVersion(ctx); err != nil {
66+
return err
67+
}
68+
6569
return RunPipelineGet(ctx, name, namespace, runtime)
6670
},
6771
}
@@ -97,6 +101,10 @@ func NewPipelineListCommand() *cobra.Command {
97101
RunE: func(cmd *cobra.Command, args []string) error {
98102
ctx := cmd.Context()
99103

104+
if err := verifyLatestVersion(ctx); err != nil {
105+
return err
106+
}
107+
100108
filterArgs := model.PipelinesFilterArgs{
101109
Name: &name,
102110
Namespace: &namespace,

cmd/commands/runtime.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ func installComponents(ctx context.Context, opts *RuntimeInstallOptions, rt *run
386386
func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) error {
387387
log.G(ctx).Debug("running pre-installation checks...")
388388

389+
if err := verifyLatestVersion(ctx); err != nil {
390+
return err
391+
}
392+
389393
if err := checkRuntimeCollisions(ctx, opts.RuntimeName, opts.KubeFactory); err != nil {
390394
return fmt.Errorf("runtime collision check failed: %w", err)
391395
}
@@ -592,10 +596,15 @@ func NewRuntimeUninstallCommand() *cobra.Command {
592596
},
593597
RunE: func(cmd *cobra.Command, args []string) error {
594598
ctx := cmd.Context()
599+
595600
if len(args) < 1 {
596601
log.G(ctx).Fatal("must enter runtime name")
597602
}
598603

604+
if err := verifyLatestVersion(ctx); err != nil {
605+
return err
606+
}
607+
599608
return RunRuntimeUninstall(ctx, &RuntimeUninstallOptions{
600609
RuntimeName: args[0],
601610
Timeout: store.Get().WaitTimeout,
@@ -620,6 +629,10 @@ func NewRuntimeUninstallCommand() *cobra.Command {
620629
}
621630

622631
func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) error {
632+
if err := verifyLatestVersion(ctx); err != nil {
633+
return err
634+
}
635+
623636
// check whether the runtime exists
624637
if !opts.SkipChecks {
625638
_, err := cfConfig.NewClient().V2().Runtime().Get(ctx, opts.RuntimeName)
@@ -702,6 +715,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
702715
err error
703716
)
704717
ctx := cmd.Context()
718+
705719
if len(args) < 1 {
706720
log.G(ctx).Fatal("must enter runtime name")
707721
}
@@ -713,6 +727,10 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
713727
}
714728
}
715729

730+
if err := verifyLatestVersion(ctx); err != nil {
731+
return err
732+
}
733+
716734
return RunRuntimeUpgrade(ctx, &RuntimeUpgradeOptions{
717735
RuntimeName: args[0],
718736
Version: version,

cmd/commands/workflow.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func NewWorkflowGetCommand() *cobra.Command {
5959
RunE: func(cmd *cobra.Command, args []string) error {
6060
ctx := cmd.Context()
6161

62+
if err := verifyLatestVersion(ctx); err != nil {
63+
return err
64+
}
65+
6266
return RunWorkflowGet(ctx, args[0])
6367
},
6468
}
@@ -86,6 +90,10 @@ func NewWorkflowListCommand() *cobra.Command {
8690
RunE: func(cmd *cobra.Command, args []string) error {
8791
ctx := cmd.Context()
8892

93+
if err := verifyLatestVersion(ctx); err != nil {
94+
return err
95+
}
96+
8997
filterArgs := model.WorkflowsFilterArgs{
9098
Namespace: &namespace,
9199
Runtime: &runtime,

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cf version
2020
### Linux
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.121/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.122/cf-linux-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -32,7 +32,7 @@ cf version
3232
### Mac
3333
```bash
3434
# download and extract the binary
35-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.121/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.122/cf-darwin-amd64.tar.gz | tar zx
3636

3737
# move the binary to your $PATH
3838
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/argoproj/argo-events v1.4.0
1111
github.com/argoproj/argo-workflows/v3 v3.1.6
1212
github.com/briandowns/spinner v1.16.0
13-
github.com/codefresh-io/go-sdk v0.34.12
13+
github.com/codefresh-io/go-sdk v0.35.0
1414
github.com/fatih/color v1.12.0
1515
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1616
github.com/go-git/go-billy/v5 v5.3.1
@@ -23,6 +23,7 @@ require (
2323
github.com/spf13/pflag v1.0.5
2424
github.com/spf13/viper v1.7.1
2525
github.com/stretchr/testify v1.7.0
26+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
2627
k8s.io/api v0.21.3
2728
k8s.io/apimachinery v0.21.1
2829
k8s.io/client-go v11.0.1-0.20190816222228-6d55c1b1f1ca+incompatible

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313/go.mod h1:P1w
262262
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
263263
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
264264
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
265-
github.com/codefresh-io/go-sdk v0.34.12 h1:cwUa1DD4yQ16xuUDHRik6M5GK+I2xkX2ADWNCnsQkOM=
266-
github.com/codefresh-io/go-sdk v0.34.12/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
265+
github.com/codefresh-io/go-sdk v0.35.0 h1:v+1E8hfIho8yi4E1bdccwjzMCBeKpOzKrJ9nTFC6ohw=
266+
github.com/codefresh-io/go-sdk v0.35.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
267267
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
268268
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
269269
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
@@ -1381,8 +1381,9 @@ golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPh
13811381
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
13821382
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
13831383
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
1384-
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
13851384
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
1385+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
1386+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
13861387
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
13871388
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
13881389
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=

0 commit comments

Comments
 (0)