chore: fix Pyink GitHub Action to check on all changed .py files

Three fixes:
1. used "fetch-depth: 2" to ensure that files in all commits in the PR are checked
2. triggered by all changed ".py" files in the repo
3. merged the "check modified files" and "run Pyink" steps because $GITHUB_ENV cannot handle multi-line env vars without special treatment

PiperOrigin-RevId: 766793736
This commit is contained in:
Liang Wu 2025-06-03 13:18:33 -07:00 committed by Copybara-Service
parent 934af25343
commit ed2aef9120

View File

@ -17,8 +17,7 @@ name: Check Pyink Formatting
on:
pull_request:
paths:
- 'src/**/*.py'
- 'tests/**/*.py'
- '**.py'
- 'pyproject.toml'
jobs:
@ -28,6 +27,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set up Python
uses: actions/setup-python@v5
@ -38,36 +39,31 @@ jobs:
run: |
pip install pyink
- name: Detect changed Python files
id: detect_changes
- name: Run pyink on changed files
id: run_pyink
run: |
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.py$' || true)
echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV
- name: Run pyink on changed files
if: env.CHANGED_FILES != ''
run: |
if [ -n "$CHANGED_FILES" ]; then
echo "Changed Python files:"
echo "$CHANGED_FILES"
echo ""
FORMATTED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ')
# Run pyink --check
set +e
pyink --check --config pyproject.toml $CHANGED_FILES
pyink --check --diff --config pyproject.toml $CHANGED_FILES
RESULT=$?
set -e
if [ $RESULT -ne 0 ]; then
echo ""
echo "❌ Pyink formatting check failed!"
echo "👉 To fix formatting, run locally:"
echo ""
echo " pyink --config pyproject.toml $CHANGED_FILES"
echo " pyink --config pyproject.toml $FORMATTED_FILES"
echo ""
exit $RESULT
fi
- name: No changed Python files detected
if: env.CHANGED_FILES == ''
run: |
else
echo "No Python files changed. Skipping pyink check."
fi