diff --git a/.github/actions/changed_files/action.yml b/.github/actions/changed_files/action.yml index f2fc336b3..d491a2d23 100644 --- a/.github/actions/changed_files/action.yml +++ b/.github/actions/changed_files/action.yml @@ -19,10 +19,12 @@ runs: # https://docs.github.com/en/actions/creating-actions/creating-a-composite-action using: "composite" steps: - - name: "Checkout PR branch (with test merge-commit)" - uses: actions/checkout@v4 - with: - fetch-depth: 2 # to also fetch parent of PR + # This has to be done in the main workflow, not in the action, because + # otherwise this reusable action is not available in the workflow. + # - 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 @@ -37,6 +39,6 @@ runs: shell: bash id: get-changed-files run: | - files_pretty=$(git diff --name-only --diff-filter=ACMR -r HEAD^1...HEAD | grep '${{inputs.file-extensions}}' || test $? = 1;) + files_pretty=$(git diff --name-only --diff-filter=ACMR -r HEAD^1...HEAD | grep -e '${{inputs.file-extensions}}' || test $? = 1;) printf "🎴 Changed files: \n$files_pretty" - echo "files=$(echo ${files_pretty} | xargs)" >> $GITHUB_ENV + echo "files=$(echo ${files_pretty} | xargs)" >> $GITHUB_OUTPUT diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 5145bd761..a627376f4 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -21,29 +21,26 @@ jobs: 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 - + id: rb-changed + uses: ./.github/actions/changed_files/ + with: + file-extensions: \.rb$ + - name: Set up Ruby 3 - if: env.CHANGED_FILES != '' + if: ${{ steps.rb-changed.outputs.changed-files != ''}} uses: ruby/setup-ruby@v1 with: ruby-version: 3.1.4 bundler-cache: true - name: Run RuboCop - if: env.CHANGED_FILES != '' + if: ${{ steps.rb-changed.outputs.changed-files != ''}} run: | echo "🚨 Running RuboCop version: $(bundle info rubocop | head -1)" bundle exec rubocop --format github --fail-level 'convention' --force-exclusion -- $CHANGED_FILES - + eslint: name: ESLint (JS) runs-on: ubuntu-latest @@ -53,22 +50,28 @@ jobs: with: fetch-depth: 2 # to also fetch parent of PR - - name: Checkout code & get changed files + - name: Get changed files id: eslint-changed uses: ./.github/actions/changed_files/ with: file-extensions: \.js$|\.js.erb$ + - name: Trial and error + if: ${{ steps.eslint-changed.outputs.changed-files != ''}} + run: 'echo "Changed files: aa${{ steps.eslint-changed.outputs.changed-files }}bb"' + - name: Setup Node.js - if: ${{ steps.eslint-changed.outputs.changed-files }} != '' + if: ${{ steps.eslint-changed.outputs.changed-files != ''}} uses: actions/setup-node@v4 with: node-version: '20' # End of Life (EOL): April 2026 - name: Install dependencies - if: ${{ steps.eslint-changed.outputs.changed-files }} != '' + if: ${{ steps.eslint-changed.outputs.changed-files != ''}} run: yarn install - name: Run ESLint - if: ${{ steps.eslint-changed.outputs.changed-files }} != '' - run: yarn run eslint --ignore-path .gitignore --max-warnings 0 ${{ steps.eslint-changed.outputs.changed-files }} + if: ${{ steps.eslint-changed.outputs.changed-files != ''}} + run: | + echo "🚨 Running ESLint version: $(yarn run eslint --version)" + yarn run eslint --ignore-path .gitignore --max-warnings 0 ${{ steps.eslint-changed.outputs.changed-files }}