Skip to content

Commit

Permalink
fix(update): fix a bug go_version_file and version_expr cause errors (#…
Browse files Browse the repository at this point in the history
…3436)

* fix(update): fix a bug go_version_file and version_expr cause errors

* test: fix a test

* ci: update a test
  • Loading branch information
suzuki-shunsuke authored Jan 7, 2025
1 parent 253b6f8 commit 13a9caf
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/wc-integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ jobs:
git checkout -- .
working-directory: tests/update

- name: update (go_version_file)
run: |
aqua up
git diff .
git checkout -- .
working-directory: tests/update2

- name: update (version_expr)
run: |
aqua up
git diff .
git checkout -- .
working-directory: tests/update3

- run: aqua update-checksum -a

- run: terraform --help
Expand Down
5 changes: 4 additions & 1 deletion pkg/config-reader/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ func (r *ConfigReader) ReadToUpdate(configFilePath string, cfg *aqua.Config) (ma
return cfgs, nil
}

func (r *ConfigReader) readImportsToUpdate(configFilePath string, cfg *aqua.Config) (map[string]*aqua.Config, error) {
func (r *ConfigReader) readImportsToUpdate(configFilePath string, cfg *aqua.Config) (map[string]*aqua.Config, error) { //nolint:cyclop
cfgs := map[string]*aqua.Config{}
pkgs := []*aqua.Package{}
for _, pkg := range cfg.Packages {
if pkg == nil {
continue
}
if pkg.VersionExpr != "" || pkg.GoVersionFile != "" || pkg.Pin {
continue
}
if pkg.Import == "" {
pkgs = append(pkgs, pkg)
continue
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/aqua/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Package struct {
VersionExprPrefix string `json:"version_expr_prefix,omitempty" yaml:"version_expr_prefix,omitempty"`
Vars map[string]any `json:"vars,omitempty" yaml:",omitempty"`
CommandAliases []*CommandAlias `json:"command_aliases,omitempty" yaml:"command_aliases,omitempty"`
Pin bool `json:"-" yaml:"-"`
}

type CommandAlias struct {
Expand Down Expand Up @@ -55,6 +56,7 @@ func (p *Package) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal(&a); err != nil {
return err
}
pin := a.Version != ""
name, version := parseNameWithVersion(a.Name)
if name != "" {
a.Name = name
Expand All @@ -66,7 +68,7 @@ func (p *Package) UnmarshalYAML(unmarshal func(interface{}) error) error {
if p.Registry == "" {
p.Registry = RegistryTypeStandard
}

p.Pin = pin
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/config/aqua/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ packages:
Name: "cmdx",
Registry: "standard",
Version: "v1.6.0",
Pin: true,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions tests/update/.terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.10.2
5 changes: 5 additions & 0 deletions tests/update/aqua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ packages:
- name: suzuki-shunsuke/[email protected]
- import: ci-info.yaml
- import: imports/*.yaml
- name: golang/go
go_version_file: go.mod
- name: hashicorp/terraform
version_expr: readFile(".terraform-version")
version_expr_prefix: v
3 changes: 3 additions & 0 deletions tests/update/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module foo

go 1.23.4
6 changes: 6 additions & 0 deletions tests/update2/aqua.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
registries:
- type: standard
ref: v4.293.0 # renovate: depName=aquaproj/aqua-registry
packages:
- name: golang/go
go_version_file: go.mod
3 changes: 3 additions & 0 deletions tests/update2/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module foo

go 1.23.4
1 change: 1 addition & 0 deletions tests/update3/.terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.10.2
7 changes: 7 additions & 0 deletions tests/update3/aqua.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
registries:
- type: standard
ref: v4.293.0 # renovate: depName=aquaproj/aqua-registry
packages:
- name: hashicorp/terraform
version_expr: readFile(".terraform-version")
version_expr_prefix: v

0 comments on commit 13a9caf

Please sign in to comment.