From 995f7036de3ef2881e9cb85265ff0cfa0c71e90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 18 Jun 2024 19:01:48 +0200 Subject: [PATCH] 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. --- .erb-lint.yml | 2 ++ .github/workflows/linters.yml | 40 +++++++++++++++++++++++++++++++++++ .github/workflows/pronto.yml | 8 ++----- .rubocop.yml | 1 + 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/linters.yml diff --git a/.erb-lint.yml b/.erb-lint.yml index 105042f03..31bcfa563 100644 --- a/.erb-lint.yml +++ b/.erb-lint.yml @@ -1,5 +1,7 @@ --- EnableDefaultLinters: false +exclude: + - '**/vendor/**/*' linters: AllowedScriptType: enabled: true diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 000000000..7a78c3b7c --- /dev/null +++ b/.github/workflows/linters.yml @@ -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 }} diff --git a/.github/workflows/pronto.yml b/.github/workflows/pronto.yml index 34eac27c7..e99175ac1 100644 --- a/.github/workflows/pronto.yml +++ b/.github/workflows/pronto.yml @@ -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 }} diff --git a/.rubocop.yml b/.rubocop.yml index 96d7572b5..e6ef500dc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,6 +11,7 @@ AllCops: Exclude: - "db/schema.rb" - "app/lib/ckeditor/backend/active_storage.rb" + - "vendor/**/*" DisabledByDefault: true Bundler/DuplicatedGem: