From c53761bbbf66bedc626113593be821051eeda941 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 4 Feb 2026 15:43:04 +0100 Subject: [PATCH] Fix Python linting workflow for fork PRs The peter-evans/create-pull-request action fails for fork PRs because it tries to fetch a branch that only exists in the fork. Add conditional logic to handle fork PRs differently: - Fork PRs: Run black --check --diff and fail if formatting issues exist - Same-repo PRs and pushes: Keep existing behavior (run black, create fix PR) --- .github/workflows/python-linting.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-linting.yml b/.github/workflows/python-linting.yml index 5d36f510b9..0ed148bc88 100644 --- a/.github/workflows/python-linting.yml +++ b/.github/workflows/python-linting.yml @@ -9,13 +9,26 @@ jobs: - uses: actions/checkout@v6 - uses: actions/setup-python@v6 with: - python-version: '3.10' + python-version: '3.10' + + # Fork PRs: Check formatting and fail with diff if issues exist + # (Cannot create fix PR because we don't have write access to fork branches) + - name: (Python) Check formatting with black (fork PRs) + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository + run: | + pip install black + cd GrpcInterface + black --check --diff . + + # Same-repo PRs and pushes: Apply fixes and create PR if needed - name: (Python) Use black to do linting + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository run: | pip install black cd GrpcInterface black . - uses: peter-evans/create-pull-request@v8 + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository with: token: ${{ secrets.GITHUB_TOKEN }} commit-message: "Python code linting changes detected by black"