Skip to content

Commit 75ca9a9

Browse files
feat(update): support filtering updated packages using package tags
1 parent 72badb2 commit 75ca9a9

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

pkg/cli/update/command.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ e.g.
8282
You can also specify a version.
8383
8484
$ aqua update [email protected]
85+
86+
You can also filter updated packages using package tags.
87+
88+
e.g.
89+
$ aqua up -t foo # Install only packages having a tag "foo"
90+
$ aqua up --exclude-tags foo # Install only packages not having a tag "foo"
8591
`
8692

8793
type command struct {
@@ -124,6 +130,15 @@ func New(r *util.Param) *cli.Command {
124130
Usage: "The maximum number of versions. Non-positive number refers to no limit.",
125131
Value: config.DefaultVerCnt,
126132
},
133+
&cli.StringFlag{
134+
Name: "tags",
135+
Aliases: []string{"t"},
136+
Usage: "filter installed packages with tags",
137+
},
138+
&cli.StringFlag{
139+
Name: "exclude-tags",
140+
Usage: "exclude installed packages with tags",
141+
},
127142
},
128143
}
129144
}

pkg/controller/update/package.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,18 @@ func (c *Controller) updatePackagesInFile(ctx context.Context, logE *logrus.Entr
6262
"package_version": pkg.Package.Version,
6363
"registry": pkg.Package.Registry,
6464
})
65+
if !aqua.FilterPackageByTag(pkg.Package, param.Tags, param.ExcludedTags) {
66+
logE.Debug("skip updating the package because package tags are unmatched")
67+
continue
68+
}
6569
if newVersion := c.getPackageNewVersion(ctx, logE, param, updatedPkgs, pkg); newVersion != "" {
6670
newVersions[fmt.Sprintf("%s,%s", pkg.Package.Registry, pkg.PackageInfo.GetName())] = newVersion
6771
newVersions[fmt.Sprintf("%s,%s", pkg.Package.Registry, pkg.Package.Name)] = newVersion
6872
}
6973
}
74+
if len(newVersions) == 0 {
75+
return nil
76+
}
7077
if err := c.updateFile(logE, cfgFilePath, newVersions); err != nil {
7178
return fmt.Errorf("update a package: %w", err)
7279
}

pkg/controller/update/registry.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (c *Controller) newRegistryVersion(ctx context.Context, logE *logrus.Entry,
1616
return "", nil
1717
}
1818

19-
logE.Debug("getting the latest release")
19+
logE.Debug("getting the latest release of a registry")
2020
release, _, err := c.gh.GetLatestRelease(ctx, rgst.RepoOwner, rgst.RepoName)
2121
if err != nil {
2222
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,
2828
func (c *Controller) updateRegistries(ctx context.Context, logE *logrus.Entry, cfgFilePath string, cfg *aqua.Config) error { //nolint:cyclop
2929
newVersions := map[string]string{}
3030
for _, rgst := range cfg.Registries {
31+
logE := logE.WithFields(logrus.Fields{
32+
"registry_name": rgst.Name,
33+
})
3134
if commitHashPattern.MatchString(rgst.Ref) {
32-
logE.WithFields(logrus.Fields{
33-
"registry_name": rgst.Name,
34-
"registry_version": rgst.Ref,
35-
}).Debug("skip a registry whose version is a commit hash")
35+
logE.Debug("skip a registry whose version is a commit hash")
3636
continue
3737
}
3838
newVersion, err := c.newRegistryVersion(ctx, logE, rgst)

pkg/runtime/runtime_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
func TestNew(t *testing.T) {
1010
t.Parallel()
1111
rt := runtime.New()
12-
if rt == nil {
12+
if rt == nil { //nolint:staticcheck
1313
t.Fatal("runtime must not be nil")
1414
}
15-
if rt.GOOS == "" {
15+
if rt.GOOS == "" { //nolint:staticcheck
1616
t.Fatal("rt.GOOS is empty")
1717
}
18-
if rt.GOARCH == "" {
18+
if rt.GOARCH == "" { //nolint:staticcheck
1919
t.Fatal("rt.GOARCH is empty")
2020
}
2121
}

0 commit comments

Comments
 (0)