8000 chore: fix Pyink GitHub Action to check on all changed .py files · dev573/adk-python@ed2aef9 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed2aef9

Browse files
wuliang229copybara-github
authored andcommitted
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
1 parent 934af25 commit ed2aef9

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

.github/workflows/pyink.yml

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ name: Check Pyink Formatting
1717
on:
1818
pull_request:
1919
paths:
20-
- 'src/**/*.py'
21-
- 'tests/**/*.py'
20+
- '**.py'
2221
- 'pyproject.toml'
2322

2423
jobs:
@@ -28,6 +27,8 @@ jobs:
2827
steps:
2928
- name: Checkout code
3029
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 2
3132

3233
- name: Set up Python
3334
uses: actions/setup-python@v5
@@ -38,36 +39,31 @@ jobs:
3839
run: |
3940
pip install pyink
4041
41-
- name: Detect changed Python files
42-
id: detect_changes
42+
- name: Run pyink on changed files
43+
id: run_pyink
4344
run: |
4445
git fetch origin ${{ github.base_ref }}
4546
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.py$' || true)
46-
echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV
47-
48-
- name: Run pyink on changed files
49-
if: env.CHANGED_FILES != ''
50-
run: |
51-
echo "Changed Python files:"
52-
echo "$CHANGED_FILES"
53-
54-
# Run pyink --check
55-
set +e
56-
pyink --check --config pyproject.toml $CHANGED_FILES
57-
RESULT=$?
58-
set -e
59-
60-
if [ $RESULT -ne 0 ]; then
61-
echo ""
62-
echo "❌ Pyink formatting check failed!"
63-
echo "👉 To fix formatting, run locally:"
64-
echo ""
65-
echo " pyink --config pyproject.toml $CHANGED_FILES"
47+
if [ -n "$CHANGED_FILES" ]; then
48+
echo "Changed Python files:"
49+
echo "$CHANGED_FILES"
6650
echo ""
67-
exit $RESULT
68-
fi
51+
FORMATTED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ')
6952
70-
- name: No changed Python files detected
71-
if: env.CHANGED_FILES == ''
72-
run: |
73-
echo "No Python files changed. Skipping pyink check."
53+
# Run pyink --check
54+
set +e
55+
pyink --check --diff --config pyproject.toml $CHANGED_FILES
56+
RESULT=$?
57+
set -e
58+
if [ $RESULT -ne 0 ]; then
59+
echo ""
60+
echo "❌ Pyink formatting check failed!"
61+
echo "👉 To fix formatting, run locally:"
62+
echo ""
63+
echo " pyink --config pyproject.toml $FORMATTED_FILES"
64+
echo ""
65+
exit $RESULT
66+
fi
67+
else
68+
echo "No Python files changed. Skipping pyink check."
69+
fi

0 commit comments

Comments
 (0)
0