From 6ee5d8e0754fb4febe1acdf7c8f5ea34db0109d4 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Thu, 19 Dec 2024 11:35:03 -0800 Subject: [PATCH] Consolidate formatting check and fix script to one Summary: To reduce discrepandcies of ruff format checking and fixing, we want to use the same script to do both The script can be used in both CI and locally. ``` sh scripts/run_ruff.sh sh scripts/run_ruff.sh --fix sh scripts/run_ruff.sh --check ``` Test Plan: 1. fix sh scripts/run_ruff.sh sh scripts/run_ruff.sh --fix All checks passed! All checks passed! All checks passed! 142 files left unchanged 2. check sh scripts/run_ruff.sh --check All checks passed! All checks passed! All checks passed! 142 files already formatted 3. unknown sh scripts/run_ruff.sh --unknown Usage: scripts/run_ruff.sh [options] Options: --fix Fix format (default) --check Check for formatting issues Reviewers: Subscribers: Tasks: Tags: --- .github/workflows/ruff_linter.yml | 13 ++----------- scripts/run_ruff_fix.sh | 6 ------ 2 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 scripts/run_ruff_fix.sh diff --git a/.github/workflows/ruff_linter.yml b/.github/workflows/ruff_linter.yml index 027279721..6041e5b1f 100644 --- a/.github/workflows/ruff_linter.yml +++ b/.github/workflows/ruff_linter.yml @@ -65,15 +65,7 @@ jobs: - name: Regular lint check if: github.event_name != 'workflow_dispatch' run: | - ruff check . - # --isolated is used to skip the allowlist at all so this applies to all files - # please be careful when using this large changes means everyone needs to rebase - ruff check --isolated --select F821,F823,W191 - ruff check --select F,I - ruff format --check || { - echo "Ruff check failed, please try again after running 'ruff format'." - exit 1 - } + sh scripts/run_ruff.sh --check - name: Apply fixes to PR if: github.event_name == 'workflow_dispatch' @@ -82,8 +74,7 @@ jobs: git config --global user.email 'github-actions[bot]@users.noreply.github.com' # Apply fixes - ruff check --select F,I --fix - ruff format . + sh scripts/run_ruff.sh # Commit and push if there are changes if [[ -n "$(git status --porcelain)" ]]; then diff --git a/scripts/run_ruff_fix.sh b/scripts/run_ruff_fix.sh deleted file mode 100644 index 9a016c2a5..000000000 --- a/scripts/run_ruff_fix.sh +++ /dev/null @@ -1,6 +0,0 @@ -ruff check . --fix -# --isolated is used to skip the allowlist at all so this applies to all files -# please be careful when using this large changes means everyone needs to rebase -ruff check --isolated --select F821,F823,W191 --fix -ruff check --select F,I --fix -ruff format .