Skip to content
Open
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
14 changes: 14 additions & 0 deletions pkg/leeway/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,20 @@ func (p *Package) resolveBuiltinVariables() error {
}
}

// Resolve builtin variables in PackageInternal (prep, env, etc.)
pifc, err := yaml.Marshal(p.PackageInternal)
if err != nil {
return err
}
pifc = replaceBuildArguments(pifc, builtinArgs)
var pi PackageInternal
err = yaml.Unmarshal(pifc, &pi)
if err != nil {
return err
}
p.PackageInternal = pi

// Resolve builtin variables in Config
type configOnlyHelper struct {
Config PackageConfig `yaml:"config"`
}
Expand Down
51 changes: 51 additions & 0 deletions pkg/leeway/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,57 @@ func TestResolveBuiltinVariables(t *testing.T) {
}
}

func TestResolveBuiltinVariablesInPackageInternal(t *testing.T) {
tests := []struct {
Name string
Prep [][]string
Env []string
ExpectedPrep [][]string
ExpectedEnv []string
}{
{
Name: "prep with __pkg_version",
Prep: [][]string{{"/bin/bash", "prepare.sh", "${__pkg_version}"}},
ExpectedPrep: [][]string{{"/bin/bash", "prepare.sh", "this-version"}},
},
{
Name: "env with __pkg_version",
Env: []string{"VERSION=${__pkg_version}"},
ExpectedEnv: []string{"VERSION=this-version"},
},
{
Name: "prep and env with __pkg_version",
Prep: [][]string{{"echo", "${__pkg_version}"}},
Env: []string{"BUILD_VERSION=${__pkg_version}"},
ExpectedPrep: [][]string{{"echo", "this-version"}},
ExpectedEnv: []string{"BUILD_VERSION=this-version"},
},
}

for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
pkg := NewTestPackage("pkg")
pkg.Type = GenericPackage
pkg.Config = GenericPkgConfig{Commands: [][]string{{"echo", "hello"}}}
pkg.PreparationCommands = test.Prep
pkg.Environment = test.Env

err := pkg.resolveBuiltinVariables()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if test.ExpectedPrep != nil && !reflect.DeepEqual(pkg.PreparationCommands, test.ExpectedPrep) {
t.Errorf("PreparationCommands mismatch. expected: %v, actual: %v", test.ExpectedPrep, pkg.PreparationCommands)
}

if test.ExpectedEnv != nil && !reflect.DeepEqual(pkg.Environment, test.ExpectedEnv) {
t.Errorf("Environment mismatch. expected: %v, actual: %v", test.ExpectedEnv, pkg.Environment)
}
})
}
}

func TestFindCycles(t *testing.T) {
tests := []struct {
Name string
Expand Down
Loading