From bf6d17c6352fa33aa8577dd43d96fe090056608a Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sun, 29 Dec 2024 17:54:31 +0900 Subject: [PATCH 1/2] feat(update): support filtering updated packages using package tags --- pkg/cli/update/command.go | 15 +++++++++++++++ pkg/controller/update/package.go | 7 +++++++ pkg/controller/update/registry.go | 10 +++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/pkg/cli/update/command.go b/pkg/cli/update/command.go index 9b9035ebc..6f4cb51f0 100644 --- a/pkg/cli/update/command.go +++ b/pkg/cli/update/command.go @@ -82,6 +82,12 @@ e.g. You can also specify a version. $ aqua update gh@v2.30.0 + +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 { @@ -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", + }, }, } } diff --git a/pkg/controller/update/package.go b/pkg/controller/update/package.go index 51f1b74d1..25975bb7d 100644 --- a/pkg/controller/update/package.go +++ b/pkg/controller/update/package.go @@ -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) } diff --git a/pkg/controller/update/registry.go b/pkg/controller/update/registry.go index 901560bb7..074ab0fe8 100644 --- a/pkg/controller/update/registry.go +++ b/pkg/controller/update/registry.go @@ -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) @@ -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) From f774735fb9c44c45d88562f260bcce5f41958934 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sun, 29 Dec 2024 18:01:36 +0900 Subject: [PATCH 2/2] fix: suppress a lint error --- pkg/controller/update/package.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/update/package.go b/pkg/controller/update/package.go index 25975bb7d..ef06de7e4 100644 --- a/pkg/controller/update/package.go +++ b/pkg/controller/update/package.go @@ -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 {