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(update): support filtering updated packages using package tags #3399

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading