-
Notifications
You must be signed in to change notification settings - Fork 7k
69 lines (60 loc) · 2.67 KB
/
lint_pr.yml
File metadata and controls
69 lines (60 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: lint_python
on: [pull_request, push]
jobs:
lint_python:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # To get all history for git diff commands
- uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Get changed Python files
id: changed-files
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# For PRs, compare against base branch
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT origin/${{ github.base_ref }} HEAD | grep '\.py$' || echo "")
else
# For pushes, use the before/after SHAs
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.before }} ${{ github.event.after }} | grep '\.py$' || echo "")
fi
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "Changed Python files: $CHANGED_FILES"
- name: Lint with flake8
if: ${{ steps.changed-files.outputs.files != '' }}
run: |
echo "Linting files: ${{ steps.changed-files.outputs.files }}"
flake8 ${{ steps.changed-files.outputs.files }} --count --show-source --statistics
continue-on-error: true
- name: Format check with isort and black
if: ${{ steps.changed-files.outputs.files != '' }}
run: |
echo "Checking format with isort for: ${{ steps.changed-files.outputs.files }}"
isort --profile black --check ${{ steps.changed-files.outputs.files }}
echo "Checking format with black for: ${{ steps.changed-files.outputs.files }}"
black --check ${{ steps.changed-files.outputs.files }}
continue-on-error: true
- name: Type check with mypy
if: ${{ steps.changed-files.outputs.files != '' }}
run: |
echo "Type checking: ${{ steps.changed-files.outputs.files }}"
mypy --ignore-missing-imports ${{ steps.changed-files.outputs.files }}
continue-on-error: true
- name: Run tests with pytest
run: |
pytest ./patterns
pytest --doctest-modules ./patterns || true
continue-on-error: true
- name: Check Python version compatibility
if: ${{ steps.changed-files.outputs.files != '' }}
run: pyupgrade --py312-plus ${{ steps.changed-files.outputs.files }}
continue-on-error: true
- name: Run tox
run: tox
continue-on-error: true