Skip to content

Commit

Permalink
Merge pull request #1343 from imjasonh/var-transform-subpkg
Browse files Browse the repository at this point in the history
support var-transforms in subpackage names
  • Loading branch information
imjasonh committed Jul 3, 2024
2 parents d58b32f + 8430195 commit d95b4d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
13 changes: 12 additions & 1 deletion examples/vars.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: hello
version: 2.12
version: 2.12.4
epoch: 0
description: "an example of how conditionals influence build behavior"
copyright:
Expand All @@ -20,6 +20,12 @@ vars:
bar: "World"
buildLocation: "/home/build/foo"

var-transforms:
- from: ${{package.version}}
match: ^(\d+\.\d+)\.\d+$
replace: "$1"
to: short-package-version

pipeline:
# Variable substitution works for `with`, `working-directory` and
# `runs` statements.
Expand All @@ -30,3 +36,8 @@ pipeline:
- working-directory: ${{targets.destdir}}
runs: |
echo "${{vars.foo}} ${{vars.bar}}"
subpackages:
- name: subpackage-${{vars.short-package-version}}
pipeline:
- runs: echo "subpackage-${{vars.short-package-version}}"
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,10 @@ func ParseConfiguration(ctx context.Context, configurationFilePath string, opts

// Mutate config properties with substitutions.
configMap := buildConfigMap(&cfg)
if err := cfg.PerformVarSubstitutions(configMap); err != nil {
return nil, fmt.Errorf("applying variable substitutions: %w", err)
}

replacer := replacerFromMap(configMap)

cfg.Package.Name = replacer.Replace(cfg.Package.Name)
Expand Down
10 changes: 9 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ vars:
foo: FOO
bar: BAR
var-transforms:
- from: ${{package.version}}
match: ^(\d+\.\d+)\.\d+$
replace: "$1"
to: short-package-version
subpackages:
- name: subpackage
- name: subpackage-${{vars.short-package-version}}
dependencies:
runtime:
- ${{package.name}}-config-${{package.version}}
Expand Down Expand Up @@ -101,6 +107,8 @@ test:
require.Equal(t, []string{
"replacement-provides-config",
}, cfg.Test.Environment.Contents.Packages)

require.Equal(t, cfg.Subpackages[0].Name, "subpackage-0.0")
}

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

0 comments on commit d95b4d0

Please sign in to comment.