From 5947f92d228e1bf29ec10060e30419841669e837 Mon Sep 17 00:00:00 2001 From: Pat Gavlin Date: Thu, 5 Oct 2023 07:53:34 -0700 Subject: [PATCH] chore: enable code coverage (#44) Add a Makefile target that will run tests with coverage profiling enabled. Upload coverage data as part of the various publish jobs. --- .github/workflows/publish-prerelease.yaml | 2 ++ .github/workflows/publish-release.yaml | 2 ++ .github/workflows/publish-snapshot.yaml | 2 ++ .github/workflows/stage-test.yml | 17 +++++++++++++++++ Makefile | 3 +++ codecov.yml | 23 +++++++++++++++++++++++ 6 files changed, 49 insertions(+) create mode 100644 codecov.yml diff --git a/.github/workflows/publish-prerelease.yaml b/.github/workflows/publish-prerelease.yaml index 6649e482..893146d3 100644 --- a/.github/workflows/publish-prerelease.yaml +++ b/.github/workflows/publish-prerelease.yaml @@ -13,6 +13,8 @@ jobs: uses: ./.github/workflows/stage-lint.yml test: uses: ./.github/workflows/stage-test.yml + with: + enable-coverage: true publish: needs: [test, lint] uses: ./.github/workflows/stage-publish.yml diff --git a/.github/workflows/publish-release.yaml b/.github/workflows/publish-release.yaml index c2613678..733e6bd6 100644 --- a/.github/workflows/publish-release.yaml +++ b/.github/workflows/publish-release.yaml @@ -14,6 +14,8 @@ jobs: uses: ./.github/workflows/stage-lint.yml test: uses: ./.github/workflows/stage-test.yml + with: + enable-coverage: true publish: needs: [test, lint] uses: ./.github/workflows/stage-publish.yml diff --git a/.github/workflows/publish-snapshot.yaml b/.github/workflows/publish-snapshot.yaml index 74e5c2ef..8b532f0c 100644 --- a/.github/workflows/publish-snapshot.yaml +++ b/.github/workflows/publish-snapshot.yaml @@ -16,6 +16,8 @@ jobs: uses: ./.github/workflows/stage-lint.yml test: uses: ./.github/workflows/stage-test.yml + with: + enable-coverage: true publish: needs: [test, lint] uses: ./.github/workflows/stage-publish.yml diff --git a/.github/workflows/stage-test.yml b/.github/workflows/stage-test.yml index 5f1a0280..9964a82e 100644 --- a/.github/workflows/stage-test.yml +++ b/.github/workflows/stage-test.yml @@ -9,6 +9,12 @@ on: required: false type: string + enable-coverage: + description: Collects coverage data from tests. + default: false + required: false + type: boolean + jobs: test: name: Test @@ -25,8 +31,19 @@ jobs: stable: ${{ matrix.go-stable }} - name: Install Pulumi CLI uses: pulumi/action-install-pulumi-cli@v2 + - name: Test w/coverage + if: ${{ inputs.enable-coverage }} + run: make test_cover - name: Test + if: ${{ ! inputs.enable-coverate }} run: make test + - name: Upload code coverage + if: ${{ inputs.enable-coverage }} + uses: codecov/codecov-action@v3 + with: + fail_ci_if_error: false + verbose: true + token: ${{ secrets.CODECOV_TOKEN }} strategy: fail-fast: false matrix: diff --git a/Makefile b/Makefile index 7e4827a6..0db67659 100644 --- a/Makefile +++ b/Makefile @@ -34,3 +34,6 @@ build_debug:: ensure test:: build ${GO} test --timeout 30m -short -count 1 -parallel ${CONCURRENCY} ./... + +test_cover:: build + ${GO} test --timeout 30m -count 1 -coverpkg=github.com/pulumi/esc/... -race -coverprofile=coverage.out -parallel ${CONCURRENCY} ./... diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..e001bdf5 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,23 @@ +coverage: + status: + + # Project tracks and reports the project-level coverage. + project: + default: + informational: true + + # Patch tracks the coverage of the changes in a single patch. + patch: + default: + informational: true + +ignore: + # None of the test data should count against coverage. + - "**/testdata" + +# Don't comment on PRs. +comment: false + +# Don't post annotations to GitHub. +github_checks: + annotations: false