Skip to content

Commit b691904

Browse files
Jacksunweicopybara-github
authored andcommitted
chore: Adds a github action to check pyformat via pyink.
PiperOrigin-RevId: 753246116
1 parent 641781b commit b691904

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

.github/workflows/pyink.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Check Pyink Formatting
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'src/**/*.py'
7+
- 'tests/**/*.py'
8+
- 'pyproject.toml'
9+
10+
jobs:
11+
pyink-check:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Install pyink
24+
run: |
25+
pip install pyink
26+
27+
- name: Detect changed Python files
28+
id: detect_changes
29+
run: |
30+
git fetch origin ${{ github.base_ref }}
31+
CHANGED_FILES=$(git diff --diff-filter=ACMR --name-only origin/${{ github.base_ref }}...HEAD | grep -E '\.py$' || true)
32+
echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV
33+
34+
- name: Run pyink on changed files
35+
if: env.CHANGED_FILES != ''
36+
run: |
37+
echo "Changed Python files:"
38+
echo "$CHANGED_FILES"
39+
40+
# Run pyink --check
41+
set +e
42+
pyink --check --config pyproject.toml $CHANGED_FILES
43+
RESULT=$?
44+
set -e
45+
46+
if [ $RESULT -ne 0 ]; then
47+
echo ""
48+
echo "❌ Pyink formatting check failed!"
49+
echo "👉 To fix formatting, run locally:"
50+
echo ""
51+
echo " pyink --config pyproject.toml $CHANGED_FILES"
52+
echo ""
53+
exit $RESULT
54+
fi
55+
56+
- name: No changed Python files detected
57+
if: env.CHANGED_FILES == ''
58+
run: |
59+
echo "No Python files changed. Skipping pyink check."

0 commit comments

Comments
 (0)