Skip to content

Commit d66eb2d

Browse files
authored
Add optional run_pre and run_post commands to tox workflow (#226)
1 parent 4d47dff commit d66eb2d

File tree

2 files changed

+45
-59
lines changed

2 files changed

+45
-59
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,21 @@
11
---
2-
name: test
2+
name: tox
33
on:
44
pull_request:
55
jobs:
6-
pre:
7-
name: pre
8-
runs-on: ubuntu-24.04
9-
outputs:
10-
matrix: ${{ steps.generate_matrix.outputs.matrix }}
11-
steps:
12-
- name: Determine matrix
13-
id: generate_matrix
14-
uses: coactions/dynamic-matrix@v3
15-
with:
16-
min_python: "3.12"
17-
max_python: "3.12"
18-
default_python: "3.12"
19-
other_names: |
20-
lint
21-
docs
226
test:
23-
needs: pre
24-
name: ${{ matrix.name || matrix.tox_env }}
25-
runs-on: ${{ matrix.runs-on || 'ubuntu-latest' }}
26-
strategy:
27-
fail-fast: true
28-
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
29-
steps:
30-
- name: Check out src from Git
31-
uses: actions/checkout@v4
32-
with:
33-
fetch-depth: 0 # needed by setuptools-scm
34-
submodules: recursive
35-
36-
- name: Install a default Python
37-
uses: actions/setup-python@v5
38-
with:
39-
python-version: ${{ matrix.python_version }}
40-
41-
- name: Install dependencies
42-
run: |
43-
python3 -m pip install 'tox>=4.0.0'
44-
45-
- run: ${{ matrix.command }}
46-
47-
- run: ${{ matrix.command2 }}
48-
if: ${{ matrix.command2 }}
49-
50-
- run: ${{ matrix.command3 }}
51-
if: ${{ matrix.command3 }}
52-
53-
- run: ${{ matrix.command4 }}
54-
if: ${{ matrix.command4 }}
55-
56-
- run: ${{ matrix.command5 }}
57-
if: ${{ matrix.command5 }}
7+
# tests reusable tox workflow
8+
uses: ./.github/workflows/tox.yml
9+
with:
10+
default_python: "3.10"
11+
jobs_producing_coverage: 0
12+
max_python: "3.13"
13+
min_python: "3.10"
14+
run_post: echo 'Running post'
15+
run_pre: echo 'Running pre'
16+
other_names: |
17+
docs
18+
lint
5819
5920
check: # This job does nothing and is only used for the branch protection
6021
if: always()

.github/workflows/tox.yml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,30 @@ on:
2424
description: Maximum python version for matrix generation
2525
required: false
2626
type: string
27+
other_names:
28+
default: |
29+
docs
30+
lint
31+
pkg
32+
py312-milestone
33+
description: Implicit names for the matrix
34+
required: false
35+
type: string
2736
other_names_also:
2837
default: ""
2938
description: Additional names for the matrix
3039
required: false
3140
type: string
41+
run_pre:
42+
default: ""
43+
description: Preparatory command to run before test commands.
44+
required: false
45+
type: string
46+
run_post:
47+
default: ""
48+
description: Command to run after test commands.
49+
required: false
50+
type: string
3251

3352
env:
3453
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # might be needed by tox commands
@@ -50,10 +69,7 @@ jobs:
5069
max_python: ${{ inputs.max_python }}
5170
default_python: ${{ inputs.default_python }}
5271
other_names: |
53-
docs
54-
lint
55-
pkg
56-
py312-milestone
72+
${{ inputs.other_names }}
5773
${{ inputs.other_names_also }}
5874
platforms: linux,macos
5975

@@ -86,12 +102,16 @@ jobs:
86102
key: pre-commit-${{ matrix.name }}-${{ hashFiles('.pre-commit-config.yaml') }}
87103

88104
- name: Set up Python ${{ matrix.python_version || '3.12' }}
89-
if: "!contains(matrix.shell, 'wsl')"
105+
if: ${{ !contains(matrix.shell, 'wsl') }}
90106
uses: actions/setup-python@v5
91107
with:
92-
cache: pip
108+
cache: ${{ hashFiles('requirements.txt', 'pyproject.toml') && 'pip' || '' }}
93109
python-version: ${{ matrix.python_version || '3.12' }}
94110

111+
- name: Run pre
112+
if: ${{ inputs.run_pre }}
113+
run: ${{ inputs.run_pre }}
114+
95115
- name: Install tox
96116
run: |
97117
python3 -m pip install --upgrade pip
@@ -114,6 +134,10 @@ jobs:
114134
- run: ${{ matrix.command5 }}
115135
if: ${{ matrix.command5 }}
116136

137+
- name: Run post
138+
if: ${{ inputs.run_post }}
139+
run: ${{ inputs.run_post }}
140+
117141
- name: Archive logs and coverage data
118142
uses: actions/upload-artifact@v4
119143
with:
@@ -176,14 +200,15 @@ jobs:
176200
fi
177201
178202
- name: Upload coverage data
203+
if: ${{ inputs.jobs_producing_coverage }}
179204
uses: codecov/[email protected]
180205
with:
181206
name: ${{ matrix.name }}
182207
fail_ci_if_error: true
183208
use_oidc: true
184209

185210
- name: Check codecov.io status
186-
if: github.event_name == 'pull_request'
211+
if: github.event_name == 'pull_request' && inputs.jobs_producing_coverage
187212
uses: coactions/codecov-status@main
188213

189214
- name: Decide whether the needed jobs succeeded or failed

0 commit comments

Comments
 (0)