From 36fdfe9288650d47a0c534ddf416dbf43bc00ee5 Mon Sep 17 00:00:00 2001 From: Josh Dolitsky Date: Mon, 15 Jul 2024 15:36:07 -0500 Subject: [PATCH] Apply variables to workdir within a range Signed-off-by: Josh Dolitsky --- pkg/config/config.go | 41 ++++++++++++++++++++++----------------- pkg/config/config_test.go | 9 +++++++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index be7a406c5..87baec722 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -784,12 +784,15 @@ func ParseConfiguration(ctx context.Context, configurationFilePath string, opts } sort.Strings(keys) + configMap := buildConfigMap(&cfg) + if err := cfg.PerformVarSubstitutions(configMap); err != nil { + return nil, fmt.Errorf("applying variable substitutions: %w", err) + } for _, k := range keys { v := items[k] - replacer := replacerFromMap(map[string]string{ - "${{range.key}}": k, - "${{range.value}}": v, - }) + configMap["${{range.key}}"] = k + configMap["${{range.value}}"] = v + replacer := replacerFromMap(configMap) thingToAdd := Subpackage{ Name: replacer.Replace(sp.Name), @@ -835,13 +838,14 @@ func ParseConfiguration(ctx context.Context, configurationFilePath string, opts } thingToAdd.Pipeline = append(thingToAdd.Pipeline, Pipeline{ - Name: p.Name, - Uses: p.Uses, - With: replacedWith, - Inputs: p.Inputs, - Needs: p.Needs, - Label: p.Label, - Runs: replacer.Replace(p.Runs), + Name: p.Name, + Uses: p.Uses, + With: replacedWith, + Inputs: p.Inputs, + Needs: p.Needs, + Label: p.Label, + Runs: replacer.Replace(p.Runs), + WorkDir: replacer.Replace(p.WorkDir), // TODO: p.Pipeline? }) } @@ -860,13 +864,14 @@ func ParseConfiguration(ctx context.Context, configurationFilePath string, opts } thingToAdd.Test.Pipeline = append(thingToAdd.Test.Pipeline, Pipeline{ - Name: p.Name, - Uses: p.Uses, - With: replacedWith, - Inputs: p.Inputs, - Needs: p.Needs, - Label: p.Label, - Runs: replacer.Replace(p.Runs), + Name: p.Name, + Uses: p.Uses, + With: replacedWith, + Inputs: p.Inputs, + Needs: p.Needs, + Label: p.Label, + Runs: replacer.Replace(p.Runs), + WorkDir: replacer.Replace(p.WorkDir), // TODO: p.Pipeline? }) } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 4510382b0..5ef24c57b 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -169,6 +169,9 @@ data: a: 10 b: 20 +vars: + buildLocation: "/home/build/foo" + subpackages: - range: I-am-a-range name: ${{range.key}} @@ -178,6 +181,10 @@ subpackages: replaces-priority: ${{range.value}} runtime: - wow-some-kinda-dynamically-linked-library-i-guess=1.0 + pipeline: + - working-directory: ${{vars.buildLocation}}/subdir/${{range.key}}/${{range.value}} + runs: | + echo "$PWD" `), 0644); err != nil { t.Fatal(err) } @@ -187,6 +194,8 @@ subpackages: } require.Equal(t, cfg.Subpackages[0].Dependencies.ProviderPriority, "10") require.Equal(t, cfg.Subpackages[0].Dependencies.ReplacesPriority, "10") + require.Equal(t, cfg.Subpackages[0].Pipeline[0].WorkDir, "/home/build/foo/subdir/a/10") + require.Equal(t, cfg.Subpackages[1].Pipeline[0].WorkDir, "/home/build/foo/subdir/b/20") } func Test_propagatePipelines(t *testing.T) {