Skip to content

Commit 1e5edbc

Browse files
EliahKaganclaude
andcommitted
ci: run tox weekly and on demand
The main CI does not use tox, so the tox configuration can break without anyone noticing. It has: `tox -e html` stopped working when 9e54de4 (gitpython-developers#2243) removed the `doc` extra, `tox -e misc` has run `ruff check` again since b7ce712 (gitpython-developers#2031) changed that hook's id, and the `base_python` fallbacks have not meant what they said since 62c024e (gitpython-developers#1693). New releases of tox and virtualenv can also change how the configuration behaves, as when tox 4.56.0 made missing interpreters fail. But running every tox environment is too slow for every push and pull request. Add a `tox` workflow that runs on a weekly schedule and through `workflow_dispatch`. Each job runs the tox environments for one Python version, from 3.8 to 3.15, on Ubuntu. 3.8 and 3.9 run on `ubuntu-24.04`, since `setup-python` has no builds of them for Ubuntu 26.04. The 3.12 job also runs `gix`, and the 3.13 job also runs `ruff`, `format`, `mypy`, `html`, and `misc`. The steps that prepare for the tests (Rust for GixPython source builds, current Git from the git-core PPA, `init-tests-after-clone.sh`, and the test Git identity and aliases) are the same as in `pythonpackage.yml`. tox and the plugin used below both need Python 3.11 or later, so `setup-python` also installs Python 3.13, and tox runs on that. tox is installed unpinned, so that the workflow tests the configuration with the tox and virtualenv that a contributor would get. The job has only `contents: read` and uses no secrets. For running tox on GitHub Actions, there are two tox plugins and one action: - `tox-gh`, from the `tox-dev` organization that maintains tox, selects the environments for the job's Python version from a mapping in the tox configuration, puts each environment's output in its own log group, and summarizes the results. - `tox-gh-actions`, an older plugin maintained outside `tox-dev`, does the same with more ways to select environments, and also supports tox 3. This project needs only selection by Python version. - `fedora-python/tox-github-action` runs tox in a Fedora container that has most Python versions, but no longer 3.8. It also pulls its image by a mutable tag, its repository has no license, and it runs tox as root in the container, which would change what GitPython's tests see about file ownership and `safe.directory`. Use `tox-gh`. Selecting environments by version is simple here, but the log groups make long weekly logs easier to read, and it adds little risk, since it comes from the `tox-dev` organization, like tox itself. Its mapping goes in `[tool.tox.gh.python]` in `pyproject.toml`. `tox-gh` does nothing outside GitHub Actions, and without it, `tox config` only adds a note that `gh` is unused. The job sets `TOX_GH_MAJOR_MINOR` to the matrix version, as `tox-gh` documents for when tox runs on a different Python. `actionlint`, `zizmor` 1.31.1 (pedantic, with online audits), and `pinact run --check --verify-comment` report nothing for the new workflow, and all pre-commit hooks pass. With `GITHUB_ACTIONS=true` set locally, tox with `tox-gh` ran only `py38` for `TOX_GH_MAJOR_MINOR=3.8`, in its own log group, and set up `py313`, `ruff`, `format`, `mypy`, `html`, and `misc` for 3.13. `workflow_dispatch` and `schedule` only work once the workflow is on the default branch, so it was run on a fork through a temporary `push` trigger, together with this branch's other changes. Every job passed except the 3.12 job's `gix` environment, whose installation test needs package downloads that `test/run-local.py` blocks. With a separate change that allows them, every job passed. The 3.12 job, which takes longest, took between 13 and 17 minutes. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent aa476c3 commit 1e5edbc

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

‎.github/workflows/tox.yml‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: tox
2+
3+
# The main CI does not use tox, so this checks that the tox configuration still
4+
# works, including with new releases of tox and virtualenv. That is too slow to
5+
# run on every push and pull request, so it runs weekly and on demand.
6+
on:
7+
schedule:
8+
- cron: "37 5 * * 1" # Mondays at 05:37 UTC.
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
tox:
16+
name: tox (${{ matrix.python-version }})
17+
18+
strategy:
19+
matrix:
20+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
21+
include:
22+
# setup-python has no builds of these versions for Ubuntu 26.04.
23+
- python-version: "3.8"
24+
os: ubuntu-24.04
25+
- python-version: "3.9"
26+
os: ubuntu-24.04
27+
28+
fail-fast: false
29+
30+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
31+
32+
defaults:
33+
run:
34+
shell: bash --noprofile --norc -exo pipefail {0}
35+
36+
steps:
37+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38+
with:
39+
fetch-depth: 0
40+
persist-credentials: false
41+
42+
- name: Set up Python ${{ matrix.python-version }}, and Python 3.13 for tox
43+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
44+
with:
45+
# Current tox does not run on some of the versions it tests, so it gets
46+
# its own interpreter. The last version listed becomes the default.
47+
python-version: |
48+
3.13
49+
${{ matrix.python-version }}
50+
allow-prereleases: true
51+
52+
- name: Prepare Rust for GixPython source builds
53+
run: |
54+
# GixPython 0.3.0 publishes macOS wheels only and needs Rust >= 1.89.
55+
rustup toolchain install stable --profile minimal
56+
rustup default stable
57+
rustc --version
58+
59+
- name: Install current Git
60+
run: |
61+
sudo add-apt-repository --yes ppa:git-core/ppa
62+
sudo apt-get update
63+
sudo apt-get install --yes git
64+
65+
- name: Prepare this repo for tests
66+
run: |
67+
./init-tests-after-clone.sh
68+
69+
- name: Set git user identity and command aliases for the tests
70+
run: |
71+
git config --global user.email "travis@ci.com"
72+
git config --global user.name "Travis Runner"
73+
# If we rewrite the user's config by accident, we will mess it up
74+
# and cause subsequent tests to fail
75+
cat test/fixtures/.gitconfig >> ~/.gitconfig
76+
77+
- name: Install tox
78+
# Unpinned on purpose, to find out when a new tox breaks the configuration.
79+
run: |
80+
python3.13 -m pip install tox tox-gh
81+
82+
- name: Show version and platform information
83+
run: |
84+
uname -a
85+
git version
86+
python --version
87+
python3.13 -m tox --version
88+
89+
- name: Run tox
90+
run: |
91+
python3.13 -m tox
92+
env:
93+
# tox-gh selects the environments mapped to this version in `[tool.tox.gh.python]`.
94+
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }}

‎pyproject.toml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,15 @@ skip_install = true
262262
deps = ["pre-commit"]
263263
set_env = { SKIP = "ruff-format,ruff-check" }
264264
commands = [["pre-commit", "run", "--all-files"]]
265+
266+
# Environments that the `tox` workflow runs for each Python version, via tox-gh.
267+
# tox-gh does nothing outside GitHub Actions.
268+
[tool.tox.gh.python]
269+
"3.8" = ["py38"]
270+
"3.9" = ["py39"]
271+
"3.10" = ["py310"]
272+
"3.11" = ["py311"]
273+
"3.12" = ["py312", "gix"]
274+
"3.13" = ["py313", "ruff", "format", "mypy", "html", "misc"]
275+
"3.14" = ["py314"]
276+
"3.15" = ["py315"]

0 commit comments

Comments
 (0)