From f7819208822712baa0a5236f9606f0508877ad1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ho=C3=9F?= Date: Sun, 11 Sep 2022 15:53:40 +0200 Subject: [PATCH 1/3] add golangci-lint --- .github/workflows/verify.yml | 5 +++++ .golangci.yml | 3 +++ dev/Containerfile | 1 + internal/provider/data_source_git_log.go | 7 +++++++ internal/provider/resource_git_commit_test.go | 4 ++-- internal/provider/resource_git_init_test.go | 2 +- project.mk | 8 ++++++++ 7 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index a36c194..7552151 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -39,6 +39,11 @@ jobs: with: go-version-file: go.mod cache: true + - id: lint + name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest - id: generate_docs name: Generate Documentation run: go generate diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..cc2de50 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,3 @@ +run: + build-tags: + - testing diff --git a/dev/Containerfile b/dev/Containerfile index cc8b3c5..5bc2fc1 100644 --- a/dev/Containerfile +++ b/dev/Containerfile @@ -5,3 +5,4 @@ FROM metio/devcontainers-go:latest RUN go install github.com/hashicorp/terraform@main RUN go install gotest.tools/gotestsum@latest +RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@master diff --git a/internal/provider/data_source_git_log.go b/internal/provider/data_source_git_log.go index 910c4f4..0f59f4f 100644 --- a/internal/provider/data_source_git_log.go +++ b/internal/provider/data_source_git_log.go @@ -203,6 +203,13 @@ func (r *dataSourceGitLog) Read(ctx context.Context, req datasource.ReadRequest, } return nil }) + if err != nil { + resp.Diagnostics.AddError( + "Cannot read commits", + "Could not read commits because of: "+err.Error(), + ) + return + } if !inputs.Skip.IsNull() && !inputs.Skip.IsUnknown() { if int64(len(hashes)) >= inputs.Skip.Value { hashes = hashes[inputs.Skip.Value:] diff --git a/internal/provider/resource_git_commit_test.go b/internal/provider/resource_git_commit_test.go index 9b5823e..4bd9d3f 100644 --- a/internal/provider/resource_git_commit_test.go +++ b/internal/provider/resource_git_commit_test.go @@ -112,11 +112,11 @@ func TestResourceGitCommit_Directory_Missing(t *testing.T) { ProtoV6ProviderFactories: testutils.ProviderFactories(), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(` + Config: ` resource "git_commit" "test" { message = "committed with terraform" } - `), + `, ExpectError: regexp.MustCompile(`Missing required argument`), }, }, diff --git a/internal/provider/resource_git_init_test.go b/internal/provider/resource_git_init_test.go index 1c6bd6c..6894386 100644 --- a/internal/provider/resource_git_init_test.go +++ b/internal/provider/resource_git_init_test.go @@ -110,7 +110,7 @@ func TestResourceGitInit_Import(t *testing.T) { { ResourceName: "git_init.test", ImportState: true, - ImportStateId: fmt.Sprintf("%s", directory), + ImportStateId: directory, ImportStateVerify: true, }, }, diff --git a/project.mk b/project.mk index b099744..1b2405f 100644 --- a/project.mk +++ b/project.mk @@ -44,6 +44,11 @@ out/go-format-sentinel: $(shell find . -type f -name '*.go') gofmt -s -w -e . touch $@ +out/go-lint-sentinel: $(shell find . -type f -name '*.go') + mkdir --parents $(@D) + golangci-lint run + touch $@ + out/tf-format-sentinel: $(shell find ./examples -type f -name '*.tf') $(shell find ./terratest -type f -name '*.tf') mkdir --parents $(@D) terraform fmt -recursive ./terratest @@ -73,6 +78,9 @@ test: ## run specific unit tests .PHONY: format format: out/go-format-sentinel out/tf-format-sentinel ## format Go code and Terraform config +.PHONY: lint +lint: out/go-lint-sentinel ## lint all Go code + .PHONY: update update: ## update all dependencies go get -u From f2c5db53caf191c364157c22dece6322e5edaac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ho=C3=9F?= Date: Sun, 11 Sep 2022 15:55:06 +0200 Subject: [PATCH 2/3] add missing license infos --- .golangci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index cc2de50..0ab5503 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: The terraform-provider-git Authors +# SPDX-License-Identifier: 0BSD + run: build-tags: - testing From 389856c23c6c5ba5f8be2f298c38f6864cf0e599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ho=C3=9F?= Date: Sun, 11 Sep 2022 15:57:31 +0200 Subject: [PATCH 3/3] improve step name --- .github/workflows/verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 7552151..0c56575 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -40,7 +40,7 @@ jobs: go-version-file: go.mod cache: true - id: lint - name: golangci-lint + name: Lint Go Code uses: golangci/golangci-lint-action@v3 with: version: latest