Skip to content

Commit

Permalink
feat(ruff): option to skip version file, and cwd. Partial monorepo su…
Browse files Browse the repository at this point in the history
…pport
  • Loading branch information
kiyoon committed Dec 13, 2024
1 parent 294bd94 commit 5c568db
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
File renamed without changes.
17 changes: 15 additions & 2 deletions .github/workflows/apply-ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ on:
type: string
ruff-version-file:
description: The requirements.txt file that contains the Ruff version (ruff==x.x.x)
required: true
required: false
type: string
cwd:
description: 'The directory to run ruff in'
required: false
type: string

jobs:
Expand All @@ -24,10 +28,19 @@ jobs:
- uses: actions/checkout@v4
- name: Install ruff
run: |
pip3 install -r <(grep '^ruff==' "${{ inputs.ruff-version-file }}") --break-system-packages
if [[ -z "${{ inputs.ruff-version-file }}" ]]; then
pip3 install ruff --break-system-packages
else
pip3 install -r <(grep '^ruff==' "${{ inputs.ruff-version-file }}") --break-system-packages
fi
- name: Run ruff and push
run: |
set +e # Do not exit shell on app failure
if [[ -n "${{ inputs.cwd }}" ]]; then
cd "${{ inputs.cwd }}"
fi
ruff check --select=${{ inputs.ruff-select }} --ignore=${{ inputs.ruff-ignore }} --fix --unsafe-fixes .
ruff format .
git config user.name github-actions[bot]
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/check-ruff-only-changed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ on:
type: string
ruff-version-file:
description: The requirements.txt file that contains the Ruff version (ruff==x.x.x)
required: true
required: false
type: string
cwd:
description: 'The directory to run ruff in'
required: false
type: string

jobs:
Expand All @@ -34,12 +38,20 @@ jobs:
- name: Install ruff
if: steps.changed-python-files.outputs.any_changed == 'true'
run: |
pip3 install -r <(grep '^ruff==' ${{ inputs.ruff-version-file }}) --break-system-packages
if [[ -z "${{ inputs.ruff-version-file }}" ]]; then
pip3 install ruff --break-system-packages
else
pip3 install -r <(grep '^ruff==' ${{ inputs.ruff-version-file }}) --break-system-packages
fi
- name: Run ruff
if: steps.changed-python-files.outputs.any_changed == 'true'
run: |
set +e # Do not exit shell on app failure
if [[ -n "${{ inputs.cwd }}" ]]; then
cd ${{ inputs.cwd }}
fi
if [[ ${{ inputs.check-type }} == 'lint' ]]; then
nonzero_exit=0
for file in ${{ steps.changed-python-files.outputs.all_changed_files }}; do
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/check-ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ on:
type: string
ruff-version-file:
description: The requirements.txt file that contains the Ruff version (ruff==x.x.x)
required: true
required: false
type: string
additional-args:
description: 'Additional arguments to pass to ruff'
required: false
type: string
cwd:
description: 'The directory to run ruff in'
required: false
type: string

jobs:
ruff:
Expand All @@ -24,11 +28,19 @@ jobs:
- uses: actions/checkout@v4
- name: Install ruff and requirements
run: |
pip3 install -r <(grep '^ruff==' "${{ inputs.ruff-version-file }}") --break-system-packages
if [[ -z "${{ inputs.ruff-version-file }}" ]]; then
pip3 install ruff --upgrade --break-system-packages
else
pip3 install -r <(grep '^ruff==' "${{ inputs.ruff-version-file }}") --break-system-packages
fi
- name: Run ruff
run: |
set +e # Do not exit shell on ruff failure
if [[ -n "${{ inputs.cwd }}" ]]; then
cd "${{ inputs.cwd }}"
fi
# parse additional_args as an array
# https://stackoverflow.com/a/31485948/7445323
additional_args=( )
Expand Down

0 comments on commit 5c568db

Please sign in to comment.