diff --git a/.github/workflows/test-activerecord.yml b/.github/workflows/test-activerecord.yml index edd83f7..0002661 100644 --- a/.github/workflows/test-activerecord.yml +++ b/.github/workflows/test-activerecord.yml @@ -1,6 +1,6 @@ --- name: test-activerecord -on: [push, pull_request] +on: workflow_call permissions: contents: read jobs: @@ -10,12 +10,12 @@ jobs: fail-fast: false matrix: entry: - - { ruby: '3.3', activerecord: '~> 6.1.0', grape: '~> 1.8', rack: '~> 2.2' } - - { ruby: '3.3', activerecord: '~> 7.2.0', grape: '~> 2.4' } - - { ruby: '3.3', activerecord: '~> 7.2.0', grape: '~> 3.0' } - - { ruby: '3.4', activerecord: '~> 8.0.0', grape: '~> 2.4' } - - { ruby: '3.4', activerecord: '~> 8.1.0', grape: '~> 4.0' } - - { ruby: '4.0', activerecord: '~> 8.1.0', grape: '~> 4.0' } + - { ruby: '3.3', activerecord: '~> 6.1.0', grape: '~> 1.8', rack: '~> 2.2', coverage: false } + - { ruby: '3.3', activerecord: '~> 7.2.0', grape: '~> 2.4', coverage: false } + - { ruby: '3.3', activerecord: '~> 7.2.0', grape: '~> 3.0', coverage: true } + - { ruby: '3.4', activerecord: '~> 8.0.0', grape: '~> 2.4', coverage: false } + - { ruby: '3.4', activerecord: '~> 8.1.0', grape: '~> 4.0', coverage: false } + - { ruby: '4.0', activerecord: '~> 8.1.0', grape: '~> 4.0', coverage: false } name: test (ruby=${{ matrix.entry.ruby }}, activerecord=${{ matrix.entry.activerecord }}, grape=${{ matrix.entry.grape }}) env: ACTIVERECORD_VERSION: ${{ matrix.entry.activerecord }} @@ -29,3 +29,11 @@ jobs: bundler-cache: true - name: Run Tests run: bundle exec rake spec + - uses: coverallsapp/github-action@v2 + if: matrix.entry.coverage + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + file: coverage/lcov/grape-roar.lcov + format: lcov + flag-name: activerecord-${{ strategy.job-index }} + parallel: true diff --git a/.github/workflows/test-mongodb.yml b/.github/workflows/test-mongodb.yml index 473c2cc..fc623f1 100644 --- a/.github/workflows/test-mongodb.yml +++ b/.github/workflows/test-mongodb.yml @@ -1,6 +1,6 @@ --- name: test-mongodb -on: [push, pull_request] +on: workflow_call permissions: contents: read jobs: @@ -10,13 +10,13 @@ jobs: fail-fast: false matrix: entry: - - { ruby: '3.3', mongoid: '~> 6.4.8', mongodb: '6.0', grape: '~> 1.7.0', rack: '~> 2.2' } - - { ruby: '3.3', mongoid: '~> 6.4.8', mongodb: '6.0', grape: '~> 2.0.0' } - - { ruby: '3.3', mongoid: '~> 7.5.4', mongodb: '7.0', grape: '~> 2.4' } - - { ruby: '3.3', mongoid: '~> 8.1.11', mongodb: '8.0', grape: '~> 2.4' } - - { ruby: '3.3', mongoid: '~> 8.1.11', mongodb: '8.0', grape: '~> 3.0' } - - { ruby: '3.4', mongoid: '~> 9.1', mongodb: '8.0', grape: '~> 4.0' } - - { ruby: '4.0', mongoid: '~> 9.1', mongodb: '8.0', grape: '~> 4.0' } + - { ruby: '3.3', mongoid: '~> 6.4.8', mongodb: '6.0', grape: '~> 1.7.0', rack: '~> 2.2', coverage: false } + - { ruby: '3.3', mongoid: '~> 6.4.8', mongodb: '6.0', grape: '~> 2.0.0', coverage: true } + - { ruby: '3.3', mongoid: '~> 7.5.4', mongodb: '7.0', grape: '~> 2.4', coverage: false } + - { ruby: '3.3', mongoid: '~> 8.1.11', mongodb: '8.0', grape: '~> 2.4', coverage: false } + - { ruby: '3.3', mongoid: '~> 8.1.11', mongodb: '8.0', grape: '~> 3.0', coverage: false } + - { ruby: '3.4', mongoid: '~> 9.1', mongodb: '8.0', grape: '~> 4.0', coverage: true } + - { ruby: '4.0', mongoid: '~> 9.1', mongodb: '8.0', grape: '~> 4.0', coverage: false } name: test (ruby=${{ matrix.entry.ruby }}, mongoid=${{ matrix.entry.mongoid }}, mongodb=${{ matrix.entry.mongodb }}, grape=${{ matrix.entry.grape }}) env: MONGOID_VERSION: ${{ matrix.entry.mongoid }} @@ -40,3 +40,11 @@ jobs: bundler-cache: true - name: Run Tests run: bundle exec rake spec + - uses: coverallsapp/github-action@v2 + if: matrix.entry.coverage + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + file: coverage/lcov/grape-roar.lcov + format: lcov + flag-name: mongoid-${{ strategy.job-index }} + parallel: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 19bd011..6d6c6d6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,3 +32,16 @@ jobs: bundler-cache: true - name: Run Tests run: bundle exec rake spec + test-activerecord: + uses: ./.github/workflows/test-activerecord.yml + test-mongodb: + uses: ./.github/workflows/test-mongodb.yml + finish: + name: Finish Coveralls + needs: [test, test-activerecord, test-mongodb] + runs-on: ubuntu-latest + steps: + - uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true diff --git a/.gitignore b/.gitignore index d5a4807..ff97a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ Gemfile.lock doc pkg .bundle +/coverage/ gemfiles/*.lock \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index dfd6cce..86e43bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * [#40](https://github.com/ruby-grape/grape-roar/pull/40): Document deeply nested representers and verify shared post/image records retain their attributes across repeated requests - [@dblock](https://github.com/dblock). * [#42](https://github.com/ruby-grape/grape-roar/pull/42): Support caching plain rendered representations without forwarding Roar-only options to generic JSON encoders; document cache serialization and request-context keys - [@dblock](https://github.com/dblock). * [#41](https://github.com/ruby-grape/grape-roar/pull/41): Document hash-backed representers with explicit key getters and verify module/decorator rendering for symbol and string keys - [@dblock](https://github.com/dblock). +* [#43](https://github.com/ruby-grape/grape-roar/pull/43): Add SimpleCov LCOV reports and a coverage badge; merge Coveralls reports from selected existing ORM matrix entries without duplicate test runs - [@dblock](https://github.com/dblock). * Your contribution here. ### 0.5.0 (2025/09/25) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a641c27..f47fdd6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,6 +50,8 @@ GRAPE_VERSION='~> 1.8' RACK_VERSION='~> 2.2' bundle exec rake Setting `ACTIVERECORD_VERSION` or `MONGOID_VERSION` loads that ORM and automatically includes its tagged examples in the suite. ActiveRecord adapter and validation tests do not require a database. Mongoid examples require MongoDB at `localhost:27017` and use the dedicated `grape_roar_test` database. CI runs MongoDB service containers for Mongoid 6.x through 9.x and tests newer Grape versions with ORM releases that permit their ActiveSupport requirements. +Spec runs generate `coverage/lcov/grape-roar.lcov` with SimpleCov. `test.yml` runs the core matrix and calls the separate reusable `test-activerecord.yml` and `test-mongodb.yml` workflows. Only `test.yml` handles push and pull-request events, so the ORM matrices run once per event. ORM entries marked `coverage: true` upload reports using the built-in GitHub token, covering ActiveRecord and both Mongoid association implementations without extra test runs. After the core matrix and both reusable workflows succeed, one completion job in `test.yml` merges the uploads into a single Coveralls report. + #### Write Tests Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/grape-roar](spec/grape-roar). diff --git a/Gemfile b/Gemfile index 0e9aa0a..451f1ac 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,8 @@ gemspec group :test do gem 'rack-test' gem 'rspec' + gem 'simplecov', require: false + gem 'simplecov-lcov', require: false end group :development, :test do diff --git a/README.md b/README.md index aa3fc5f..75cc131 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,8 @@ Grape::Roar ----------- [![Gem Version](http://img.shields.io/gem/v/grape-roar.svg)](http://badge.fury.io/rb/grape-roar) +[![Coverage Status](https://coveralls.io/repos/github/ruby-grape/grape-roar/badge.svg?branch=master)](https://coveralls.io/github/ruby-grape/grape-roar?branch=master) [![test](https://github.com/ruby-grape/grape-roar/actions/workflows/test.yml/badge.svg)](https://github.com/ruby-grape/grape-roar/actions/workflows/test.yml) -[![test-activerecord](https://github.com/ruby-grape/grape-roar/actions/workflows/test-activerecord.yml/badge.svg)](https://github.com/ruby-grape/grape-roar/actions/workflows/test-activerecord.yml) -[![test-mongodb](https://github.com/ruby-grape/grape-roar/actions/workflows/test-mongodb.yml/badge.svg)](https://github.com/ruby-grape/grape-roar/actions/workflows/test-mongodb.yml) Use [Roar](https://github.com/apotonick/roar) with [Grape](https://github.com/intridea/grape). diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0983ce2..57d5554 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,16 @@ require 'bundler' Bundler.setup :default, :test + +require 'simplecov' +require 'simplecov-lcov' +SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true +SimpleCov::Formatter::LcovFormatter.config.lcov_file_name = 'grape-roar.lcov' +SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter +SimpleCov.start do + add_filter '/spec/' +end + Bundler.require require 'grape'