Skip to content

Commit b657f57

Browse files
committed
feat: Add CI for linting, formatting, unit tests, and type checking
This also modifies the scripts used to run the linting and formatting tasks.
1 parent 911faf4 commit b657f57

File tree

4 files changed

+126
-136
lines changed

4 files changed

+126
-136
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Artifacts Helper Keyring Tests
2+
3+
on:
4+
push:
5+
paths:
6+
- ".github/workflows/test-keyring.yaml"
7+
- "src/artifacts-helper/codespaces_artifacts_helper_keyring/**.py"
8+
9+
pull_request:
10+
branches:
11+
- main
12+
paths:
13+
- ".github/workflows/test-keyring.yaml"
14+
- "src/artifacts-helper/codespaces_artifacts_helper_keyring/**.py"
15+
16+
defaults:
17+
run:
18+
working-directory: src/artifacts-helper/codespaces_artifacts_helper_keyring
19+
20+
jobs:
21+
generate-jobs:
22+
name: Generate jobs
23+
runs-on: ubuntu-latest
24+
outputs:
25+
session: ${{ steps.set-matrix.outputs.session }}
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- uses: wntrblm/nox@main
30+
with:
31+
python-versions: "3.12"
32+
33+
- id: set-matrix
34+
shell: bash
35+
run: echo session=$(nox --json -l --tags ci | jq -c '[.[].session]') | tee --append $GITHUB_OUTPUT
36+
37+
checks:
38+
name: Session ${{ matrix.session }}
39+
needs: [generate-jobs]
40+
runs-on: ubuntu-latest
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
session: ${{ fromJson(needs.generate-jobs.outputs.session) }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- uses: wntrblm/nox@main
49+
with:
50+
python-versions: "3.8, 3.9, 3.10, 3.11, 3.12, pypy-3.9, pypy-3.10"
51+
52+
- name: Setup PDM
53+
uses: pdm-project/setup-pdm@v4
54+
with:
55+
version: "2.15.1"
56+
python-version-file: "src/artifacts-helper/codespaces_artifacts_helper_keyring/pyproject.toml"
57+
58+
- name: Run ${{ matrix.session }}
59+
run: pdm run nox --error-on-missing-interpreters --error-on-external-run -s "${{ matrix.session }}"
Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,63 @@
11
import os
2+
from typing import List
23

34
import nox
45

56
os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1"})
67

7-
PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]
8-
LOCATIONS = "src", "tests", "noxfile.py"
8+
DEFAULT_PYTHON_VERSION = "3.11"
9+
PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12"]
910

10-
11-
@nox.session(py=PYTHON_VERSIONS)
12-
@nox.parametrize("keyring", ["20", "25.1"])
13-
def tests(session, keyring):
14-
session.run_always("pdm", "install", "-G", "test", external=True)
15-
session.install(f"keyring=={keyring}")
16-
session.run("pdm", "test", *session.posargs, external=True)
11+
DEFAULT_TEST_LOCATION = "tests"
12+
LOCATIONS = ["src", DEFAULT_TEST_LOCATION, "noxfile.py"]
1713

1814

19-
@nox.session
15+
@nox.session(py=DEFAULT_PYTHON_VERSION, tags=["ci"])
2016
def lint(session):
21-
session.run_always("pdm", "install", "-G", "lint", external=True)
22-
session.run("pdm", "check", external=True)
17+
"""Run the linter.
18+
19+
Returns a failure if the linter finds any issues.
20+
"""
21+
session.run_always("pdm", "install", "-dG", "lint", external=True)
22+
session.run("ruff", "check", *LOCATIONS, *session.posargs)
23+
24+
25+
@nox.session(py=DEFAULT_PYTHON_VERSION, tags=["ci"])
26+
def format_check(session):
27+
"""Run the formatter and fail if issues are found."""
28+
session.notify("format", posargs=["--check", *LOCATIONS])
29+
30+
31+
@nox.session(py=DEFAULT_PYTHON_VERSION)
32+
def format(session):
33+
"""Run the formatter and fix issues."""
34+
session.run_always("pdm", "install", "-dG", "lint", external=True)
35+
args = session.posargs or LOCATIONS
36+
session.run("ruff", "format", *args)
37+
38+
39+
@nox.session(tags=["ci"])
40+
@nox.parametrize(
41+
"python,keyring",
42+
[
43+
(python, keyring)
44+
for python in PYTHON_VERSIONS
45+
for keyring in ("20", "25.1")
46+
# exclude keyring 20 because it is incompatible with python 3.12
47+
if (python, keyring) != ("3.12", "20")
48+
],
49+
)
50+
def tests(session, keyring):
51+
"""Run the test suite."""
52+
session.run_always("pdm", "install", "-dG", "test", external=True)
53+
session.install(f"keyring=={keyring}")
54+
args = session.posargs or [DEFAULT_TEST_LOCATION]
55+
session.run("pytest", "-v", *args)
2356

2457

25-
@nox.session(py=PYTHON_VERSIONS)
58+
@nox.session(py=PYTHON_VERSIONS, tags=["ci"])
2659
def mypy(session):
60+
"""Run the type checker."""
2761
session.run_always("pdm", "install", external=True)
2862
args = session.posargs or LOCATIONS
29-
session.run("pdm", "run", "mypy", *args, external=True)
63+
session.run("mypy", *args)

src/artifacts-helper/codespaces_artifacts_helper_keyring/pdm.lock

Lines changed: 5 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/artifacts-helper/codespaces_artifacts_helper_keyring/pyproject.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,25 @@ version = {attr = "codespaces_artifacts_helper_keyring.__version__"}
3939
distribution = true
4040

4141
[tool.pdm.dev-dependencies]
42-
lint = ["mypy>=1.9.0", "ruff>=0.4.0", "pre-commit>=3.5.0"]
42+
lint = [
43+
"mypy>=1.9.0",
44+
"ruff>=0.4.0",
45+
]
4346
dev = ["pip>=24.0", "nox>=2024.4.15"]
4447
test = ["pytest>=8.1.1", "pytest-cov>=5.0.0"]
4548
stubs = ["types-requests>=2.31.0.20240406"]
4649

4750
[tool.pdm.scripts]
48-
check = "ruff check ."
49-
fmt = "ruff format ."
50-
test = "pytest -v tests"
51+
lint-fix = "pdm lint --fix"
52+
lint = "nox --error-on-external-run -R -s lint -- {args}"
53+
54+
format-check = "pdm format --check"
55+
format = "nox --error-on-external-run -R -s format -- {args}"
56+
57+
mypy = "nox --error-on-external-run -R -s mypy -- {args}"
58+
tests = "nox --error-on-external-run -R -s tests -- {args}"
59+
60+
release = "nox --error-on-external-run -R -s release"
5161

5262
[tool.ruff]
5363
line-length = 88

0 commit comments

Comments
 (0)