Skip to content

Commit bcd4b16

Browse files
Ruff Check for changed py files (#123)
* ruff-check.yml file updated * test of ruff-check * ruff-check-yaml updated * test * workflow error fixed * error fixed * final check * test for ruff-check on non py files * check for a py file * all pyhton files instead of just api-server and state-managerment * test check for all changed py files * will check for all py files * fixed init * heredoc syntac used for multipline output
1 parent 808a6a6 commit bcd4b16

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

.github/workflows/ruff-check.yml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,66 @@ permissions:
1313
jobs:
1414
ruff-changed-files:
1515
runs-on: ubuntu-latest
16-
16+
1717
steps:
1818
# 1. Checkout entire history for accurate diffs
1919
- name: Checkout code
2020
uses: actions/checkout@v4
2121
with:
2222
fetch-depth: 0
23-
23+
2424
# 2. Set up Python for Ruff
2525
- name: Set up Python
2626
uses: actions/setup-python@v5
2727
with:
2828
python-version: '3.12'
29-
29+
3030
# 3. Determine changed Python files
3131
- name: Get changed Python files
3232
id: changed-files
3333
run: |
3434
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
3535
BASE_SHA=${{ github.event.pull_request.base.sha }}
36-
HEAD_SHA=${{ github.sha }}
36+
HEAD_SHA=${{ github.event.pull_request.head.sha }}
3737
else
3838
BASE_SHA=${{ github.event.before }}
39-
HEAD_SHA=${{ github.event.after }}
39+
HEAD_SHA=${{ github.sha }}
4040
fi
41-
42-
# List all changed .py files in target directories
41+
42+
echo "BASE_SHA: $BASE_SHA"
43+
echo "HEAD_SHA: $HEAD_SHA"
44+
45+
# List all changed .py files
4346
FILES=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA $HEAD_SHA \
4447
| grep -E '\.py$' || true)
45-
46-
echo "files=$FILES" >> "$GITHUB_OUTPUT"
47-
48+
49+
# Handle multi-line output properly for GitHub Actions
50+
if [ -n "$FILES" ]; then
51+
{
52+
echo 'files<<EOF'
53+
echo "$FILES"
54+
echo 'EOF'
55+
} >> "$GITHUB_OUTPUT"
56+
echo "has_files=true" >> "$GITHUB_OUTPUT"
57+
else
58+
echo "files=" >> "$GITHUB_OUTPUT"
59+
echo "has_files=false" >> "$GITHUB_OUTPUT"
60+
fi
4861
49-
50-
5162
# 4. Install and Run Ruff on changed files, if any
5263
- name: Run Ruff on changed files
53-
if: steps.changed-files.outputs.files != ''
64+
if: steps.changed-files.outputs.has_files == 'true'
5465
run: |
5566
pip install ruff
5667
echo "Linting the following Python files:"
5768
echo "${{ steps.changed-files.outputs.files }}"
58-
ruff check ${{ steps.changed-files.outputs.files }}
59-
69+
70+
# Convert multiline string to space-separated for ruff
71+
FILES_ARGS=$(echo "${{ steps.changed-files.outputs.files }}" | tr '\n' ' ')
72+
ruff check $FILES_ARGS
73+
6074
# 5. Skip Ruff when no relevant files changed
6175
- name: Skip Ruff if no files changed
62-
if: steps.changed-files.outputs.files == ''
76+
if: steps.changed-files.outputs.has_files == 'false'
6377
run: |
64-
echo "No Python files changed in api-server/ or state-manager/. Skipping Ruff."
78+
echo "No Python files changed. Skipping Ruff."

0 commit comments

Comments
 (0)