[RUBY] Make failed rspec tests visible on github check annotations

Introduction

Convenient to rotate CICD flow with Github Actions! But when rspec is broken, it is difficult to find the error part. I hope you can see it on Github Checks.

Break

I tried uploading with reviewdog, but there was no supported error format. https://github.com/reviewdog/reviewdog#available-pre-defined-errorformat

When I was looking at the source thinking that I could make a PR to support it, a proposal called Reviewdog Diagnostic Format was proposed. https://github.com/reviewdog/reviewdog/tree/master/proto/rdf

Rather than writing a parser, it seems better to process the output of rspec according to this format. But it doesn't seem to be the official version yet. SARIF looks good. So instead of RDFormat, I decided to create a formatter for rspec according to the existing input format. https://github.com/reviewdog/reviewdog#input-format

Try a prototype and use checkstyle, which makes it easy to check the operation.

I miss XML.

Sudden

https://github.com/astronoka/rspec-checkstyle_formatter I made a formatter and made it a gem.

During implementation, the XML builder / parser has an error due to the ascii color code \ e [0; 34m" that is output with an error such as mysql. By the way, I feel more and more nostalgic when I get an error because of this.

Description example in Github Actions


name: CI

on: push

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2

    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: 2.7.1

    - name: Restore gems
      uses: actions/cache@v2
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gems-

    - name: Run rspec
      run: |
        bundle config path vendor/bundle
        bundle install --jobs 4 --retry 3
        bundle exec rspec \
          --no-fail-fast \
          --format RSpec::CheckstyleFormatter \
          --out /tmp/rspec_result.xml

    - name: Upload rspec result
      if: always()
      uses: actions/upload-artifact@v2
      with:
        name: rspec_result.xml
        path: /tmp/rspec_result.xml

    - name: Install reviewdog
      if: always()
      uses: reviewdog/action-setup@v1
      with:
        reviewdog_version: latest

    - name: Report rspec error
      if: always()
      env:
        REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        cat /tmp/rspec_result.xml | reviewdog -name=rspec -f=checkstyle -reporter=github-check -filter-mode=nofilter

like this.

image.png

reviewdog Great: sparkles:

While wondering how to pass it in the format for linter Done.

Recommended Posts

Make failed rspec tests visible on github check annotations