Skip to content

Commit c3732ef

Browse files
committed
Adopt tox workflow using coactions/dynamic-matrix
1 parent 8668a57 commit c3732ef

File tree

4 files changed

+219
-9
lines changed

4 files changed

+219
-9
lines changed

.github/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* @pycontribs/jira
2+
/.github/ @ssbarnea

.github/workflows/jira_ci.yml

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
name: ci
22

3+
# runs only after tox workflow finished successfully
34
on:
4-
# Trigger the workflow on push or pull request,
5-
# but only for the main branch
6-
push:
7-
branches:
8-
- main
9-
pull_request:
10-
branches:
11-
- main
5+
workflow_run:
6+
workflows: [tox]
7+
branches: [main]
8+
types:
9+
- completed
1210

1311
jobs:
1412
server:
13+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1514
uses: pycontribs/jira/.github/workflows/jira_server_ci.yml@main
1615

1716
cloud:

.github/workflows/tox.yml

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
---
2+
name: tox
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
11+
cancel-in-progress: true
12+
13+
env:
14+
FORCE_COLOR: 1 # tox, pytest
15+
PY_COLORS: 1
16+
17+
jobs:
18+
prepare:
19+
name: prepare
20+
runs-on: ubuntu-24.04
21+
outputs:
22+
matrix: ${{ steps.generate_matrix.outputs.matrix }}
23+
steps:
24+
- name: Determine matrix
25+
id: generate_matrix
26+
uses: coactions/dynamic-matrix@main # v3
27+
with:
28+
min_python: "3.9"
29+
max_python: "3.12"
30+
default_python: "3.9"
31+
# We run sanity with 3 different versions of ansible as the result
32+
# can be different. Each of them is testing with all supported
33+
# python versions, regardless the tox pyXY name.
34+
other_names: |
35+
lint
36+
docs
37+
pkg
38+
# ^ arm64 runner is using py311 for matching python version used in AAP 2.5
39+
platforms: linux,macos,linux-arm64:ubuntu-24.04-arm64-2core
40+
skip_explode: "1"
41+
build:
42+
name: ${{ matrix.name }}
43+
runs-on: ${{ matrix.os || 'ubuntu-24.04' }}
44+
continue-on-error: ${{ contains(matrix.name, 'integration') && true || false }}
45+
needs:
46+
- prepare
47+
defaults:
48+
run:
49+
shell: ${{ matrix.shell || 'bash'}}
50+
working-directory: ansible_collections/ansible/eda
51+
strategy:
52+
fail-fast: false
53+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
54+
steps:
55+
56+
- uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0 # needed by setuptools-scm
59+
path: ansible_collections/ansible/eda
60+
submodules: true
61+
62+
# - name: Install package dependencies (ubuntu)
63+
# if: ${{ contains(matrix.os, 'ubuntu') }}
64+
# run: |
65+
# sudo apt remove -y docker-compose
66+
# sudo apt-get update -y
67+
# sudo apt-get --assume-yes --no-install-recommends install -y apt-transport-https curl libsystemd0 libsystemd-dev pkg-config
68+
# sudo add-apt-repository ppa:deadsnakes/ppa
69+
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
70+
# echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
71+
# sudo apt update -y
72+
# sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin shellcheck
73+
# # Do not install docker-compose-plugin because it would v1 (broken due to not working with newer requests library)
74+
# sudo systemctl enable --now docker
75+
# sudo curl -sL "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
76+
# sudo chmod +x /usr/local/bin/docker-compose
77+
78+
- name: Set pre-commit cache
79+
uses: actions/cache@v4
80+
if: ${{ contains(matrix.name, 'lint') }}
81+
with:
82+
path: |
83+
~/.cache/pre-commit
84+
key: pre-commit-${{ matrix.name }}-${{ hashFiles('.pre-commit-config.yaml') }}
85+
86+
- name: Set up Python ${{ matrix.python_version || '3.10' }}
87+
uses: actions/setup-python@v5
88+
with:
89+
cache: pip
90+
python-version: ${{ matrix.python_version || '3.10' }}
91+
cache-dependency-path: "*requirements*.txt"
92+
93+
- name: Install tox
94+
run: |
95+
python3 -m pip install --upgrade pip wheel tox
96+
97+
- run: ${{ matrix.command }}
98+
99+
- run: ${{ matrix.command2 }}
100+
if: ${{ matrix.command2 }}
101+
102+
- run: ${{ matrix.command3 }}
103+
if: ${{ matrix.command3 }}
104+
105+
- run: ${{ matrix.command4 }}
106+
if: ${{ matrix.command4 }}
107+
108+
- run: ${{ matrix.command5 }}
109+
if: ${{ matrix.command5 }}
110+
111+
- name: Archive logs
112+
uses: actions/upload-artifact@v4
113+
with:
114+
name: logs-${{ matrix.name }}.zip
115+
if-no-files-found: error
116+
path: |
117+
ansible_collections/ansible/eda/.tox/**/log/
118+
ansible_collections/ansible/eda/.tox/**/coverage.xml
119+
ansible_collections/ansible/eda/tests/output/reports/coverage.xml
120+
ansible_collections/ansible/eda/tests/output/junit/*.xml
121+
122+
- name: Report failure if git reports dirty status
123+
run: |
124+
if [[ -n $(git status -s) ]]; then
125+
# shellcheck disable=SC2016
126+
echo -n '::error file=git-status::'
127+
printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY"
128+
exit 99
129+
fi
130+
# https://github.com/actions/toolkit/issues/193
131+
check:
132+
if: always()
133+
environment: check
134+
permissions:
135+
id-token: write
136+
checks: read
137+
138+
needs:
139+
- build
140+
141+
runs-on: ubuntu-24.04
142+
143+
steps:
144+
# checkout needed for codecov action which needs codecov.yml file
145+
- uses: actions/checkout@v4
146+
147+
- name: Set up Python # likely needed for coverage
148+
uses: actions/setup-python@v5
149+
with:
150+
python-version: "3.12"
151+
152+
- run: pip3 install 'coverage>=7.5.1'
153+
154+
- name: Merge logs into a single archive
155+
uses: actions/upload-artifact/merge@v4
156+
with:
157+
name: logs.zip
158+
pattern: logs-*.zip
159+
# artifacts like py312.zip and py312-macos do have overlapping files
160+
separate-directories: true
161+
162+
- name: Download artifacts
163+
uses: actions/download-artifact@v4
164+
with:
165+
name: logs.zip
166+
path: .
167+
168+
- name: Check for expected number of coverage reports
169+
run: .github/check-coverage.sh
170+
171+
# Single uploads inside check job for codecov to allow use to retry
172+
# it when it fails without running tests again. Fails often enough!
173+
- name: Upload junit xml reports
174+
# PRs from forks might not have access to the secret
175+
if: env.CODECOV_TOKEN
176+
env:
177+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN || env.CODECOV_TOKEN }}
178+
uses: codecov/test-results-action@v1
179+
with:
180+
name: ${{ matrix.name }}
181+
files: "*/tests/output/junit/*.xml"
182+
fail_ci_if_error: true
183+
token: ${{ secrets.CODECOV_TOKEN }}
184+
185+
- name: Upload coverage data
186+
uses: codecov/codecov-action@v4
187+
with:
188+
name: ${{ matrix.name }}
189+
# verbose: true # optional (default = false)
190+
fail_ci_if_error: true
191+
use_oidc: true # cspell:ignore oidc
192+
files: "*/tests/output/reports/coverage.xml"
193+
194+
# - name: Check codecov.io status
195+
# if: github.event_name == 'pull_request'
196+
# uses: coactions/codecov-status@main
197+
198+
- name: Decide whether the needed jobs succeeded or failed
199+
uses: re-actors/alls-green@release/v1
200+
with:
201+
jobs: ${{ toJSON(needs) }}
202+
203+
- name: Delete Merged Artifacts
204+
uses: actions/upload-artifact/merge@v4
205+
with:
206+
delete-merged: true

tox.ini

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ requires =
66
# tox-extra
77
# tox-pyenv
88
envlist =
9+
lint
10+
pkg
11+
docs
912
py311
1013
py310
1114
py39
@@ -99,7 +102,7 @@ commands =
99102
'import pathlib; '\
100103
'docs_dir = pathlib.Path(r"{toxworkdir}") / "docs_out"; index_file = docs_dir / "index.html"; print(f"\nDocumentation available under `file://\{index_file\}`\n\nTo serve docs, use `python3 -m http.server --directory \{docs_dir\} 0`\n")'
101104

102-
[testenv:packaging]
105+
[testenv:pkg]
103106
basepython = python3
104107
description =
105108
Build package, verify metadata, install package and assert behavior when ansible is missing.

0 commit comments

Comments
 (0)