From e793fc206c97a3059c8f396d2205cf5335d17db1 Mon Sep 17 00:00:00 2001 From: Mateusz Grotek Date: Tue, 25 Jun 2024 14:51:33 +0100 Subject: [PATCH] Check ruby test coverage before merging PRs --- .github/workflows/ci.yml | 4 ++++ .github/workflows/minitest.yml | 7 +++++++ .github/workflows/pact-verify.yml | 7 +++++++ .../store-test-coverage-percentage.yml | 0 .github/workflows/test-coverage.yml | 19 +++++++++++++++++++ test/test_helper.rb | 7 +++++++ 6 files changed, 44 insertions(+) create mode 100644 .github/workflows/store-test-coverage-percentage.yml create mode 100644 .github/workflows/test-coverage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08a813b098..51ab6b245e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,3 +61,7 @@ jobs: uses: ./.github/workflows/pact-verify.yml with: ref: ${{ github.ref }} + + test-coverage: + name: Check test coverage + uses: ./.github/workflows/test-coverage.yml diff --git a/.github/workflows/minitest.yml b/.github/workflows/minitest.yml index 10e4788fca..fc877d9f66 100644 --- a/.github/workflows/minitest.yml +++ b/.github/workflows/minitest.yml @@ -47,3 +47,10 @@ jobs: RAILS_ENV: test GOVUK_CONTENT_SCHEMAS_PATH: vendor/publishing-api/content_schemas run: bundle exec rake test + + - name: Store test coverage percentage + uses: actions/upload-artifact@v4 + with: + name: minitest-test-coverage + path: coverage/percentage.txt + retention-days: 1 diff --git a/.github/workflows/pact-verify.yml b/.github/workflows/pact-verify.yml index cc36d0c5a6..f941855c82 100644 --- a/.github/workflows/pact-verify.yml +++ b/.github/workflows/pact-verify.yml @@ -64,3 +64,10 @@ jobs: - if: inputs.pact_artifact != '' run: bundle exec rake pact:verify:at[tmp/pacts/${{ inputs.pact_artifact_file_to_verify }}] + + - name: Store test coverage percentage + uses: actions/upload-artifact@v4 + with: + name: pact-test-coverage + path: coverage/percentage.txt + retention-days: 1 diff --git a/.github/workflows/store-test-coverage-percentage.yml b/.github/workflows/store-test-coverage-percentage.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml new file mode 100644 index 0000000000..7e34578817 --- /dev/null +++ b/.github/workflows/test-coverage.yml @@ -0,0 +1,19 @@ +name: Check test coverage + +on: + workflow_call: + +jobs: + name: Check test coverage + runs-on: ubuntu-latest + steps: + - name: Retrieve minitest test coverage + uses: actions/download-artifact@v4 + with: + name: minitest-test-overage + - name: Retrieve pact test coverage + with: + name: minitest-test-overage + - name: Check Ruby test coverage + run: ls -R + diff --git a/test/test_helper.rb b/test/test_helper.rb index fb0ff388a2..9582f1f2f8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,11 @@ require "simplecov" +SimpleCov.at_exit do + SimpleCov.result.format! + File.write( + Rails.root.join("coverage/percentage.txt"), + SimpleCov.result.coverage_statistics[:line].percent.to_s, + ) +end SimpleCov.start "rails" require "i18n/coverage"