Skip to content

Commit ea5108b

Browse files
Cr 15334 - added upgrade command (#649)
* added version check * added upgrade command * added upgrade command * small fix * fixing linting issues
1 parent b5f8c03 commit ea5108b

File tree

11 files changed

+473
-12
lines changed

11 files changed

+473
-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.1.11
1+
VERSION=v0.1.12
22

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

cmd/commands/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ variables in advanced to simplify the use of those commands.
4949
cfConfig = config.AddFlags(cmd.PersistentFlags())
5050

5151
cmd.AddCommand(NewVersionCommand())
52+
cmd.AddCommand(NewUpgradeCommand())
5253
cmd.AddCommand(NewConfigCommand())
5354
cmd.AddCommand(NewRuntimeCommand())
5455
cmd.AddCommand(NewGitSourceCommand())

cmd/commands/upgrade.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2022 The Codefresh Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package commands
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
20+
cliutil "github.com/codefresh-io/cli-v2/pkg/util/cli"
21+
)
22+
23+
func NewUpgradeCommand() *cobra.Command {
24+
var opts struct {
25+
version string
26+
output string
27+
}
28+
29+
cmd := &cobra.Command{
30+
Use: "upgrade",
31+
Short: "Upgrades the cli",
32+
Annotations: map[string]string{
33+
cliutil.SkipVersionCheck: "true",
34+
},
35+
Args: cobra.NoArgs,
36+
RunE: func(cmd *cobra.Command, args []string) error {
37+
return cliutil.UpgradeCLIToVersion(cmd.Context(), opts.version, opts.output)
38+
},
39+
}
40+
41+
cmd.Flags().StringVar(&opts.version, "version", "", "Specify a cli version to upgrade to")
42+
cmd.Flags().StringVarP(&opts.output, "ouput", "o", "", "Where to save the new binary (default: replace the old binary)")
43+
44+
return cmd
45+
}

cmd/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/codefresh-io/cli-v2/pkg/reporter"
2424
"github.com/codefresh-io/cli-v2/pkg/util"
2525
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
26+
cliutil "github.com/codefresh-io/cli-v2/pkg/util/cli"
2627

2728
"github.com/sirupsen/logrus"
2829
)
@@ -37,6 +38,8 @@ func main() {
3738

3839
c := commands.NewRoot()
3940

41+
cliutil.AddCLIVersionCheck(c)
42+
4043
lgr.AddPFlags(c)
4144

4245
// configure autopilot logger

docs/commands/cli-v2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ cli-v2 [flags]
4040
* [cli-v2 integration](cli-v2_integration.md) - Manage integrations with git providers, container registries and more
4141
* [cli-v2 pipeline](cli-v2_pipeline.md) - Manage pipelines of Codefresh runtimes
4242
* [cli-v2 runtime](cli-v2_runtime.md) - Manage Codefresh runtimes
43+
* [cli-v2 upgrade](cli-v2_upgrade.md) - Upgrades the cli
4344
* [cli-v2 version](cli-v2_version.md) - Show cli version
4445
* [cli-v2 workflow](cli-v2_workflow.md) - Manage workflows of Codefresh runtimes
4546

docs/commands/cli-v2_upgrade.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## cli-v2 upgrade
2+
3+
Upgrades the cli
4+
5+
```
6+
cli-v2 upgrade [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-h, --help help for upgrade
13+
-o, --ouput string Where to save the new binary (default: replace the old binary)
14+
--version string Specify a cli version to upgrade to
15+
```
16+
17+
### Options inherited from parent commands
18+
19+
```
20+
--auth-context string Run the next command using a specific authentication context
21+
--cfconfig string Custom path for authentication contexts config file (default "/home/user")
22+
--insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io)
23+
--insecure-ingress-host Disable certificate validation of ingress host (default: false)
24+
--request-timeout duration Request timeout (default 30s)
25+
```
26+
27+
### SEE ALSO
28+
29+
* [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops
30+

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.11/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.12/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.11/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.12/cf-darwin-amd64.tar.gz | tar zx
4040

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

hack/release.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ if [[ -z "$VERSION" ]]; then
99
exit 1
1010
fi
1111

12+
echo "$VERSION" > ./dist/version.txt
13+
1214
if [[ -z "$GITHUB_TOKEN" ]]; then
1315
echo "error: GITHUB_TOKEN token not defined"
1416
exit 1
@@ -19,7 +21,7 @@ if [[ -z "$PRERELEASE" ]]; then
1921
fi
2022

2123
echo "uploading files:"
22-
ls -1a ./dist/*.tar.gz ./dist/*.sha256 ./manifests/runtime.yaml
24+
ls -1a ./dist/version.txt ./dist/*.tar.gz ./dist/*.sha256 ./manifests/runtime.yaml
2325
echo ""
2426

2527
FILE="./docs/releases/release_notes.md"
@@ -28,8 +30,8 @@ cat $FILE | head -n 5 && echo ...
2830
echo ""
2931

3032
if [[ "$DRY_RUN" == "1" ]]; then
31-
echo "gh release create --repo $GIT_REPO -t $VERSION -F $FILE --prerelease=$PRERELEASE $VERSION ./dist/*.tar.gz ./dist/*.sha256 ./manifests/runtime.yaml"
33+
echo "gh release create --repo $GIT_REPO -t $VERSION -F $FILE --prerelease=$PRERELEASE $VERSION ./dist/version.txt ./dist/*.tar.gz ./dist/*.sha256 ./manifests/runtime.yaml"
3234
exit 0
3335
fi
3436

35-
gh release create --repo $GIT_REPO -t $VERSION -F $FILE --prerelease=$PRERELEASE $VERSION ./dist/*.tar.gz ./dist/*.sha256 ./manifests/runtime.yaml
37+
gh release create --repo $GIT_REPO -t $VERSION -F $FILE --prerelease=$PRERELEASE $VERSION ./dist/version.txt ./dist/*.tar.gz ./dist/*.sha256 ./manifests/runtime.yaml

pkg/log/logrus.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ func GetLogrusEntry(l Logger) (*logrus.Entry, error) {
6262
return adpt.Entry, nil
6363
}
6464

65-
func initCommands(cmds []*cobra.Command, initFunc func(*cobra.Command)) {
66-
for _, cmd := range cmds {
67-
initFunc(cmd)
68-
if cmd.HasSubCommands() {
69-
initCommands(cmd.Commands(), initFunc)
65+
func initCommands(cmd *cobra.Command, initFunc func(*cobra.Command)) {
66+
initFunc(cmd)
67+
68+
for _, subCmd := range cmd.Commands() {
69+
if subCmd.HasSubCommands() {
70+
initCommands(subCmd, initFunc)
71+
} else {
72+
initFunc(subCmd)
7073
}
7174
}
7275
}
@@ -104,7 +107,7 @@ func (l *logrusAdapter) AddPFlags(cmd *cobra.Command) {
104107
}
105108
}
106109

107-
cobra.OnInitialize(func() { initCommands(cmd.Commands(), initFunc) })
110+
cobra.OnInitialize(func() { initCommands(cmd, initFunc) })
108111

109112
cmdutil.LogFormat = *format
110113
cmdutil.LogLevel = l.c.Level

pkg/store/store.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ type Store struct {
133133
RequirementsLink string
134134
GitTokensLink string
135135
DownloadCliLink string
136+
CLIDownloadTemplate string
137+
CLILatestVersionFileLink string
136138
RolloutReporterName string
137139
RolloutResourceName string
138140
RolloutReporterServiceAccount string
@@ -252,6 +254,8 @@ func init() {
252254
s.RequirementsLink = "https://codefresh.io/csdp-docs/docs/runtime/requirements/"
253255
s.GitTokensLink = "https://codefresh.io/csdp-docs/docs/reference/git-tokens/"
254256
s.DownloadCliLink = "https://codefresh.io/csdp-docs/docs/clients/csdp-cli/"
257+
s.CLIDownloadTemplate = "https://github.com/codefresh-io/cli-v2/releases/download/%s/cf-%s-%s.tar.gz"
258+
s.CLILatestVersionFileLink = "https://github.com/codefresh-io/cli-v2/releases/latest/download/version.txt"
255259
s.DefaultNamespace = "default"
256260
s.NetworkTesterName = "cf-network-tester"
257261
s.NetworkTesterGenerateName = "cf-network-tester-"

0 commit comments

Comments
 (0)