From ed2aef9120089b274b97c94b3dbde1737c0a47ee Mon Sep 17 00:00:00 2001 From: Liang Wu Date: Tue, 3 Jun 2025 13:18:33 -0700 Subject: [PATCH] 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 --- .github/workflows/pyink.yml | 56 +++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/.github/workflows/pyink.yml b/.github/workflows/pyink.yml index c79ae4b..ef9e72e 100644 --- a/.github/workflows/pyink.yml +++ b/.github/workflows/pyink.yml @@ -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: | - echo "Changed Python files:" - echo "$CHANGED_FILES" - - # Run pyink --check - set +e - pyink --check --config pyproject.toml $CHANGED_FILES - RESULT=$? - set -e - - if [ $RESULT -ne 0 ]; then + if [ -n "$CHANGED_FILES" ]; then + echo "Changed Python files:" + echo "$CHANGED_FILES" echo "" - echo "❌ Pyink formatting check failed!" - echo "👉 To fix formatting, run locally:" - echo "" - echo " pyink --config pyproject.toml $CHANGED_FILES" - echo "" - exit $RESULT + FORMATTED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ') + + # Run pyink --check + set +e + 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 $FORMATTED_FILES" + echo "" + exit $RESULT + fi + else + echo "No Python files changed. Skipping pyink check." fi - - - name: No changed Python files detected - if: env.CHANGED_FILES == '' - run: | - echo "No Python files changed. Skipping pyink check."