Skip to content

Commit a24eaa3

Browse files
authored
Use reusable tox workflow (#172)
1 parent 7d9129f commit a24eaa3

File tree

2 files changed

+18
-209
lines changed

2 files changed

+18
-209
lines changed

.github/workflows/tox.yml

Lines changed: 12 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -2,222 +2,25 @@
22
name: tox
33

44
on:
5-
push: # only publishes pushes to the main branch to TestPyPI
6-
branches: # any integration branch but not tag
5+
push:
6+
branches:
77
- "main"
88
pull_request:
99
branches:
1010
- "main"
11+
workflow_call:
1112

1213
concurrency:
1314
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
1415
cancel-in-progress: true
1516

16-
env:
17-
FORCE_COLOR: 1
18-
PY_COLORS: 1
19-
2017
jobs:
21-
prepare:
22-
name: prepare
23-
runs-on: ubuntu-22.04
24-
outputs:
25-
matrix: ${{ steps.generate_matrix.outputs.matrix }}
26-
steps:
27-
- name: Determine matrix
28-
id: generate_matrix
29-
uses: coactions/dynamic-matrix@v2
30-
with:
31-
default_python: "3.10"
32-
min_python: "3.10"
33-
max_python: "3.12"
34-
other_names: |
35-
lint
36-
docs
37-
platforms: linux,macos
38-
39-
build:
40-
name: ${{ matrix.name }}
41-
runs-on: ${{ matrix.os || 'ubuntu-22.04' }}
42-
needs:
43-
- prepare
44-
defaults:
45-
run:
46-
shell: ${{ matrix.shell || 'bash'}}
47-
strategy:
48-
fail-fast: false
49-
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
50-
env:
51-
# Number of expected test passes, safety measure for accidental skip of
52-
# tests. Update value if you add/remove tests.
53-
PYTEST_REQPASS: 1
54-
steps:
55-
- uses: actions/checkout@v4
56-
with:
57-
fetch-depth: 0 # needed by setuptools-scm
58-
submodules: true
59-
60-
- name: Set pre-commit cache
61-
uses: actions/cache@v4
62-
if: ${{ matrix.passed_name == 'lint' }}
63-
with:
64-
path: |
65-
~/.cache/pre-commit
66-
key: pre-commit-${{ matrix.name || matrix.passed_name }}-${{ hashFiles('.pre-commit-config.yaml') }}
67-
68-
- name: Set galaxy cache
69-
uses: actions/cache@v4
70-
if: ${{ startsWith(matrix.passed_name, 'py') }}
71-
with:
72-
path: |
73-
examples/playbooks/collections/*.tar.gz
74-
examples/playbooks/collections/ansible_collections
75-
key: galaxy-${{ hashFiles('examples/playbooks/collections/requirements.yml') }}
76-
77-
- name: Set up Python ${{ matrix.python_version || '3.10' }}
78-
uses: actions/setup-python@v5
79-
with:
80-
cache: pip
81-
python-version: ${{ matrix.python_version || '3.10' }}
82-
83-
- name: Install tox
84-
run: |
85-
python3 -m pip install --upgrade pip
86-
python3 -m pip install --upgrade "tox>=4.0.0"
87-
88-
- name: Log installed dists
89-
run: python3 -m pip freeze --all
90-
91-
- name: Initialize tox envs ${{ matrix.passed_name }}
92-
run: python3 -m tox --notest --skip-missing-interpreters false -vv -e ${{ matrix.passed_name }}
93-
timeout-minutes: 5 # average is under 1, but macos can be over 3
94-
95-
# sequential run improves browsing experience (almost no speed impact)
96-
- name: tox -e ${{ matrix.passed_name }}
97-
run: python3 -m tox -e ${{ matrix.passed_name }}
98-
99-
- name: Archive logs
100-
uses: actions/upload-artifact@v4
101-
with:
102-
name: logs-${{ matrix.name }}.zip
103-
include-hidden-files: true
104-
path: |
105-
.tox/**/log/
106-
.tox/**/.coverage*
107-
.tox/**/coverage.xml
108-
109-
- name: Report failure if git reports dirty status
110-
run: |
111-
if [[ -n $(git status -s) ]]; then
112-
# shellcheck disable=SC2016
113-
echo -n '::error file=git-status::'
114-
printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY"
115-
exit 99
116-
fi
117-
# https://github.com/actions/toolkit/issues/193
118-
119-
codeql:
120-
name: codeql
121-
runs-on: ubuntu-latest
122-
permissions:
123-
actions: read
124-
contents: read
125-
security-events: write
126-
127-
strategy:
128-
fail-fast: false
129-
matrix:
130-
language: ["python"]
131-
132-
steps:
133-
- name: Checkout repository
134-
uses: actions/checkout@v4
135-
136-
# Initializes the CodeQL tools for scanning.
137-
- name: Initialize CodeQL
138-
uses: github/codeql-action/init@v3
139-
with:
140-
languages: ${{ matrix.language }}
141-
# If you wish to specify custom queries, you can do so here or in a config file.
142-
# By default, queries listed here will override any specified in a config file.
143-
# Prefix the list here with "+" to use these queries and those in the config file.
144-
145-
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
146-
# queries: security-extended,security-and-quality
147-
148-
- name: Autobuild
149-
uses: github/codeql-action/autobuild@v3
150-
151-
- name: Perform CodeQL Analysis
152-
uses: github/codeql-action/analyze@v3
153-
with:
154-
category: "/language:${{matrix.language}}"
155-
156-
check: # This job does nothing and is only used for the branch protection
157-
if: always()
158-
permissions:
159-
id-token: write # codecov
160-
pull-requests: write # allow codenotify to comment on pull-request
161-
162-
needs:
163-
- build
164-
- codeql
165-
166-
runs-on: ubuntu-latest
167-
168-
steps:
169-
# checkout needed for codecov action which needs codecov.yml file
170-
- uses: actions/checkout@v4
171-
172-
- name: Set up Python # likely needed for coverage
173-
uses: actions/setup-python@v5
174-
with:
175-
python-version: "3.12"
176-
177-
- run: pip3 install 'coverage>=7.5.1'
178-
179-
- name: Merge logs into a single archive
180-
uses: actions/upload-artifact/merge@v4
181-
with:
182-
name: logs.zip
183-
include-hidden-files: true
184-
pattern: logs-*.zip
185-
# artifacts like py312.zip and py312-macos do have overlapping files
186-
separate-directories: true
187-
188-
- name: Download artifacts
189-
uses: actions/download-artifact@v4
190-
with:
191-
name: logs.zip
192-
path: .
193-
194-
- name: Check for expected number of coverage.xml reports
195-
run: |
196-
JOBS_PRODUCING_COVERAGE=5
197-
if [ "$(find . -name coverage.xml | wc -l | bc)" -ne "${JOBS_PRODUCING_COVERAGE}" ]; then
198-
echo "::error::Number of coverage.xml files was not the expected one (${JOBS_PRODUCING_COVERAGE}): $(find . -name coverage.xml |xargs echo)"
199-
exit 1
200-
fi
201-
202-
- name: Upload coverage data
203-
uses: codecov/codecov-action@v4
204-
with:
205-
name: ${{ matrix.passed_name }}
206-
# verbose: true # optional (default = false)
207-
fail_ci_if_error: true
208-
use_oidc: true # cspell:ignore oidc
209-
210-
- name: Check codecov.io status
211-
if: github.event_name == 'pull_request'
212-
uses: coactions/codecov-status@main
213-
214-
- name: Decide whether the needed jobs succeeded or failed
215-
uses: re-actors/alls-green@release/v1
216-
with:
217-
jobs: ${{ toJSON(needs) }}
218-
219-
- name: Delete Merged Artifacts
220-
uses: actions/upload-artifact/merge@v4
221-
with:
222-
include-hidden-files: true
223-
delete-merged: true
18+
tox:
19+
uses: ansible/team-devtools/.github/workflows/tox.yml@main
20+
with:
21+
jobs_producing_coverage: 7
22+
other_names: |
23+
docs
24+
lint
25+
pkg
26+
devel

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ envlist =
66
lint
77
pkg
88
docs
9+
py
10+
devel
911

1012
[testenv]
13+
description =
14+
Run tests
15+
devel: without constrained dependencies
1116
extras =
1217
test
1318
passenv =
@@ -100,6 +105,7 @@ description =
100105
Build package, verify metadata, install package and assert behavior when ansible is missing.
101106
deps =
102107
build >= 1.0.3
108+
pip
103109
twine >= 4.0.1
104110
skip_install = true
105111
# Ref: https://twitter.com/di_codes/status/1044358639081975813

0 commit comments

Comments
 (0)