Skip to content

Commit 0af72dc

Browse files
authored
Merge pull request #420 from kurtmckee/make-ci-more-resilient
Make CI more resilient
2 parents 7e61505 + 7b3e928 commit 0af72dc

File tree

3 files changed

+174
-120
lines changed

3 files changed

+174
-120
lines changed

.github/workflows/feedparser.yml

Lines changed: 0 additions & 120 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: "🔬 Test"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "develop"
8+
- "master"
9+
- "main"
10+
- "releases"
11+
12+
jobs:
13+
test:
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
# macOS and Windows tests target only the upper and lower CPython versions.
18+
interpreter:
19+
- "CPython"
20+
os:
21+
- name: "macOS"
22+
runner: "macos-latest"
23+
- name: "Windows"
24+
interpreters: "CPython"
25+
runner: "windows-latest"
26+
cpythons:
27+
# The goal is to ensure that each individual runner
28+
# is paired with all Python versions simultaneously.
29+
# This nested-list syntax accomplishes that goal.
30+
- - "3.8"
31+
- "3.12"
32+
# These last two keys are placeholders to ensure consistency in matrix values.
33+
cpython-beta:
34+
- ""
35+
pypys:
36+
- []
37+
38+
# The Linux runner tests all CPython and PyPy versions.
39+
# To reduce clock time, CPython and PyPy are tested separately.
40+
include:
41+
# CPython
42+
- interpreter: "CPython"
43+
os:
44+
name: "Linux (CPython)"
45+
runner: "ubuntu-latest"
46+
cpythons:
47+
- "3.8"
48+
- "3.9"
49+
- "3.10"
50+
- "3.11"
51+
- "3.12"
52+
cpython-beta: "3.13"
53+
pypys: []
54+
# PyPy
55+
- interpreter: "PyPy"
56+
os:
57+
name: "Linux (PyPy)"
58+
runner: "ubuntu-latest"
59+
cpythons: []
60+
cpython-beta: ""
61+
pypys:
62+
- "3.8"
63+
- "3.9"
64+
- "3.10"
65+
# NOTE: Tox only offers "best effort" support for PyPy.
66+
# To prevent installing tox on a PyPy interpreter,
67+
# a CPython version must be added to the end of the PyPy list.
68+
tox-python: "3.12"
69+
70+
name: "${{ matrix.os.name }}"
71+
runs-on: "${{ matrix.os.runner }}"
72+
73+
steps:
74+
- name: "Checkout the repo"
75+
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1
76+
77+
- name: "Setup Python"
78+
id: "setup-python"
79+
uses: "actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236" # v4.7.1
80+
with:
81+
python-version: "${{
82+
matrix.interpreter == 'PyPy'
83+
&& format('pypy-{0}\n{1}', join(matrix.pypys, '\npypy-'), matrix.tox-python)
84+
|| format('{0}\n{1}', matrix.cpython-beta, join(matrix.cpythons, '\n'))
85+
}}"
86+
allow-prereleases: true
87+
88+
- name: "Detect Pythons"
89+
uses: "kurtmckee/detect-pythons@cd2193638306e04e41ac36f0f9290f18680138ac" # v1.0.0
90+
91+
- name: "Restore cache"
92+
id: "restore-cache"
93+
uses: "actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84" # v3.3.2
94+
with:
95+
# The cache key includes the following to ensure it busts correctly:
96+
#
97+
# * All Python versions (detected by kurtmckee/detect-pythons, above)
98+
# This ensures that .venv/ symlinks to Python interpreters work.
99+
# * The tox configuration (tox.ini)
100+
# * The pytest configuration (pyproject.toml)
101+
#
102+
key: "test-os=${{ runner.os }}-interpreter=${{ matrix.interpreter }}-hash=${{ hashFiles('.python-identifiers', 'tox.ini', 'pyproject.toml') }}"
103+
path: |
104+
.tox/
105+
.venv/
106+
107+
- name: "Determine venv path"
108+
shell: "bash"
109+
run: "echo 'venv-path=.venv/${{ runner.os == 'Windows' && 'Scripts' || 'bin' }}' >> $GITHUB_ENV"
110+
111+
- name: "Create virtual environment"
112+
if: "steps.restore-cache.outputs.cache-hit == false"
113+
run: |
114+
python -m venv .venv
115+
${{ env.venv-path }}/python -m pip install --upgrade pip setuptools wheel
116+
${{ env.venv-path }}/python -m pip install tox
117+
118+
- name: "Run tests (CPython interpreters)"
119+
if: "matrix.interpreter == 'CPython'"
120+
run: "${{ env.venv-path }}/tox run -e py${{ join(matrix.cpythons, '-chardet,py') }}-chardet${{ matrix.cpython-beta != '' && format(',py{0}-chardet', matrix.cpython-beta) || '' }}"
121+
122+
- name: "Run tests (PyPy interpreters)"
123+
if: "matrix.interpreter == 'PyPy'"
124+
run: "${{ env.venv-path }}/tox run -e pypy${{ join(matrix.pypys, '-chardet,pypy') }}-chardet"
125+
126+
lint:
127+
name: "Lint"
128+
runs-on: "ubuntu-latest"
129+
130+
steps:
131+
- name: "Checkout the repo"
132+
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1
133+
134+
- name: "Setup Python"
135+
id: "setup-python"
136+
uses: "actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236" # v4.7.1
137+
with:
138+
python-version: "3.12"
139+
140+
- name: "Detect Pythons"
141+
uses: "kurtmckee/detect-pythons@cd2193638306e04e41ac36f0f9290f18680138ac" # v1.0.0
142+
143+
- name: "Restore cache"
144+
id: "restore-cache"
145+
uses: "actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84" # v3.3.2
146+
with:
147+
# The cache key includes the following to ensure it busts correctly:
148+
#
149+
# * All Python versions (detected by kurtmckee/detect-pythons, above)
150+
# This ensures that .venv/ symlinks to Python interpreters work.
151+
# * The tox config (tox.ini)
152+
# * The mypy config (pyproject.toml)
153+
# * The Sphinx config (docs/conf.py)
154+
# * The exact dependencies used during testing (requirements/*.txt)
155+
#
156+
key: "lint-hash=${{ hashFiles('.python-identifiers', 'tox.ini', 'pyproject.toml', 'docs/conf.py', 'requirements/*.txt') }}"
157+
path: |
158+
.mypy_cache/
159+
.tox/
160+
.venv/
161+
162+
- name: "Create virtual environment"
163+
if: "steps.restore-cache.outputs.cache-hit == false"
164+
run: |
165+
python -m venv .venv
166+
.venv/bin/python -m pip install --upgrade pip setuptools wheel
167+
.venv/bin/python -m pip install tox
168+
169+
- name: "Lint"
170+
run: ".venv/bin/tox run -e docs,mypy"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Project development
2+
-------------------
3+
4+
* Optimize CI for efficiency and speed.

0 commit comments

Comments
 (0)