Skip to content

Commit

Permalink
Merge pull request #838 from imjasonh/package-replace
Browse files Browse the repository at this point in the history
apply substitutions to .environment.contents.packages
  • Loading branch information
imjasonh authored Nov 11, 2023
2 parents a857d9d + e71ab50 commit 3aa8b7c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,33 @@ func (cfg *Configuration) applySubstitutionsForRuntime() error {
var err error
cfg.Package.Dependencies.Runtime[i], err = util.MutateStringFromMap(nw, runtime)
if err != nil {
return fmt.Errorf("failed to apply replacement to provides %q: %w", runtime, err)
return fmt.Errorf("failed to apply replacement to runtime %q: %w", runtime, err)
}
}
for _, srt := range cfg.Subpackages {
for i, prov := range srt.Dependencies.Runtime {
var err error
srt.Dependencies.Runtime[i], err = util.MutateStringFromMap(nw, prov)
if err != nil {
return fmt.Errorf("failed to apply replacement to provides %q: %w", prov, err)
return fmt.Errorf("failed to apply replacement to runtime %q: %w", prov, err)
}
}
}
return nil
}

func (cfg *Configuration) applySubstitutionsForPackages() error {
nw := buildConfigMap(cfg)
for i, runtime := range cfg.Environment.Contents.Packages {
var err error
cfg.Environment.Contents.Packages[i], err = util.MutateStringFromMap(nw, runtime)
if err != nil {
return fmt.Errorf("failed to apply replacement to package %q: %w", runtime, err)
}
}
return nil
}

type Copyright struct {
// Optional: The license paths, typically '*'
Paths []string `json:"paths,omitempty" yaml:"paths,omitempty"`
Expand Down Expand Up @@ -814,6 +826,9 @@ func ParseConfiguration(configurationFilePath string, opts ...ConfigurationParsi
if err := cfg.applySubstitutionsForRuntime(); err != nil {
return nil, err
}
if err := cfg.applySubstitutionsForPackages(); err != nil {
return nil, err
}

// Propagate all child pipelines
cfg.propagatePipelines()
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ package:
- replacement-provides-bar=${{vars.bar}}
- replacement-provides=${{package.full-version}}
environment:
contents:
packages:
- dep~${{package.version}}
vars:
foo: FOO
bar: BAR
Expand Down Expand Up @@ -73,6 +78,10 @@ subpackages:
"FOO",
"other-package=0.0.1",
}, cfg.Subpackages[0].Dependencies.Runtime)

require.Equal(t, []string{
"dep~0.0.1",
}, cfg.Environment.Contents.Packages)
}

func Test_rangeSubstitutions(t *testing.T) {
Expand Down

0 comments on commit 3aa8b7c

Please sign in to comment.