Skip to content

Commit

Permalink
Check ruby test coverage before merging PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
unoduetre committed Jun 25, 2024
1 parent bd31bca commit c8fa21e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ jobs:
uses: ./.github/workflows/pact-verify.yml
with:
ref: ${{ github.ref }}

test-coverage:
name: Check test coverage
needs:
- test-ruby
- pact-tests
uses: ./.github/workflows/test-coverage.yml
7 changes: 7 additions & 0 deletions .github/workflows/minitest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions .github/workflows/pact-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file.
20 changes: 20 additions & 0 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check test coverage

on:
workflow_call:

jobs:
check_ruby_test_coverage:
name: Check Ruby test coverage
runs-on: ubuntu-latest
steps:
- name: Retrieve minitest test coverage
uses: actions/download-artifact@v4
with:
name: minitest-test-coverage
- name: Retrieve pact test coverage
uses: actions/download-artifact@v4
with:
name: pact-test-coverage
- name: Check Ruby test coverage
run: ls -R
8 changes: 8 additions & 0 deletions lib/tasks/test_coverage.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
desc "Start test coverage tool"
task :test_coverage do

Check failure on line 2 in lib/tasks/test_coverage.rake

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Rails/RakeEnvironment: Include `:environment` task as a dependency for all Rake tasks.
binding.pry

Check failure on line 3 in lib/tasks/test_coverage.rake

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Lint/Debugger: Remove debugger entry point `binding.pry`.
require_relative "../../test/test_coverage"
end

Rake::Task["pact:verify"].enhance %w[test_coverage]
Rake::Task["pact:verify:at"].enhance %w[test_coverage]
12 changes: 12 additions & 0 deletions test/test_coverage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
unless defined?(TEST_COVERAGE_ACTIVATED)
TEST_COVERAGE_ACTIVATED = true
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"
end
4 changes: 1 addition & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require "simplecov"
SimpleCov.start "rails"

require_relative "test_coverage"
require "i18n/coverage"
require "i18n/coverage/printers/file_printer"
I18n::Coverage.config.printer = I18n::Coverage::Printers::FilePrinter
Expand Down

0 comments on commit c8fa21e

Please sign in to comment.