mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-27 23:50:19 -05:00
Switch from black to ruff for Python code linting and formatting. Ruff provides both linting (ruff check) and formatting (ruff format) in a single fast tool.
42 lines
1.5 KiB
YAML
42 lines
1.5 KiB
YAML
name: Python Linting
|
|
|
|
on: [push, pull_request]
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
- uses: actions/setup-python@v6
|
|
with:
|
|
python-version: '3.10'
|
|
|
|
# Fork PRs: Check linting and formatting, fail with diff if issues exist
|
|
# (Cannot create fix PR because we don't have write access to fork branches)
|
|
- name: (Python) Check with ruff (fork PRs)
|
|
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
|
|
run: |
|
|
pip install ruff
|
|
cd GrpcInterface
|
|
ruff check --diff .
|
|
ruff format --check --diff .
|
|
|
|
# Same-repo PRs and pushes: Apply fixes and create PR if needed
|
|
- name: (Python) Lint and format with ruff
|
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
|
run: |
|
|
pip install ruff
|
|
cd GrpcInterface
|
|
ruff check --fix .
|
|
ruff format .
|
|
- 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 ruff"
|
|
title: "Fixes by ruff (Python)"
|
|
branch: python-ruff-patches
|
|
branch-suffix: random
|
|
base: ${{ github.head_ref }}
|
|
|