Run every linter separately in Github Actions

The main reason for this change is that Pronto doesn't run in pull
requests opened by external contributors, and we haven't found how to
fix this issue.

Another reason is that Pronto only detects issues in the lines where the
changes are done, but sometimes we introduce issues related to other
lines and those aren't detected by Pronto. Also, when adding or changing
Rubocop rules, or when we update Rubocop, Pronto doesn't check whether
those rules are applied in every Ruby and ERB file, and we sometimes
forget to do so (particularly in ERB files).

So, from now, the linters will check all the code in every pull request.

Note we're now excluding the `vendor` folder in our linters because the
`setup-ruby` action actions generates a `vendor/bundle/` folder with all
our gem dependencies, and we don't want to check those files.
This commit is contained in:
Javi Martín
2024-06-18 19:01:48 +02:00
parent 61a6ba26b1
commit 995f7036de
4 changed files with 45 additions and 6 deletions

40
.github/workflows/linters.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: linters
on: [pull_request]
permissions:
contents: read
jobs:
linters:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: RuboCop
run: bundle exec rubocop --fail-level convention --display-only-fail-level-offenses -f github
- name: ERB Lint
run: bundle exec erblint .
- name: ESLint
run: npx eslint . --quiet
- name: Stylelint
run: npx stylelint app/assets/stylesheets
name: ${{ matrix.name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- run: |
git fetch --no-tags --prune origin +refs/heads/*:refs/remotes/origin/*
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Setup NPM
uses: actions/setup-node@v4
with:
cache: "npm"
node-version-file: ".node-version"
- name: Install node packages
run: npm clean-install
- name: ${{ matrix.name }}
run: ${{ matrix.run }}

View File

@@ -4,6 +4,7 @@ on: [pull_request]
jobs:
pronto:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.actor != 'dependabot'
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -21,9 +22,4 @@ jobs:
- name: Install node packages
run: npm clean-install
- name: Run pronto
run: |
if [[ ${{ github.event.pull_request.head.repo.full_name }} == ${{ github.event.pull_request.base.repo.full_name }} && ${{ github.actor }} != dependabot ]]; then
PRONTO_PULL_REQUEST_ID="$(jq --raw-output .number "$GITHUB_EVENT_PATH")" PRONTO_GITHUB_ACCESS_TOKEN="${{ github.token }}" bundle exec pronto run -f github_status github_pr -c origin/${{ github.base_ref }}
else
bundle exec pronto run --exit-code -c origin/${{ github.base_ref }}
fi
run: PRONTO_PULL_REQUEST_ID="$(jq --raw-output .number "$GITHUB_EVENT_PATH")" PRONTO_GITHUB_ACCESS_TOKEN="${{ github.token }}" bundle exec pronto run -f github_status github_pr -c origin/${{ github.base_ref }}