Skip to content

ci: Introduce tox as a test runner #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 75 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,26 @@ on:
- main
tags:
- "*"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
name: test with ${{ matrix.env }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
env:
- "3.13"
- "3.12"
- "3.11"
os:
- ubuntu-latest
- macos-latest
# - windows-latest
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -24,22 +41,58 @@ jobs:
with:
version: latest
enable-cache: true
cache-dependency-glob: "uv.lock"
cache-dependency-glob: "pyproject.toml"
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Python
run: uv python install 3.12
- name: Add .local/bin to Windows PATH
if: runner.os == 'Windows'
shell: bash
run: echo "$USERPROFILE/.local/bin" >> $GITHUB_PATH

- name: Sync Dependencies
run: uv sync --all-extras --dev
- name: Install tox
run: uv tool install --python-preference only-managed --python 3.13 tox
--with tox-uv # --with tox-gh

- name: Check code with Ruff
uses: chartboost/ruff-action@v1
- name: Setup Python
if: matrix.env != '3.13'
run:
uv python install --python-preference only-managed ${{ matrix.env }}

- name: Run Tests
run: uv run pytest --cov --cov-report=xml:coverage.xml
--junit-xml=junit.xml
- name: Setup Tests
run: tox run -vv --notest --skip-missing-interpreters false
env:
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}

- name: Run test suite
run: tox run --skip-pkg-install
env:
AOC_SESSION: ${{ secrets.AOC_SESSION }}
TOX_GH_MAJOR_MINOR: ${{ matrix.env }}

- name: Rename reports
run: >-
mv junit.xml "junit-${{ matrix.os }}-${{ matrix.env }}.xml" ; mv
ruff.json "ruff-${{ matrix.os }}-${{ matrix.env }}.json" ; mv
coverage.xml "coverage-${{ matrix.os }}-${{ matrix.env }}.xml"

- name: Upload JUnit results
uses: actions/upload-artifact@v4
with:
name: junit-${{ matrix.os }}-${{ matrix.env }}
path: |
coverage*.xml
junit-*.xml
ruff-*.json
retention-days: 1

sonar:
needs: test
concurrency: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Obtain Project Version
uses: SebRollen/[email protected]
Expand All @@ -55,6 +108,14 @@ jobs:
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Download JUnit reports
uses: actions/download-artifact@v4
with:
path: .
merge-multiple: true
env:
PARALLEL_DOWNLOADS: 1

- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@master
env:
Expand All @@ -68,15 +129,16 @@ jobs:
uses: pmeier/[email protected]
if: always()
with:
path: "junit.xml"
path: "junit-*.xml"

release:
needs: test
concurrency: release
permissions:
id-token: write
contents: write
if: github.event_name == 'push' && github.ref == 'refs/heads/main' &&
if:
github.event_name == 'push' && github.ref == 'refs/heads/main' &&
!contains(github.event.head_commit.message, 'chore(release):')
runs-on: ubuntu-latest
outputs:
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ repos:
rev: v1.3.0
hooks:
- id: commitlint
- repo: https://github.com/pypa/pip-audit
rev: v2.8.0
hooks:
- id: pip-audit
args:
- .
# - repo: https://github.com/pypa/pip-audit
# rev: v2.8.0
# hooks:
# - id: pip-audit
# args:
# - .

ci:
# Leave pip-audit to only run locally and not in CI
Expand Down
164 changes: 109 additions & 55 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@
description = "darac's solutions for http://adventofcode.com"
name = "aoc"
readme = "README.md"
requires-python = "<3.13,>=3.10"
version = "2024.4.2"
# It's common to not specify an upper band,
# But some of the dependencies are slow to update,
# So, we limit here until they update.
requires-python = "<3.14,>=3.11"
version = "2024.4.2"

[project.entry-points."adventofcode.user"]
darac_aoc = "aoc:solve"

[project.optional-dependencies]
test = [
"pytest-cov>=6.0.0",
"pytest-gh-log-group>=0.2.0",
"pytest-randomly>=3.16.0",
"pytest-xdist>=3.6.1",
]

[tool.black]
line-length = 76
target-version = ["py311"]
Expand Down Expand Up @@ -70,7 +81,7 @@
venv = "/home/vscode/.venv"

[tool.pytest.ini_options]
# addopts = "--cov --cov-report=term --cov-report=xml:coverage.xml --junitxml=junit.xml -n 4"
addopts = "--cov --cov-report=xml:coverage.xml --junitxml=junit.xml"
junit_suite_name = "aoc"

[tool.ruff]
Expand Down Expand Up @@ -108,74 +119,117 @@
prerelease = false
prerelease_token = "rc"

[tool.semantic_release.changelog]

[tool.semantic_release.changelog.default_templates]
changelog_file = "CHANGELOG.md"
exclude_commit_patterns = []
template_dir = "templates"

[tool.semantic_release.changelog.environment]
autoescape = true
block_end_string = "%}"
block_start_string = "{%"
comment_end_string = "#}"
comment_start_string = "{#"
extensions = []
keep_trailing_newline = false
lstrip_blocks = false
newline_sequence = "\n"
trim_blocks = false
variable_end_string = "}}"
variable_start_string = "{{"

[tool.semantic_release.commit_author]
default = "semantic-release <semantic-release>"
env = "GIT_COMMIT_AUTHOR"

[tool.semantic_release.commit_parser_options]
allowed_tags = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"style",
"test",
]
default_bump_level = 0
minor_tags = ["feat"]
patch_tags = ["fix", "perf"]

[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = true

[tool.semantic_release.remote]
ignore_token_for_push = false
insecure = false
name = "origin"
type = "github"
[tool.semantic_release.changelog]

[tool.semantic_release.changelog.default_templates]
changelog_file = "CHANGELOG.md"
exclude_commit_patterns = []
template_dir = "templates"

[tool.semantic_release.changelog.environment]
autoescape = true
block_end_string = "%}"
block_start_string = "{%"
comment_end_string = "#}"
comment_start_string = "{#"
extensions = []
keep_trailing_newline = false
lstrip_blocks = false
newline_sequence = "\n"
trim_blocks = false
variable_end_string = "}}"
variable_start_string = "{{"

[tool.semantic_release.commit_author]
default = "semantic-release <semantic-release>"
env = "GIT_COMMIT_AUTHOR"

[tool.semantic_release.commit_parser_options]
allowed_tags = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"style",
"test",
]
default_bump_level = 0
minor_tags = ["feat"]
patch_tags = ["fix", "perf"]

[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = true

[tool.semantic_release.remote]
ignore_token_for_push = false
insecure = false
name = "origin"
type = "github"

[tool.sonar]
coverage.exclusions = "aoc/visualisations/**,**/__init__.py"
links.homepage = "https://github.com/darac/adventofcode/"
organization = "darac"
projectKey = "darac_adventofcode"
python.coverage.reportPaths = "*coverage*.xml"
python.ruff.reportPaths = "ruff*.json"
python.version = "3.12"
python.xunit.reportPath = "junit.xml"
python.xunit.reportPath = "junit*.xml"
python.xunit.skipDetails = true
sources = "aoc/"
tests = "tests/"

[tool.tox]
env_list = ["3.11", "3.12", "3.13", "ruff", "type"]
requires = ["tox>=4.19"]

[tool.tox.env_run_base]
commands = [["uv", "run", "pytest", "-q"]]
description = "Run test under {base_python}"
extras = ["test"]
runner = "uv-venv-lock-runner"

[tool.tox.env.ruff]
commands = [
[
"uv",
"run",
"ruff",
"check",
"aoc",
"--output-format",
"json",
"--output-file",
"ruff.json",
],
]
description = "Run ruff checking"
extras = ["test"]
runner = "uv-venv-lock-runner"

[tool.tox.env.type]
commands = [["uv", "run", "mypy", "tests"], ["uv", "run", "mypy", "aoc"]]
deps = ["mypy==1.11.2", "types-cachetools>=5.5.0.20240820", "types-chardet>=5.0.4.6"]
description = "Run type check on code base"
extras = ["test"]
runner = "uv-venv-lock-runner"

[tool.tox.gh.python]
"3.10" = ["3.10"]
"3.11" = ["3.11"]
"3.12" = ["3.12", "ruff", "type"]
"3.13" = ["3.13", "ruff", "type"]


[tool.uv]
dev-dependencies = [
"deptry>=0.19.0",
"mypy>=1.15.0",
"pre-commit>=3.8.0",
"pytest-cov>=5.0.0",
"pytest-gh-log-group>=0.2.0",
Expand Down
3 changes: 2 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ sonar.links.homepage=https://github.com/darac/adventofcode/
sonar.organization=darac
sonar.projectKey=darac_adventofcode
sonar.python.coverage.reportPaths=*coverage*.xml
sonar.python.ruff.reportPaths=ruff*.json
sonar.python.version=3.12
sonar.python.xunit.reportPath=junit.xml
sonar.python.xunit.reportPath=junit*.xml
sonar.python.xunit.skipDetails=true
sonar.sources=aoc/
sonar.tests=tests/
Expand Down
Loading
Loading