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

Fix a bug where substitutions were not done for runtime. #754

Merged
merged 1 commit into from
Oct 16, 2023
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
24 changes: 24 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ func (cfg *Configuration) applySubstitutionsForProvides() error {
return nil
}

func (cfg *Configuration) applySubstitutionsForRuntime() error {
nw := buildConfigMap(cfg)
for i, runtime := range cfg.Package.Dependencies.Runtime {
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)
}
}
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 nil
}

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

// Propagate all child pipelines
cfg.propagatePipelines()
Expand Down
16 changes: 16 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package:
epoch: 7
description: example using a replacement in provides
dependencies:
runtime:
- ${{package.name}}-config
- ${{vars.bar}}
provides:
- replacement-provides-version=${{package.version}}
- replacement-provides-foo=${{vars.foo}}
Expand All @@ -30,6 +33,9 @@ vars:
subpackages:
- name: subpackage
dependencies:
runtime:
- ${{package.name}}-config-${{package.version}}
- ${{vars.foo}}
provides:
- subpackage-version=${{package.version}}
- subpackage-foo=${{vars.foo}}
Expand All @@ -53,6 +59,16 @@ subpackages:
"subpackage-foo=FOO",
"subpackage-bar=BAR",
}, cfg.Subpackages[0].Dependencies.Provides)

require.Equal(t, []string{
"replacement-provides-config",
"BAR",
}, cfg.Package.Dependencies.Runtime)

require.Equal(t, []string{
"replacement-provides-config-0.0.1",
"FOO",
}, cfg.Subpackages[0].Dependencies.Runtime)
}

func Test_propagatePipelines(t *testing.T) {
Expand Down
Loading