Skip to content

Commit b0d1fbd

Browse files
committed
Refactor GHA pipelines
1 parent 62c68c5 commit b0d1fbd

File tree

1 file changed

+114
-18
lines changed

1 file changed

+114
-18
lines changed

.github/workflows/tox.yml

Lines changed: 114 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1+
---
12
name: tox
23

34
on:
5+
merge_group:
46
push:
57
branches:
6-
- main
8+
- "main"
79

810
pull_request:
911
branches:
10-
- main
12+
- "main"
13+
schedule:
14+
- cron: "0 0 * * *"
15+
workflow_call:
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
19+
cancel-in-progress: true
20+
21+
env:
22+
FORCE_COLOR: 1 # tox, pytest, ansible-lint
23+
PY_COLORS: 1
1124

1225
jobs:
13-
pre:
14-
name: pre
15-
runs-on: ubuntu-22.04
26+
prepare:
27+
name: prepare
28+
runs-on: ubuntu-24.04
1629
outputs:
1730
matrix: ${{ steps.generate_matrix.outputs.matrix }}
1831
steps:
1932
- name: Determine matrix
2033
id: generate_matrix
21-
uses: coactions/matrix@v4
34+
uses: coactions/dynamic-matrix@v4
2235
with:
2336
min_python: "3.10"
2437
max_python: "3.14"
@@ -29,37 +42,120 @@ jobs:
2942
docs
3043
build:
3144
name: ${{ matrix.name }}
32-
needs: pre
33-
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
45+
runs-on: ${{ matrix.os || 'ubuntu-24.04' }}
46+
needs:
47+
- prepare
3448

3549
strategy:
3650
fail-fast: false
37-
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
51+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
3852

3953
steps:
4054
- uses: actions/checkout@v4
4155
with:
4256
fetch-depth: 0 # needed by setuptools-scm
57+
submodules: true
4358

44-
- name: Set up Python ${{ matrix.python_version }}
59+
- name: Set pre-commit cache
60+
uses: actions/cache@v4
61+
if: ${{ matrix.name == 'lint' }}
62+
with:
63+
path: |
64+
~/.cache/pre-commit
65+
key: pre-commit-${{ matrix.name }}-${{ hashFiles('.pre-commit-config.yaml') }}
66+
67+
- name: Set up Python ${{ matrix.python_version || '3.10' }}
68+
if: "!contains(matrix.shell, 'wsl')"
4569
uses: actions/setup-python@v5
4670
with:
47-
python-version: ${{ matrix.python_version }}
71+
cache: pip
72+
python-version: ${{ matrix.python_version || '3.10' }}
73+
4874

49-
- name: Install dependencies
75+
- name: Install tox
5076
run: |
51-
python -m pip install --upgrade pip
52-
pip install tox>=4.0
77+
python3 -m pip install --upgrade pip
78+
python3 -m pip install --upgrade "tox>=4.0.0" "tox-uv>=1.25.0" "uv>=0.6.6"
79+
80+
- name: Log installed dists
81+
run: python3 -m pip freeze --all
5382

54-
- name: ${{ matrix.name }}
55-
run: ${{ matrix.command }}
83+
- run: ${{ matrix.command }}
5684

57-
check: # This job does nothing and is only used for the branch protection
85+
- run: ${{ matrix.command2 }}
86+
if: ${{ matrix.command2 }}
87+
88+
- run: ${{ matrix.command3 }}
89+
if: ${{ matrix.command3 }}
90+
91+
- run: ${{ matrix.command4 }}
92+
if: ${{ matrix.command4 }}
93+
94+
- run: ${{ matrix.command5 }}
95+
if: ${{ matrix.command5 }}
96+
97+
- name: Archive logs
98+
uses: coactions/upload-artifact@v4
99+
with:
100+
name: logs-${{ matrix.name }}.zip
101+
include-hidden-files: true
102+
path: |
103+
.tox/**/.coverage*
104+
.tox/**/coverage.xml
105+
106+
- name: Report failure if git reports dirty status
107+
run: |
108+
if [[ -n $(git status -s) ]]; then
109+
# shellcheck disable=SC2016
110+
echo -n '::error file=git-status::'
111+
printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY"
112+
exit 99
113+
fi
114+
check:
58115
if: always()
116+
permissions:
117+
id-token: write
118+
checks: read
59119
needs:
60120
- build
61-
runs-on: ubuntu-22.04
121+
runs-on: ubuntu-24.04
122+
62123
steps:
124+
# checkout needed for codecov action which needs codecov.yml file
125+
- uses: actions/checkout@v4
126+
127+
- name: Set up Python # likely needed for coverage
128+
uses: actions/setup-python@v5
129+
with:
130+
python-version: "3.13"
131+
132+
- run: pip3 install 'coverage>=7.5.1'
133+
134+
- name: Merge logs into a single archive
135+
uses: actions/upload-artifact/merge@v4
136+
with:
137+
name: logs.zip
138+
include-hidden-files: true
139+
pattern: logs-*.zip
140+
# artifacts like py312.zip and py312-macos do have overlapping files
141+
separate-directories: true
142+
143+
- name: Download artifacts
144+
uses: actions/download-artifact@v4
145+
continue-on-error: true # to allow rerunning this job
146+
with:
147+
name: logs.zip
148+
path: .
149+
150+
151+
- name: Upload coverage data
152+
uses: codecov/[email protected]
153+
with:
154+
name: ${{ matrix.name }}
155+
# verbose: true # optional (default = false)
156+
fail_ci_if_error: true
157+
use_oidc: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }} # cspell:ignore oidc
158+
63159
- name: Decide whether the needed jobs succeeded or failed
64160
uses: re-actors/alls-green@release/v1
65161
with:

0 commit comments

Comments
 (0)