diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..edc833d --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,23 @@ +name: golangci-lint +on: + push: + branches: + - main + pull_request: +permissions: + contents: read # Optional: allow read access to pull requests +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: golangci-lint + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 + with: + version: latest + args: --timeout 10m + only-new-issues: true diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d23a9f4..2a13927 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,7 +1,36 @@ +# copy of https://github.com/hashicorp/vault-workflows-common/blob/main/.github/workflows/tests.yaml name: Run Tests + on: push: + branches: [ "main" ] + pull_request: + +permissions: + contents: read + jobs: run-tests: - # using `main` as the ref will keep your workflow up-to-date - uses: hashicorp/vault-workflows-common/.github/workflows/tests.yaml@main + name: "Run Tests" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0 + with: + go-version-file: .go-version + + - name: Run Build + run: make dev + + - name: Run Tests + run: make test + + - name: Print Coverage Summary + # Parses the profile and prints per-function coverage to stdout + run: go tool cover -func=coverage.txt + + - name: Archive code coverage results + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + with: + name: code-coverage + path: coverage.txt diff --git a/.gitignore b/.gitignore index 3f9ee1f..159efba 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ *.a *.so +coverage.* + # Folders _obj _test diff --git a/Makefile b/Makefile index 0a2d43d..18d4ec0 100644 --- a/Makefile +++ b/Makefile @@ -35,12 +35,17 @@ bootstrap: go mod edit -module github.com/hashicorp/$(REPO_DIR); \ fi +.PHONY: tools +tools: + @which gofumpt > /dev/null || (echo "Installing gofumpt..." && go install mvdan.cc/gofumpt@latest) + @which gotestsum > /dev/null || (echo "Installing gotestsum..." && go install gotest.tools/gotestsum@latest) .PHONY: test -test: fmtcheck - CGO_ENABLED=0 go test ./... $(TESTARGS) -timeout=20m +test: tools fmtcheck + gotestsum --format github-actions \ + -- ./... $(TESTARGS) -timeout=20m -race -coverprofile=coverage.txt -.PHONY: fmtcheck +.PHONY: tools fmtcheck fmtcheck: @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"