mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-01 08:38:00 -06:00
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)
This commit is contained in:
1 parent
0dfbcd34f6
commit
c53761bbbf
1 file changed
+14
-1
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user