Skip to content

Commit

Permalink
Fix import/imports not importing non-top-level jobs via shebang
Browse files Browse the repository at this point in the history
When run via shebang, `import = "."` from the entry variant file works, but nested `import = "path/to/subdir" from within variant files imported via the first `import = "."` was apparently not was ignoring `job`s.
  • Loading branch information
mumoshu committed Sep 18, 2020
1 parent 64a0e8b commit 1dda858
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/advanced/import/mycli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env variant

import = "."
13 changes: 12 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ func TestExamples(t *testing.T) {
args: []string{"variant", "test"},
wd: "./examples/advanced/import",
},
{
subject: "import/shebang",
variantName: "",
args: []string{"variant", "./examples/advanced/import/mycli", "foo", "bar", "HELLO"},
wd: "./examples/advanced/import",
expectOut: "HELLO\n",
},
{
subject: "import-multi",
variantName: "",
Expand Down Expand Up @@ -209,9 +216,13 @@ func TestExamples(t *testing.T) {
},
}

for i := range testcases {
for idx := range testcases {
i := idx
tc := testcases[i]

t.Run(fmt.Sprintf("%d: %s", i, tc.subject), func(t *testing.T) {
t.Logf("Running subtest: %d %s", i, tc.subject)

outRead, outWrite := io.Pipe()
env := Env{
Args: tc.args,
Expand Down
10 changes: 10 additions & 0 deletions pkg/app/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ func newApp(app *App, cc *HCL2Config, importDir func(string) (*App, error)) (*Ap
// their types MUST match.
merged := mergeJobs(importedJob, j)

merged.Name = ""

importedJob = *merged
}

Expand Down Expand Up @@ -322,6 +324,14 @@ func newApp(app *App, cc *HCL2Config, importDir func(string) (*App, error)) (*Ap

app.JobByName = jobByName

var newJobs []JobSpec

for _, j := range app.JobByName {
newJobs = append(newJobs, j)
}

app.Config.Jobs = newJobs

return app, nil
}

Expand Down

0 comments on commit 1dda858

Please sign in to comment.