Skip to content

Commit

Permalink
feat(update): support filtering updated packages using package tags (#…
Browse files Browse the repository at this point in the history
…3399)

* feat(update): support filtering updated packages using package tags

* fix: suppress a lint error
  • Loading branch information
suzuki-shunsuke authored Dec 31, 2024
1 parent ec2ac9c commit 2eb8946
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
15 changes: 15 additions & 0 deletions pkg/cli/update/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ e.g.
You can also specify a version.
$ aqua update [email protected]
You can also filter updated packages using package tags.
e.g.
$ aqua up -t foo # Install only packages having a tag "foo"
$ aqua up --exclude-tags foo # Install only packages not having a tag "foo"
`

type command struct {
Expand Down Expand Up @@ -124,6 +130,15 @@ func New(r *util.Param) *cli.Command {
Usage: "The maximum number of versions. Non-positive number refers to no limit.",
Value: config.DefaultVerCnt,
},
&cli.StringFlag{
Name: "tags",
Aliases: []string{"t"},
Usage: "filter installed packages with tags",
},
&cli.StringFlag{
Name: "exclude-tags",
Usage: "exclude installed packages with tags",
},
},
}
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/controller/update/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Controller) updatePackages(ctx context.Context, logE *logrus.Entry, par
return nil
}

func (c *Controller) updatePackagesInFile(ctx context.Context, logE *logrus.Entry, param *config.Param, cfgFilePath string, cfg *aqua.Config, rgstCfgs map[string]*registry.Config, updatedPkgs map[string]struct{}, newVersions map[string]string) error {
func (c *Controller) updatePackagesInFile(ctx context.Context, logE *logrus.Entry, param *config.Param, cfgFilePath string, cfg *aqua.Config, rgstCfgs map[string]*registry.Config, updatedPkgs map[string]struct{}, newVersions map[string]string) error { //nolint:cyclop
pkgs, failed := config.ListPackages(logE, cfg, c.runtime, rgstCfgs)
if len(pkgs) == 0 {
if failed {
Expand All @@ -62,11 +62,18 @@ func (c *Controller) updatePackagesInFile(ctx context.Context, logE *logrus.Entr
"package_version": pkg.Package.Version,
"registry": pkg.Package.Registry,
})
if !aqua.FilterPackageByTag(pkg.Package, param.Tags, param.ExcludedTags) {
logE.Debug("skip updating the package because package tags are unmatched")
continue
}
if newVersion := c.getPackageNewVersion(ctx, logE, param, updatedPkgs, pkg); newVersion != "" {
newVersions[fmt.Sprintf("%s,%s", pkg.Package.Registry, pkg.PackageInfo.GetName())] = newVersion
newVersions[fmt.Sprintf("%s,%s", pkg.Package.Registry, pkg.Package.Name)] = newVersion
}
}
if len(newVersions) == 0 {
return nil
}
if err := c.updateFile(logE, cfgFilePath, newVersions); err != nil {
return fmt.Errorf("update a package: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/update/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (c *Controller) newRegistryVersion(ctx context.Context, logE *logrus.Entry,
return "", nil
}

logE.Debug("getting the latest release")
logE.Debug("getting the latest release of a registry")
release, _, err := c.gh.GetLatestRelease(ctx, rgst.RepoOwner, rgst.RepoName)
if err != nil {
return "", fmt.Errorf("get the latest release by GitHub API: %w", err)
Expand All @@ -28,11 +28,11 @@ func (c *Controller) newRegistryVersion(ctx context.Context, logE *logrus.Entry,
func (c *Controller) updateRegistries(ctx context.Context, logE *logrus.Entry, cfgFilePath string, cfg *aqua.Config) error { //nolint:cyclop
newVersions := map[string]string{}
for _, rgst := range cfg.Registries {
logE := logE.WithFields(logrus.Fields{
"registry_name": rgst.Name,
})
if commitHashPattern.MatchString(rgst.Ref) {
logE.WithFields(logrus.Fields{
"registry_name": rgst.Name,
"registry_version": rgst.Ref,
}).Debug("skip a registry whose version is a commit hash")
logE.Debug("skip a registry whose version is a commit hash")
continue
}
newVersion, err := c.newRegistryVersion(ctx, logE, rgst)
Expand Down

0 comments on commit 2eb8946

Please sign in to comment.