Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add update command #2329

Merged
merged 44 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
08d8ef3
feat: add update command
suzuki-shunsuke Oct 9, 2023
a922c77
fix: set github client
suzuki-shunsuke Oct 10, 2023
d88341b
fix: output log of registry update
suzuki-shunsuke Oct 10, 2023
2af9bcd
refactor: create VersionGetter
suzuki-shunsuke Oct 12, 2023
efe9d45
refactor: add versiongetter
suzuki-shunsuke Oct 13, 2023
f6314a5
feat: update packages
suzuki-shunsuke Oct 14, 2023
0369da6
feat: support selecting packages
suzuki-shunsuke Oct 14, 2023
4f55c36
feat: support only-package and only-registry
suzuki-shunsuke Oct 14, 2023
f1fccd1
feat: support selecting versions
suzuki-shunsuke Oct 14, 2023
0992e44
refactor: remove comment out
suzuki-shunsuke Oct 14, 2023
c6740d5
refactor: remove unused codes
suzuki-shunsuke Oct 14, 2023
80bafe4
refactor: remove unused interface
suzuki-shunsuke Oct 14, 2023
3e861ac
refactor: remove unused function
suzuki-shunsuke Oct 14, 2023
7b6ff6f
refactor: remove unused function
suzuki-shunsuke Oct 14, 2023
bccbfe6
refactor: remove unused type
suzuki-shunsuke Oct 14, 2023
58c8b5c
feat(update): update the help message
suzuki-shunsuke Oct 14, 2023
e0003c2
feat: skip updating commit hashes
suzuki-shunsuke Oct 14, 2023
e002af7
refactor(update): refactoring
suzuki-shunsuke Oct 14, 2023
cdd2114
feat(update): support finding updated packages with command names
suzuki-shunsuke Oct 14, 2023
b98f2f7
feat(update): update the help message
suzuki-shunsuke Oct 14, 2023
aa91214
feat(update): add the command alias "up"
suzuki-shunsuke Oct 14, 2023
f263856
feat(update): update the help message
suzuki-shunsuke Oct 14, 2023
ccdab87
ci(update): add tests
suzuki-shunsuke Oct 14, 2023
6a18c71
fix(update): update imported packages
suzuki-shunsuke Oct 14, 2023
45ea671
test(update): fix test
suzuki-shunsuke Oct 14, 2023
5733d92
test(update): add tests
suzuki-shunsuke Oct 14, 2023
d04577b
test(update): add tests
suzuki-shunsuke Oct 14, 2023
71dad0a
test(update): add tests
suzuki-shunsuke Oct 15, 2023
bf33757
test(update): ignore lint error
suzuki-shunsuke Oct 15, 2023
8b81fe8
fix(update): read import recursively
suzuki-shunsuke Oct 15, 2023
00576b9
fix(update): check command line args first
suzuki-shunsuke Oct 15, 2023
2abd9c3
refactor(update): rename a method
suzuki-shunsuke Oct 15, 2023
a1c81b4
refactor(update): refactor FuzzyGetter
suzuki-shunsuke Oct 15, 2023
1c8772e
fix(versiongetter): remove the duplicated tags and releases
suzuki-shunsuke Oct 15, 2023
06a2913
fix(update): add the mark `(*)` to the current version
suzuki-shunsuke Oct 15, 2023
70ff5af
fix(update): check command line arguments
suzuki-shunsuke Oct 15, 2023
0a0bf26
test(update): add tests
suzuki-shunsuke Oct 15, 2023
115aff9
test(update): add tests
suzuki-shunsuke Oct 15, 2023
4615610
test(update): add tests
suzuki-shunsuke Oct 15, 2023
b649063
test(update): add tests
suzuki-shunsuke Oct 15, 2023
2d541c4
test(versiongetter): add tests
suzuki-shunsuke Oct 16, 2023
04c9057
fix(update): update packages before registries
suzuki-shunsuke Oct 16, 2023
905c1fe
test(versiongetter): add tests
suzuki-shunsuke Oct 16, 2023
e759a2b
fix: ignore a lint error
suzuki-shunsuke Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/wc-integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,34 @@ jobs:
run: aqua cp --exclude-tags test -t foo
working-directory: tests/tag

- name: update only registrires
run: |
aqua update -r
git diff .
git checkout -- .
working-directory: tests/update

- name: update only packages
run: |
aqua up -p
git diff .
git checkout -- .
working-directory: tests/update

- name: update all registries and packages
run: |
aqua update
git diff .
git checkout -- .
working-directory: tests/update

- name: update only specific command
run: |
aqua update tfcmt ci-info
git diff .
git checkout -- .
working-directory: tests/update

- run: aqua update-checksum -a

- name: Test rm
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func (r *Runner) setParam(c *cli.Context, commandName string, param *config.Para
param.GlobalConfigFilePaths = finder.ParseGlobalConfigFilePaths(os.Getenv("AQUA_GLOBAL_CONFIG"))
param.Deep = c.Bool("deep")
param.Pin = c.Bool("pin")
param.OnlyPackage = c.Bool("only-package")
param.OnlyRegistry = c.Bool("only-registry")
wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("get the current directory: %w", err)
Expand Down Expand Up @@ -172,6 +174,7 @@ func (r *Runner) Run(ctx context.Context, args ...string) error {
r.newRootDirCommand(),
r.newUpdateChecksumCommand(),
r.newRemoveCommand(),
r.newUpdateCommand(),
},
}

Expand Down
124 changes: 124 additions & 0 deletions pkg/cli/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package cli

import (
"fmt"
"net/http"

"github.com/aquaproj/aqua/v2/pkg/config"
"github.com/aquaproj/aqua/v2/pkg/controller"
"github.com/urfave/cli/v2"
)

func (r *Runner) newUpdateCommand() *cli.Command {
return &cli.Command{
Name: "update",
Aliases: []string{"up"},
Usage: "Update registries and packages",
Description: updateDescription,
Action: r.updateAction,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "i",
Usage: `Select packages with fuzzy finder`,
},
&cli.BoolFlag{
Name: "select-version",
Aliases: []string{"s"},
Usage: `Select the version with fuzzy finder`,
},
&cli.BoolFlag{
Name: "only-registry",
Aliases: []string{"r"},
Usage: `Update only registries`,
},
&cli.BoolFlag{
Name: "only-package",
Aliases: []string{"p"},
Usage: `Update only packages`,
},
},
}
}

const updateDescription = `Update registries and packages.
If no argument is passed, all registries and packages are updated to the latest.

# Update all packages and registries to the latest versions
$ aqua update

This command has an alias "up"

$ aqua up

This command gets the latest version from GitHub Releases, GitHub Tags, and crates.io and updates aqua.yaml.
This command doesn't update commit hashes.
This command doesn't install packages.
This command updates only a nearest aqua.yaml from the current directory.
If this command finds a aqua.yaml, it ignores other aqua.yaml including global configuration files ($AQUA_GLOBAL_CONFIG).

So if you want to update other files, please change the current directory or specify the configuration file path with the option '-c'.

$ aqua -c foo/aqua.yaml update

If you want to update only registries, please use the --only-registry [-r] option.

# Update only registries
$ aqua update -r

If you want to update only packages, please use the --only-package [-p] option.

# Update only packages
$ aqua update -p

If you want to update only specific packages, please use the -i option.
You can select packages with the fuzzy finder.
If -i option is used, registries aren't updated.

# Select updated packages with fuzzy finder
$ aqua update -i

If you want to select versions, please use the --select-version [-s] option.
You can select versions with the fuzzy finder. You can not only update but also downgrade packages.

# Select updated packages and versions with fuzzy finder
$ aqua update -i -s

This command doesn't update packages if the field 'version' is used.

packages:
- name: cli/[email protected] # Update
- name: gohugoio/hugo
version: v0.118.0 # Doesn't update

So if you don't want to update specific packages, the field 'version' is useful.

You can specify packages with command names. aqua finds packages that have these commands and updates them.

$ aqua update <command name> [<command name> ...]

e.g.

# Update cli/cli
$ aqua update gh
`

func (r *Runner) updateAction(c *cli.Context) error {
tracer, err := startTrace(c.String("trace"))
if err != nil {
return err
}
defer tracer.Stop()

cpuProfiler, err := startCPUProfile(c.String("cpu-profile"))
if err != nil {
return err
}
defer cpuProfiler.Stop()

param := &config.Param{}
if err := r.setParam(c, "update", param); err != nil {
return fmt.Errorf("parse the command line arguments: %w", err)
}
ctrl := controller.InitializeUpdateCommandController(c.Context, param, http.DefaultClient, r.Runtime)
return ctrl.Update(c.Context, r.LogE, param) //nolint:wrapcheck
}
5 changes: 4 additions & 1 deletion pkg/config-reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ func (r *ConfigReaderImpl) readImports(configFilePath string, cfg *aqua.Config)
if err := r.Read(filePath, subCfg); err != nil {
return err
}
pkgs = append(pkgs, subCfg.Packages...)
for _, pkg := range subCfg.Packages {
pkg.FilePath = filePath
pkgs = append(pkgs, pkg)
}
}
}
cfg.Packages = pkgs
Expand Down
1 change: 1 addition & 0 deletions pkg/config-reader/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ packages:
Name: "aquaproj/aqua-installer",
Registry: "standard",
Version: "v1.0.0",
FilePath: "/home/workspace/foo/aqua-installer.yaml",
},
},
},
Expand Down
79 changes: 79 additions & 0 deletions pkg/config-reader/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package reader

import (
"fmt"
"path/filepath"
"sort"
"strings"

"github.com/aquaproj/aqua/v2/pkg/config/aqua"
"github.com/aquaproj/aqua/v2/pkg/osfile"
"github.com/spf13/afero"
"gopkg.in/yaml.v2"
)

func (r *ConfigReaderImpl) ReadToUpdate(configFilePath string, cfg *aqua.Config) (map[string]*aqua.Config, error) {
file, err := r.fs.Open(configFilePath)
if err != nil {
return nil, err //nolint:wrapcheck
}
defer file.Close()
if err := yaml.NewDecoder(file).Decode(cfg); err != nil {
return nil, fmt.Errorf("parse a configuration file as YAML %s: %w", configFilePath, err)
}
var configFileDir string
for _, rgst := range cfg.Registries {
rgst := rgst
if rgst.Type == "local" {
if strings.HasPrefix(rgst.Path, homePrefix) {
if r.homeDir == "" {
return nil, errHomeDirEmpty
}
rgst.Path = filepath.Join(r.homeDir, rgst.Path[6:]) // 6: "$HOME/"
}
if configFileDir == "" {
configFileDir = filepath.Dir(configFilePath)
}
rgst.Path = osfile.Abs(configFileDir, rgst.Path)
}
}
cfgs, err := r.readImportsToUpdate(configFilePath, cfg)
if err != nil {
return nil, fmt.Errorf("read imports (%s): %w", configFilePath, err)
}
return cfgs, nil
}

func (r *ConfigReaderImpl) readImportsToUpdate(configFilePath string, cfg *aqua.Config) (map[string]*aqua.Config, error) {
cfgs := map[string]*aqua.Config{}
pkgs := []*aqua.Package{}
for _, pkg := range cfg.Packages {
if pkg == nil {
continue
}
if pkg.Import == "" {
pkgs = append(pkgs, pkg)
continue
}
p := filepath.Join(filepath.Dir(configFilePath), pkg.Import)
filePaths, err := afero.Glob(r.fs, p)
if err != nil {
return nil, fmt.Errorf("read files with glob pattern (%s): %w", p, err)
}
sort.Strings(filePaths)
for _, filePath := range filePaths {
subCfg := &aqua.Config{}
subCfgs, err := r.ReadToUpdate(filePath, subCfg)
if err != nil {
return nil, err
}
subCfg.Registries = cfg.Registries
cfgs[filePath] = subCfg
for k, subCfg := range subCfgs {
cfgs[k] = subCfg
}
}
}
cfg.Packages = pkgs
return cfgs, nil
}
Loading