Skip to content

Commit a26b798

Browse files
authored
test: add workflow to test PRs (#36)
1 parent 8657fd9 commit a26b798

2 files changed

Lines changed: 61 additions & 8 deletions

File tree

.github/workflows/presubmit.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Runs tests on pull requests for main
2+
permissions: read-all
3+
name: Presubmit
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
jobs:
9+
test:
10+
strategy:
11+
matrix:
12+
python-version: ["3.10", "3.11", "3.12", "3.13"]
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
cache: 'pip'
21+
22+
- name: Install nox
23+
run: pip install -e .[dev]
24+
25+
- name: Check formatting
26+
run: nox -s lint
27+
- name: Run tests
28+
run: nox -s tests-${{ matrix.python-version }}

noxfile.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,42 @@
3838
]
3939

4040

41+
def _format(session, check=False):
42+
"""Helper function to run formatters.
43+
44+
Args:
45+
session: The nox session object.
46+
check: If True, checks formatting and fails if any file requires
47+
formatting, but doesn't apply any changes. If False, applies formatting
48+
fixes.
49+
"""
50+
black_command = ["black"]
51+
if check:
52+
black_command.append("--check")
53+
54+
black_command.extend(
55+
[
56+
"-l",
57+
"80",
58+
"--exclude",
59+
r"/(v[0-9]+|\.eggs|\.git|_cache|\.nox|\.tox|\.venv|env|venv|\.svn|_build|buck-out|build|dist)/",
60+
".",
61+
]
62+
)
63+
64+
session.run(*black_command)
65+
66+
67+
@nox.session(venv_backend="none")
68+
def lint(session):
69+
"""Fails if the code is not formatted correctly."""
70+
_format(session, check=True)
71+
72+
4173
@nox.session(venv_backend="none")
4274
def format(session):
4375
"""Runs the black formatter and applies formatting fixes."""
44-
session.run(
45-
"black",
46-
"-l",
47-
"80",
48-
"--exclude",
49-
r"/(v[0-9]+|\.eggs|\.git|_cache|\.nox|\.tox|\.venv|env|venv|\.svn|_build|buck-out|build|dist)/",
50-
".",
51-
)
76+
_format(session)
5277

5378

5479
@nox.session(python=PYTHON_VERSIONS)

0 commit comments

Comments
 (0)