|
| 1 | +# This workflow uses actions that are not certified by GitHub. |
| 2 | +# They are provided by a third-party and are governed by |
| 3 | +# separate terms of service, privacy policy, and support |
| 4 | +# documentation. |
| 5 | +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake |
| 6 | +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby |
| 7 | + |
| 8 | +name: Test |
| 9 | +on: |
| 10 | + workflow_call: |
| 11 | + |
| 12 | +jobs: |
| 13 | + test: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + ruby-version: ['2.7', '3.1', '3.2'] |
| 19 | + gemfile: [ rails_6.1, rails_7.0, rails_7.1 ] |
| 20 | + env: |
| 21 | + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v2 |
| 24 | + - name: Set up Ruby |
| 25 | + uses: ruby/setup-ruby@v1 |
| 26 | + with: |
| 27 | + ruby-version: ${{ matrix.ruby-version }} |
| 28 | + bundler-cache: true # runs 'bundle install' and caches installed gems automatically |
| 29 | + - name: Run tests |
| 30 | + run: bundle exec rspec |
| 31 | + |
| 32 | + - name: Archive coverage |
| 33 | + if: ${{ success() || failure() }} |
| 34 | + uses: actions/upload-artifact@v3 |
| 35 | + with: |
| 36 | + name: code-coverage-report-ruby_${{ matrix.ruby-version }}-${{ matrix.gemfile }} |
| 37 | + path: ${{ github.workspace }}/coverage/ |
| 38 | + |
| 39 | + post_coverage: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: test |
| 42 | + permissions: |
| 43 | + pull-requests: write |
| 44 | + steps: |
| 45 | + - uses: actions/download-artifact@v3 |
| 46 | + with: |
| 47 | + name: code-coverage-report-ruby_3.2-rails_7.1 |
| 48 | + path: coverage/ |
| 49 | + |
| 50 | + - name: Install JQ |
| 51 | + run: sudo apt-get install -y jq |
| 52 | + |
| 53 | + - name: Determine coverage |
| 54 | + id: coverage |
| 55 | + run: | |
| 56 | + # Check to see if coverage is under `result.line` or under `result.covered_percent` (older versions) |
| 57 | + coverage=$(jq -r 'if .result.line then .result.line else .result.covered_percent end' < coverage/.last_run.json) |
| 58 | + [ "${coverage}" = "null" ] && coverage="** Failed to determine coverage **" |
| 59 | + echo value="${coverage}" >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - uses: mshick/add-pr-comment@v2 |
| 62 | + with: |
| 63 | + message: | |
| 64 | + * GitHub Actions [run \#${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 65 | +
|
| 66 | + Test coverage: ${{ steps.coverage.outputs.value }}% |
0 commit comments