Skip to content

Commit 3115935

Browse files
committed
Added workflow to check per PR
1 parent 68fdae6 commit 3115935

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

.github/lint_pr.yml

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

0 commit comments

Comments
 (0)