Skip to content

Commit

Permalink
Merge pull request #1383 from jdolitsky/fix-range-subs
Browse files Browse the repository at this point in the history
Apply variables to workdir within a range
  • Loading branch information
jdolitsky committed Jul 16, 2024
2 parents 8a118eb + 36fdfe9 commit 751494a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
41 changes: 23 additions & 18 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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?
})
}
Expand All @@ -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?
})
}
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 @@ -169,6 +169,9 @@ data:
a: 10
b: 20
vars:
buildLocation: "/home/build/foo"
subpackages:
- range: I-am-a-range
name: ${{range.key}}
Expand All @@ -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)
}
Expand All @@ -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) {
Expand Down

0 comments on commit 751494a

Please sign in to comment.