From feb5866c9c4ec865a7edae5cac1f533057caeae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraci=20Paix=C3=A3o=20Kr=C3=B6hling?= Date: Wed, 14 Oct 2020 14:15:12 +0200 Subject: [PATCH] Setup CI (#7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juraci Paixão Kröhling --- .github/workflows/go.yaml | 32 ++++++++++++++++++++++++++++++++ cmd/root.go | 8 ++++++-- internal/builder/main.go | 4 ++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/go.yaml diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml new file mode 100644 index 0000000..670ea34 --- /dev/null +++ b/.github/workflows/go.yaml @@ -0,0 +1,32 @@ +name: Go + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.14 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Test + run: go test -v ./... + + - name: Lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.29 + only-new-issues: true + diff --git a/cmd/root.go b/cmd/root.go index c183e2b..0844f28 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -61,9 +61,13 @@ func Execute() { cmd.Flags().StringVar(&cfg.Distribution.Module, "module", "github.com/jpkroehling/opentelemetry-collector-builder", "The Go module for the new distribution") // tie Viper to flags - viper.BindPFlags(cmd.Flags()) + if err := viper.BindPFlags(cmd.Flags()); err != nil { + cfg.Logger.Error(err, "failed to bind flags: %w", err) + } - cmd.Execute() + if err := cmd.Execute(); err != nil { + cfg.Logger.Error(err, "failed to run: %w", err) + } } func initConfig() { diff --git a/internal/builder/main.go b/internal/builder/main.go index 401454c..abfa471 100644 --- a/internal/builder/main.go +++ b/internal/builder/main.go @@ -107,6 +107,10 @@ func Compile(cfg Config) error { func processAndWrite(cfg Config, tmpl string, outFile string, tmplParams interface{}) error { t, err := template.New("template").Parse(tmpl) + if err != nil { + return err + } + out, err := os.Create(filepath.Join(cfg.Distribution.OutputPath, outFile)) if err != nil { return err