LoginSignup
12
3

More than 3 years have passed since last update.

RSpecの実行結果を分かりやすくするGitHub Actionを作った

Posted at

はじめに

CI/CDのサービスとして最近はGitHub Actionsを利用しているのですが、CircleCIと比較した時にRSpecが失敗した時の実行結果が分かりにくいのが不満でした。
そんなストレスを解消するために社内ハッカソンで作った以下のGitHub Actionを紹介します。

RSpec Report · Actions · GitHub Marketplace · GitHub

何が出来るの?

PRイベントの場合は失敗結果がコメントされます。
またコメントされることで同様の内容がメールでも通知されるので、失敗したテストの内容がGitHubにアクセスしなくても把握できるようになります。

a23798fbb2f0e6454bf75a0e09034eb8.png

PRイベント以外の場合はChecks API経由で通知されます。

0d3c61f6ecc3354a9734eb2b30a82211.png

使い方

test.yml
name: Build
on:
  pull_request:

jobs:
  rspec:
    steps:
      # RSpec実行の為の事前準備は省略しています

      - name: Test
        run: bundle exec rspec -f j -o tmp/rspec_results.json -f p

      - name: RSpec Report
        uses: SonicGarden/rspec-report-action@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          json-path: tmp/rspec_results.json
        if: always()

その他

ポイント

  • JSONフォーマットで出力したRSpecの実行結果を解析してコメントしています
    • rspecコマンドの-f j -o tmp/rspec_results.jsonオプションは必須です(保存先は任意)
  • テストが全て通ればコメントは削除されます
  • 繰り返し同じコメントが投稿されることはありません
  • テストの並列実行にも対応しています
    • その場合は以下のようにタイトルがユニークになるように調整してください
with:
  token: ${{ secrets.GITHUB_TOKEN }}
  json-path: tmp/rspec_results.json
  title: "# :cold_sweat: RSpec failure ${{ matrix.ci_node_index }}"

リポジトリ

GitHub - SonicGarden/rspec-report-action: A GitHub Action that report RSpec failure.

良かったら使ってみてください。

12
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
3