diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ff55d914e..d0652ff32 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,87 +1,45 @@ -on: [push] +name: Linting + +# Trigger each time HEAD branch is updated in a pull request +# see https://github.com/orgs/community/discussions/26366 +on: + pull_request: + types: [opened, reopened, synchronize, ready_for_review] jobs: + + # Resources: + # number [1] being most important + # [1] https://github.com/actions/checkout/issues/520#issuecomment-1167205721 + # [2] https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b + # [3] https://community.atlassian.com/t5/Bitbucket-questions/Git-diff-show-different-files-than-PR-Pull-Request/qaq-p/2331786 rubocop: + name: RuboCop runs-on: ubuntu-latest - name: A job to check rubocop linter errors steps: - - uses: actions/checkout@v2 + - name: 'Checkout PR branch (with test merge-commit)' + uses: actions/checkout@v4 + with: + fetch-depth: 2 # to also fetch parent of PR + + # Adapted from this great comment [1]. Git diff adapted from [2]. + # "|| test $? = 1;" is used to ignore the exit code of grep when no files + # are found matching the pattern. For the "three dots" ... syntax, see [3]. + - name: Get changed files + run: | + files=$(git diff --name-only --diff-filter=ACMR -r HEAD^1...HEAD | grep '\.rb$' || test $? = 1;) + printf "🎴 Changed ruby files: \n$files" + echo "CHANGED_FILES=$(echo ${files} | xargs)" >> $GITHUB_ENV + - name: Set up Ruby 3 + if: env.CHANGED_FILES != '' uses: ruby/setup-ruby@v1 with: ruby-version: 3.1.4 - - name: Install gems # usual step to install the gems. + bundler-cache: true + + - name: Run RuboCop + if: env.CHANGED_FILES != '' run: | - bin/bundle config path vendor/bundle - bin/bundle config set without 'default doc job cable storage ujs test db' - bin/bundle install --jobs 4 --retry 3 - - name: Linter count - id: hello - uses: henrixapp/linter-less-or-equal-action@v1.19 - with: - name: Rubocop - command: bin/bundle exec rubocop app config lib spec - total_regexp: \d+ offenses detected - errors_regexp: \d+ offenses detected - warnings_regexp: \d+ offenses detected - compare_branch: mampf-next - mode: changed - include: .rb - eslint: - runs-on: ubuntu-latest - name: A job to check eslint linter errors - steps: - - uses: actions/checkout@v2 - - name: Linter count - id: hello - uses: henrixapp/linter-less-or-equal-action@v1.19 - with: - name: EsLint - command: npx eslint - total_regexp: \d+ problems - errors_regexp: \d+ errors - warnings_regexp: \d+ warnings - compare_branch: mampf-next - mode: changed - include: .js - coffee: - runs-on: ubuntu-latest - name: A job to check coffee linter errors - steps: - - uses: actions/checkout@v2 - - name: Linter count - id: hello - uses: henrixapp/linter-less-or-equal-action@v1.19 - with: - name: Coffee - command: npx coffeelint - total_regexp: \d+ errors - errors_regexp: \d+ errors - warnings_regexp: \d+ warnings - compare_branch: mampf-next - mode: changed - include: .coffee - # erblint: - # runs-on: ubuntu-latest - # name: A job to check erblint linter errors - # steps: - # - uses: actions/checkout@v2 - # - name: Set up Ruby 2.7 - # uses: ruby/setup-ruby@v1 - # with: - # ruby-version: 2.7 - # - name: Install gems # usual step to install the gems. - # run: | - # bin/bundle config path vendor/bundle - # bin/bundle config set without 'default doc job cable storage ujs test db' - # bin/bundle install --jobs 4 --retry 3 - # - name: Linter count - # id: hello - # uses: henrixapp/linter-less-or-equal-action@v1.1 - # with: - # name: Erblint - # command: bin/bundle exec erblint . - # total_regexp: \d+ error(s) - # errors_regexp: \d+ error(s) - # warnings_regexp: \d+ error(s) - # compare_branch: mampf-next + echo "🚨 Running RuboCop version: $(bundle info rubocop | head -1)" + bundle exec rubocop --format github --fail-level 'convention' --force-exclusion -- $CHANGED_FILES diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index ac0fb3280..000000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: Tests - -on: - push: - branches: - - main - - mampf-next - - production - - experimental - pull_request: - -jobs: - unit-test-job: - name: Execute unit tests & upload to Codecov - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Pull docker images - run: docker compose pull --ignore-buildable - working-directory: docker/run_cypress_tests - - - name: Use Docker layer caching # https://github.com/jpribyl/action-docker-layer-caching - uses: jpribyl/action-docker-layer-caching@v0.1.1 - continue-on-error: true - - - name: Build docker containers - run: docker compose build - working-directory: docker/run_cypress_tests - - name: Create and migrate DB - run: docker compose run --entrypoint "" mampf sh -c "rake db:create db:migrate db:test:prepare" - working-directory: docker/run_cypress_tests - - name: Reindex sunspot - working-directory: docker/run_cypress_tests - run: | - docker compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rake sunspot:reindex" - - - name: Run unit tests - working-directory: docker/run_cypress_tests - run: docker compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rails spec" - - name: Send test coverage report to Codecov - uses: codecov/codecov-action@v3 - with: - files: ./coverage/coverage.xml - fail_ci_if_error: true - verbose: true - e2e-test-job: - name: Run E2E tests & upload results to Cypress - runs-on: ubuntu-latest - timeout-minutes: 30 - needs: unit-test-job - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Pull docker images - run: docker compose pull --ignore-buildable - working-directory: docker/run_cypress_tests - - - name: Use Docker layer caching # https://github.com/jpribyl/action-docker-layer-caching - uses: jpribyl/action-docker-layer-caching@v0.1.1 - continue-on-error: true - - - name: Build docker containers - run: docker compose build - working-directory: docker/run_cypress_tests - - name: Create and migrate DB - run: docker compose run --entrypoint "" mampf sh -c "rake db:create db:migrate db:test:prepare" - working-directory: docker/run_cypress_tests - - name: Run integration tests - working-directory: docker/run_cypress_tests - env: - # pass the Dashboard record key as an environment variable - CYPRESS_baseUrl: http://mampf:3000 - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - # pass GitHub token to allow accurately detecting a build vs a re-run build - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: docker compose run -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} --entrypoint="" cypress_runner sh -c "while ! curl http://mampf:3000 ; do echo waiting for MaMpf to come online at http://mampf:3000; sleep 3; done; cypress run --record --key ${{ secrets.CYPRESS_RECORD_KEY }}" -