From 1dda858bea3ec48c113709385180488192017824 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Tue, 15 Sep 2020 19:55:31 +0900 Subject: [PATCH 1/4] Fix import/imports not importing non-top-level jobs via shebang 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. --- examples/advanced/import/mycli | 3 +++ main_test.go | 13 ++++++++++++- pkg/app/load.go | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 examples/advanced/import/mycli diff --git a/examples/advanced/import/mycli b/examples/advanced/import/mycli new file mode 100644 index 0000000..271dc17 --- /dev/null +++ b/examples/advanced/import/mycli @@ -0,0 +1,3 @@ +#!/usr/bin/env variant + +import = "." diff --git a/main_test.go b/main_test.go index aea8fae..d396fec 100644 --- a/main_test.go +++ b/main_test.go @@ -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: "", @@ -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, diff --git a/pkg/app/load.go b/pkg/app/load.go index 1d368e4..6b50ffb 100644 --- a/pkg/app/load.go +++ b/pkg/app/load.go @@ -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 } @@ -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 } From 88d819428e2cef900aa810334c99350bf90869b1 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 23 Sep 2020 22:25:12 +0900 Subject: [PATCH 2/4] Fix failing test whose result was dependent on some container image repo contents --- examples/module/Dockerfile | 2 +- examples/module/default.variantmod | 2 +- examples/module/module_test.variant | 4 ++-- main_test.go | 20 ++++++++++++++------ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/examples/module/Dockerfile b/examples/module/Dockerfile index 7e7ae05..a272deb 100644 --- a/examples/module/Dockerfile +++ b/examples/module/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.10 -ARG HELM_VERSION=3.0.0 +ARG HELM_VERSION=3.2.0 ARG HELM_FILENAME="helm-${HELM_VERSION}-linux-amd64.tar.gz" ADD http://storage.googleapis.com/kubernetes-helm/${HELM_FILE_NAME} /tmp diff --git a/examples/module/default.variantmod b/examples/module/default.variantmod index f5f4c66..9c225a2 100644 --- a/examples/module/default.variantmod +++ b/examples/module/default.variantmod @@ -1,7 +1,7 @@ module "default" { dependency "github_release" "helm" { source = "helm/helm" - version = "> 1.0.0, < 3.0.1" + version = ">= 3.0.0, < 3.2.1" } file "Dockerfile" { diff --git a/examples/module/module_test.variant b/examples/module/module_test.variant index 633b154..db600c4 100644 --- a/examples/module/module_test.variant +++ b/examples/module/module_test.variant @@ -2,7 +2,7 @@ test "test" { case "ok" { out = trimspace(< Date: Wed, 23 Sep 2020 22:47:25 +0900 Subject: [PATCH 3/4] Fix dead-lock while waiting for command output while in test --- main_test.go | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/main_test.go b/main_test.go index 42e086a..8191367 100644 --- a/main_test.go +++ b/main_test.go @@ -10,6 +10,8 @@ import ( "strings" "testing" + "golang.org/x/sync/errgroup" + "github.com/google/go-cmp/cmp" ) @@ -257,17 +259,35 @@ func TestExamples(t *testing.T) { errWrite.Close() }() - outBuf := new(bytes.Buffer) - if _, err := outBuf.ReadFrom(outRead); err != nil { - t.Fatalf("unexpected error: %v", err) - } - out := outBuf.String() + var out, errOut string + + eg := &errgroup.Group{} + + eg.Go(func() error { + outBuf := new(bytes.Buffer) + if _, err := outBuf.ReadFrom(outRead); err != nil { + return fmt.Errorf("reading stdout: %w", err) + } + + out = outBuf.String() + + return nil + }) + + eg.Go(func() error { + errBuf := new(bytes.Buffer) + if _, err := errBuf.ReadFrom(errRead); err != nil { + return fmt.Errorf("reading stderr: %w", err) + } + + errOut = errBuf.String() + + return nil + }) - errBuf := new(bytes.Buffer) - if _, err := errBuf.ReadFrom(errRead); err != nil { + if err := eg.Wait(); err != nil { t.Fatalf("unexpected error: %v", err) } - errOut := errBuf.String() if tc.expectErr != "" { if err == nil { From 41b6a1b2139bda1de36b4725d60715c8143c121a Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 23 Sep 2020 22:55:11 +0900 Subject: [PATCH 4/4] Split build gh action job for faster completion --- .github/workflows/ci.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4423acb..0dd0851 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: Go on: [push] jobs: - build: + test: runs-on: ubuntu-latest strategy: matrix: @@ -16,8 +16,6 @@ jobs: version: ${{ matrix.go }} - name: Run go mod download run: go mod download - - name: Run golangci-lint - run: make lint - name: Install SSH key uses: shimataro/ssh-key-action@v2 with: @@ -29,3 +27,20 @@ jobs: sudo apt-get update -y sudo apt-get install ruby -y make test smoke + lint: + runs-on: ubuntu-latest + strategy: + matrix: + go: + - 1.13.4 + name: Go ${{ matrix.go }} build + steps: + - uses: actions/checkout@master + - name: Setup Go + uses: actions/setup-go@v1 + with: + version: ${{ matrix.go }} + - name: Run go mod download + run: go mod download + - name: Run golangci-lint + run: make lint