Skip to content

Commit

Permalink
Setup Code Coverage (#28)
Browse files Browse the repository at this point in the history
Integrate Code Climate
  • Loading branch information
avmnu-sng authored Sep 10, 2021
1 parent 086433e commit eccda63
Show file tree
Hide file tree
Showing 30 changed files with 427 additions and 155 deletions.
27 changes: 27 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "2"
checks:
file-lines:
config:
threshold: 300
method-complexity:
config:
threshold: 10
method-count:
config:
threshold: 50
similar-code:
config:
threshold: 50
identical-code:
config:
threshold: 50
plugins:
duplication:
enabled: true
exclude_patterns:
- "spec/"
exclude_patterns:
- "lib/rspec_tracer/html_reporter/assets"
- "lib/rspec_tracer/html_reporter/public"
- "sample_projects"
- "tmp"
77 changes: 71 additions & 6 deletions .github/workflows/lint-and-specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

concurrency:
group: ${GITHUB_REF#refs/heads/}
group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-lint-and-specs
cancel-in-progress: true

jobs:
Expand All @@ -20,18 +20,83 @@ jobs:
ruby: [ '2.5', '2.6', '2.7', '3.0', 'head' ]

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Setup Code Climate test-reporter
run: |
pip3 install awscli --user
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- name: Install Dependencies
run: bundle install --jobs 3 --retry 3

- name: Run Rubocop
run: bundle exec rake rubocop
- name: Run Tests
run: bundle exec rake

- name: Configure AWS Credentials for Coverage Upload
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CI_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CI_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Upload Job Coverage
env:
GIT_BRANCH: ${{ github.event_name == 'pull_request' && github.head_ref || 'main' }}
GIT_COMMIT_SHA: ${{ github.sha }}
run: |
./cc-test-reporter format-coverage coverage/coverage.json --output coverage/ruby-${{ matrix.ruby }}.simplecov.json --input-type simplecov
aws s3 cp coverage/ruby-${{ matrix.ruby }}.simplecov.json ${{ secrets.CI_ARTIFACTS_S3_URI }}/${{ github.repository }}/${{ github.run_number }}/ruby-${{ matrix.ruby }}.simplecov.json
coverage:
needs: [ 'main' ]
name: coverage
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
architecture: 'x64'

- name: Setup Code Climate test-reporter
run: |
pip3 install awscli --user
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- name: Configure AWS Credentials for Coverage Upload
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CI_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CI_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Download Jobs Coverage
run: |
mkdir coverage
aws s3 cp --recursive ${{ secrets.CI_ARTIFACTS_S3_URI }}/${{ github.repository }}/${{ github.run_number }}/ coverage/
- name: Run Specs
run: bundle exec rake spec
- name: Upload Coverage
env:
GIT_BRANCH: ${{ github.event_name == 'pull_request' && github.head_ref || 'main' }}
GIT_COMMIT_SHA: ${{ github.sha }}
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
./cc-test-reporter sum-coverage coverage/ruby-*.simplecov.json --parts 5 --output coverage/coverage.json
./cc-test-reporter upload-coverage --input coverage/coverage.json
12 changes: 4 additions & 8 deletions .github/workflows/rails-5-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

concurrency:
group: ${GITHUB_REF#refs/heads/}-rails-1
group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-rails-5
cancel-in-progress: true

jobs:
Expand All @@ -23,7 +23,8 @@ jobs:
simplecov: [ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -39,9 +40,4 @@ jobs:
RSPEC_RAILS_VERSION: "~> ${{ matrix.rspec-rails }}"
SIMPLECOV_VERSION: "~> 0.${{ matrix.simplecov }}.0"
BRANCH_COVERAGE: "${{ matrix.simplecov >= 18 && 'true' || 'false' }}"
run: |
echo RAILS_VERSION=$RAILS_VERSION
echo RSPEC_RAILS_VERSION=$RSPEC_RAILS_VERSION
echo SIMPLECOV_VERSION=$SIMPLECOV_VERSION
echo BRANCH_COVERAGE=$BRANCH_COVERAGE
bundle exec cucumber --tags @rails_app
run: bundle exec cucumber --tags @rails-app
12 changes: 4 additions & 8 deletions .github/workflows/rails-6-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

concurrency:
group: ${GITHUB_REF#refs/heads/}-rails-2
group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-rails-6
cancel-in-progress: true

jobs:
Expand All @@ -23,7 +23,8 @@ jobs:
simplecov: [ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -39,9 +40,4 @@ jobs:
RSPEC_RAILS_VERSION: "~> ${{ matrix.rspec-rails }}"
SIMPLECOV_VERSION: "~> 0.${{ matrix.simplecov }}.0"
BRANCH_COVERAGE: "${{ matrix.simplecov >= 18 && 'true' || 'false' }}"
run: |
echo RAILS_VERSION=$RAILS_VERSION
echo RSPEC_RAILS_VERSION=$RSPEC_RAILS_VERSION
echo SIMPLECOV_VERSION=$SIMPLECOV_VERSION
echo BRANCH_COVERAGE=$BRANCH_COVERAGE
bundle exec cucumber --tags @rails_app
run: bundle exec cucumber --tags @rails-app
11 changes: 4 additions & 7 deletions .github/workflows/ruby-project-part-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

concurrency:
group: ${GITHUB_REF#refs/heads/}-ruby-1
group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-ruby-1
cancel-in-progress: true

jobs:
Expand All @@ -22,7 +22,8 @@ jobs:
simplecov: [ '0.12.0', '0.13.0', '0.14.0', '0.15.0', '0.16.0', '0.17.0' ]

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -36,8 +37,4 @@ jobs:
env:
RSPEC_VERSION: "~> ${{ matrix.rspec }}"
SIMPLECOV_VERSION: "~> ${{ matrix.simplecov }}"
run: |
echo RSPEC_VERSION=$RSPEC_VERSION
echo SIMPLECOV_VERSION=$SIMPLECOV_VERSION
echo BRANCH_COVERAGE=$BRANCH_COVERAGE
bundle exec cucumber --tags @ruby_app
run: bundle exec cucumber --tags @ruby-app
11 changes: 4 additions & 7 deletions .github/workflows/ruby-project-part-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

concurrency:
group: ${GITHUB_REF#refs/heads/}-ruby-2
group: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}-ruby-2
cancel-in-progress: true

jobs:
Expand All @@ -22,7 +22,8 @@ jobs:
simplecov: [ '0.18.0', '0.19.0', '0.20.0', '0.21.0' ]

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -37,8 +38,4 @@ jobs:
RSPEC_VERSION: "~> ${{ matrix.rspec }}"
SIMPLECOV_VERSION: "~> ${{ matrix.simplecov }}"
BRANCH_COVERAGE: true
run: |
echo RSPEC_VERSION=$RSPEC_VERSION
echo SIMPLECOV_VERSION=$SIMPLECOV_VERSION
echo BRANCH_COVERAGE=$BRANCH_COVERAGE
bundle exec cucumber --tags @ruby_app
run: bundle exec cucumber --tags @ruby-app
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Layout/MultilineOperationIndentation:

Metrics/BlockLength:
Exclude:
- "tasks/**/*"
- "spec/**/*"

Metrics/ClassLength:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ GEM
yui-compressor (0.12.0)

PLATFORMS
ruby
x86_64-darwin-19
x86_64-linux

DEPENDENCIES
aruba (~> 2.0)
Expand Down
48 changes: 14 additions & 34 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,17 @@ require 'rubocop/rake_task'
RuboCop::RakeTask.new

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

namespace :features do
desc 'Run feature specs on sample ruby project'
task :ruby do
puts "\nRunning feature specs on sample Ruby project..."

command = <<-COMMAND.strip.gsub(/\s+/, ' ')
RSPEC_VERSION="~> 3.10.0"
SIMPLECOV_VERSION="~> 0.21.0"
BRANCH_COVERAGE="true"
bundle exec cucumber features/ruby_app_*.feature
COMMAND

exit(1) unless system(command)
end

desc 'Run feature specs on sample rails project'
task :rails do
puts "\nRunning feature specs on sample Rails project..."

command = <<-COMMAND.strip.gsub(/\s+/, ' ')
RAILS_VERSION="~> 6.1.0"
RSPEC_RAILS_VERSION="~> 5.0.0"
SIMPLECOV_VERSION="~> 0.21.0"
BRANCH_COVERAGE="true"
bundle exec cucumber features/rails_app_*.feature
COMMAND

exit(1) unless system(command)
end
end

task default: %i[rubocop spec features:ruby features:rails]
RSpec::Core::RakeTask.new(:rspec)

Dir.glob('tasks/features/**/*.rake') { |task| load task }

task default: %i[
rubocop
rspec
features:coverage:rspec_tracer:measure_line_coverage
features:coverage:simplecov:measure_branch_coverage
features:coverage:simplecov:measure_line_coverage
features:validation:rspec_tracer:validate_line_coverage
features:validation:simplecov:validate_branch_coverage
features:validation:simplecov:validate_line_coverage
]
8 changes: 4 additions & 4 deletions features/rails_app_with_explicit_run.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@rails_app @simplecov @explicit_run @disable-bundler
@rails-app @simplecov @explicit-run @disable-bundler
Feature: Rails App with Explicit Run

Adding rspec-tracer with simplecov should generate tracer reports and the
Expand Down Expand Up @@ -53,7 +53,7 @@ Feature: Rails App with Explicit Run
And The dependency report should have correct details
And The reverse dependency report should have correct details
And The JSON coverage report should have been generated for "RSpec"
And the output should contain "71 / 72 LOC (98.61%) covered"
And The coverage percent stat is "71 / 72 LOC (98.61%) covered"
And The JSON coverage report should have correct coverage for "RSpec"
Given I want to explicitly run all the tests
When I run `bundle exec rspec spec`
Expand Down Expand Up @@ -101,7 +101,7 @@ Feature: Rails App with Explicit Run
And The dependency report should have correct details
And The reverse dependency report should have correct details
And The JSON coverage report should have been generated for "RSpec"
And the output should contain "71 / 72 LOC (98.61%) covered"
And The coverage percent stat is "71 / 72 LOC (98.61%) covered"
And The JSON coverage report should have correct coverage for "RSpec"
Given I reset explicit run
When I run `bundle exec rspec spec`
Expand Down Expand Up @@ -141,5 +141,5 @@ Feature: Rails App with Explicit Run
And The dependency report should have correct details
And The reverse dependency report should have correct details
And The JSON coverage report should have been generated for "RSpec"
And the output should contain "71 / 72 LOC (98.61%) covered"
And The coverage percent stat is "71 / 72 LOC (98.61%) covered"
And The JSON coverage report should have correct coverage for "RSpec"
Loading

0 comments on commit eccda63

Please sign in to comment.