add rubocop github ci #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: RuboCop linting | |
on: | |
push: | |
pull_request: | |
types: [ opened, reopened ] | |
jobs: | |
rubocop: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install Ruby and gems | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 2.7.8 | |
bundler-cache: true | |
- name: Run RuboCop | |
run: | | |
rubocop --format offenses | |
rubocop --format offenses --out tmp/rubocop/offenses.json | |
- name: Post RuboCop annotations | |
if: always() | |
run: | | |
cat tmp/rubocop/offenses.json | jq -r '.files[] | .offenses[] | "\(.message) at \(.location.line):\(.location.column)"' | \ | |
while read -r line; do | |
file=$(echo "$line" | awk -F ':' '{print $1}') | |
message=$(echo "$line" | awk -F ':' '{print $2}') | |
line_number=$(echo "$line" | awk -F ':' '{print $3}' | cut -d' ' -f1) | |
col_number=$(echo "$line" | awk -F ':' '{print $4}') | |
echo "::error file=${file},line=${line_number},col=${col_number}::${message}" | |
done |