@@ -13,52 +13,66 @@ permissions:
1313jobs :
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