Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion .github/workflows/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Tests

on: [push]
on:
pull_request:
push:
branches: [master] # push is already covered by pull_request while a PR is open

permissions:
contents: read
pull-requests: write # needed to post/update the coverage comment

jobs:
linter:
Expand Down Expand Up @@ -31,10 +38,48 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # full history, needed to diff against the PR's base branch

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- run: bundle exec rspec

- name: Generate coverage report for the PR's changed files
if: github.event_name == 'pull_request'
run: |
curl -L https://github.com/asseinfo/test-reporter/releases/download/0.11.1/cc-test-reporter > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage coverage/coverage.json -t simplecov -o coverage/codeclimate.json

gem install couve

git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD \
| couve coverage/codeclimate.json coverage-report.md --changed-files -

- name: Post or update the coverage comment on the PR
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
MARKER="<!-- couve-coverage -->"

if [ "$(grep -c '^|' coverage-report.md)" -le 2 ]; then
REPORT="Nenhum arquivo coberto por testes foi alterado nesta PR."
else
REPORT="$(cat coverage-report.md)"
fi

{ echo "$MARKER"; echo; echo "$REPORT"; } > full-comment.md

COMMENT_ID=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
--paginate --jq 'map(select(.body | startswith("<!-- couve-coverage -->"))) | .[0].id // empty')

if [ -n "$COMMENT_ID" ]; then
gh api -X PATCH "repos/${{ github.repository }}/issues/comments/$COMMENT_ID" -F body=@full-comment.md
else
gh api -X POST "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" -F body=@full-comment.md
fi
10 changes: 9 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
require 'simplecov'
SimpleCov.start unless ENV["NO_COVERAGE"]
require 'simplecov_json_formatter'

unless ENV["NO_COVERAGE"]
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::JSONFormatter,
SimpleCov::Formatter::HTMLFormatter
])
SimpleCov.start
end

require "bundler/setup"
require "br_danfe"
Expand Down
Loading