From 6a96badeb1c6b8ddb2b946eec2b9d8ebac96e1fd Mon Sep 17 00:00:00 2001 From: David LJ Date: Sun, 7 Jul 2024 20:16:23 +0200 Subject: [PATCH] test: report merged tests coverage (#656) * test: merge tests coverage * test: use coverage:report run script * ci: add job to collect & publish coverage results * ci: add coverage dir to codecov action * test: create lcov merged report for Codecov * ci: keep old component tests job name * ci: use previous unit tests name --- .github/workflows/main.yml | 2 + .github/workflows/pull-request.yml | 2 + .github/workflows/reusable-test.yml | 50 +++++++++++++++++-- .../Cypress__all_component_tests.xml | 2 +- karma.conf.js | 7 ++- package.json | 11 +++- pnpm-lock.yaml | 48 ++++++++++++++++-- 7 files changed, 109 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 38c436dc..dd5b3ca8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,6 +20,8 @@ jobs: uses: ./.github/workflows/reusable-test.yml permissions: checks: write + secrets: + codecov-token: ${{ secrets.CODECOV_TOKEN }} lint: name: Lint uses: ./.github/workflows/reusable-lint.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a780ef19..51d6f683 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -15,6 +15,8 @@ jobs: test: name: Test uses: ./.github/workflows/reusable-test.yml + secrets: + codecov-token: ${{ secrets.CODECOV_TOKEN }} lint: name: Lint uses: ./.github/workflows/reusable-lint.yml diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index ac736777..790bfd56 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -7,12 +7,20 @@ on: type: string required: false default: '' + secrets: + codecov-token: + description: Token to use to upload coverage to Codecov. Can be empty for forks https://about.codecov.io/blog/january-product-update-updating-the-codecov-ci-uploaders-to-the-codecov-cli/ + required: true # Add those permissions if reporting test results # https://github.com/dorny/test-reporter/issues/229 # permissions: # checks: write +env: + COVERAGE_ARTIFACT_NAME_PREFIX: coverage- + COVERAGE_DIR: coverage + jobs: templates-have-been-rendered: name: Templated files are rendered @@ -49,12 +57,12 @@ jobs: name: Test results path: '*.xml' reporter: java-junit - - name: Report coverage - # noinspection SpellCheckingInspection - uses: livewing/lcov-job-summary@0a9952db27f98def2ba2de3189c6b24acc4c5501 # v1.1.0 - if: success() || failure() + - name: Upload coverage results + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4 with: - lcov: coverage/davidlj95/website/lcov.info + name: ${{ env.COVERAGE_ARTIFACT_NAME_PREFIX }}${{ github.job }} + path: ${{ env.COVERAGE_DIR }} + retention-days: 5 component-test: name: Component tests @@ -102,3 +110,35 @@ jobs: # Given we're doing caching manually, installing apart to leverage cache install: false component: true + - name: Upload coverage results + uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4 + with: + name: ${{ env.COVERAGE_ARTIFACT_NAME_PREFIX }}${{ github.job }} + path: ${{ env.COVERAGE_DIR }} + retention-days: 5 + + coverage: + name: Coverage + needs: [test, component-test] + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + ref: ${{ inputs.ref }} + - name: Setup + uses: ./.github/actions/setup + - name: Download code coverage reports + uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4 + with: + pattern: ${{ env.COVERAGE_ARTIFACT_NAME_PREFIX }}* + path: ${{ env.COVERAGE_DIR }} + merge-multiple: true + - name: Merge coverage reports + run: pnpm run coverage:report:all + - name: Upload to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + directory: ${{ env.COVERAGE_DIR }} + token: ${{ secrets.codecov-token }} diff --git a/.idea/runConfigurations/Cypress__all_component_tests.xml b/.idea/runConfigurations/Cypress__all_component_tests.xml index 1e0fe0b4..b3d378ec 100644 --- a/.idea/runConfigurations/Cypress__all_component_tests.xml +++ b/.idea/runConfigurations/Cypress__all_component_tests.xml @@ -3,7 +3,7 @@ -