Skip to content

Commit

Permalink
Fix further stuff related to GitHub action
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Dec 6, 2023
1 parent df3fc53 commit 425a27e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
14 changes: 8 additions & 6 deletions .github/actions/changed_files/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
37 changes: 20 additions & 17 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}

0 comments on commit 425a27e

Please sign in to comment.