Skip to content

Commit 02917c5

Browse files
authored
Add Python 3.11/3.12 matrix builds to CI (#222)
- Run unit tests against Python 3.11 and 3.12 in parallel - Add PRIMARY_PYTHON_VERSION env var to control which version is used for coverage uploads, SonarCloud, and jUnit reporting - Add documentation for managing the Python version matrix
1 parent ae992b6 commit 02917c5

4 files changed

Lines changed: 125 additions & 4 deletions

File tree

.github/workflows/ci_full.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
---
22
name: galaxy_ng/ci
3+
4+
env:
5+
# Version used for coverage/SonarCloud/jUnit reporting
6+
# Note: When changing versions, you must also update the matrix in the test job
7+
PRIMARY_PYTHON_VERSION: "3.12"
8+
39
on:
410
pull_request:
511
branches:
@@ -62,11 +68,17 @@ jobs:
6268

6369
test:
6470
runs-on: ubuntu-latest
71+
strategy:
72+
fail-fast: false
73+
matrix:
74+
# Note: GitHub Actions doesn't support env vars in matrix definitions
75+
# PRIMARY_PYTHON_VERSION is used for coverage/SonarCloud reporting
76+
python-version: ["3.11", "3.12"]
6577
steps:
6678

6779
- uses: actions/setup-python@v6
6880
with:
69-
python-version: "3.12"
81+
python-version: ${{ matrix.python-version }}
7082

7183
- uses: actions/checkout@v5
7284
with:
@@ -89,12 +101,16 @@ jobs:
89101
run: pip3 install tox coverage[toml]
90102

91103
- name: run the unit tests
92-
run: tox --colored yes -e py312
104+
run: |
105+
TOX_ENV="py$(echo ${{ matrix.python-version }} | tr -d '.')"
106+
tox --colored yes -e $TOX_ENV
93107
94108
- name: Inject PR number into coverage.xml
109+
if: matrix.python-version == env.PRIMARY_PYTHON_VERSION
95110
run: sed -i '2i <!-- PR ${{ github.event.number }} -->' coverage.xml
96111

97112
- name: upload coverage as artifact
113+
if: matrix.python-version == env.PRIMARY_PYTHON_VERSION
98114
uses: actions/upload-artifact@v5
99115
with:
100116
name: coverage
@@ -113,7 +129,7 @@ jobs:
113129
114130
- name: SonarCloud Scan
115131
uses: SonarSource/sonarqube-scan-action@v6
116-
if: github.event_name == 'push' && contains(github.repository, 'ansible') && github.ref_name == 'main'
132+
if: github.event_name == 'push' && contains(github.repository, 'ansible') && github.ref_name == 'main' && matrix.python-version == env.PRIMARY_PYTHON_VERSION
117133
env:
118134
SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT || secrets.AAP_ORG_SONAR_TOKEN_ANSIBLE_CICD_BOT }}
119135
with:
@@ -122,7 +138,7 @@ jobs:
122138
-Dsonar.organization=${{ env.REPO_OWNER }}
123139
124140
- name: upload jUnit XML test results
125-
if: github.event_name == 'push' && contains(github.repository, 'ansible') && github.ref_name == 'main'
141+
if: github.event_name == 'push' && contains(github.repository, 'ansible') && github.ref_name == 'main' && matrix.python-version == env.PRIMARY_PYTHON_VERSION
126142
continue-on-error: true
127143
run: |
128144
curl -v --user "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}" \

docs/dev/ci.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Continuous Integration
2+
3+
Galaxy NG uses GitHub Actions for continuous integration testing. The CI pipeline runs linting, unit tests, and integration tests on every pull request and push to main or stable branches.
4+
5+
## CI Pipelines
6+
7+
The main CI workflows are located in `.github/workflows/`:
8+
9+
- **ci_full.yml**: Runs linting, unit tests, and uploads coverage to SonarCloud
10+
- **ci-docker-compose-integration.yml**: Runs integration tests across multiple deployment profiles
11+
- **ci_automation_hub_collection.yml**: Tests the ansible_hub collection integration
12+
- **sonar-pr.yaml**: Handles SonarCloud analysis for pull requests
13+
14+
## Python Version Matrix
15+
16+
The CI pipeline runs unit tests across multiple Python versions using GitHub Actions matrix builds.
17+
18+
**Current Python versions tested**: 3.11, 3.12
19+
20+
### Adding a New Python Version
21+
22+
To add support for a new Python version (e.g., 3.13):
23+
24+
1. **Update `tox.ini`** in the repository root:
25+
```ini
26+
env_list =
27+
py311
28+
py312
29+
py313 # Add new version
30+
```
31+
32+
2. **Update `.github/workflows/ci_full.yml`**:
33+
```yaml
34+
matrix:
35+
python-version: ["3.11", "3.12", "3.13"] # Add new version
36+
```
37+
38+
That's it! The rest of the configuration is designed to be extensible:
39+
40+
- **Dynamic tox environment naming**: Version numbers are automatically converted to tox environment names (3.13 → py313)
41+
- **Coverage artifacts**: Only uploaded from the latest Python version (currently 3.12) to save storage and simplify reporting
42+
- **Parallel execution**: Tests run in parallel across all versions with `fail-fast: false`
43+
- **Reporting**: SonarCloud and jUnit uploads use Python 3.12 by default (see below for how to change)
44+
45+
### Why Only Upload Coverage from the Latest Python Version?
46+
47+
The CI uploads test coverage artifacts only from Python 3.12 (the latest supported version), not from all matrix versions. This is intentional:
48+
49+
- **Code coverage is version-agnostic**: Coverage measures which lines of code are executed during tests, not Python-specific behavior. The coverage from 3.12 accurately represents what's tested across all versions.
50+
- **Saves storage**: Coverage XML files are uploaded as artifacts. Only uploading one saves GitHub Actions storage quota.
51+
- **Simplifies SonarCloud integration**: SonarCloud only needs one coverage report for analysis.
52+
- **Future-focused**: Using the latest Python version ensures our coverage analysis reflects modern Python behavior and features.
53+
54+
If you need coverage from a specific Python version for debugging, you can always run tox locally: `tox -e py311` generates `coverage.xml` locally.
55+
56+
### Changing the Python Version for Coverage/SonarCloud/jUnit Reporting
57+
58+
The workflow defines a `PRIMARY_PYTHON_VERSION` environment variable at the top of `.github/workflows/ci_full.yml`. This variable controls which Python version is used for coverage uploads, SonarCloud analysis, and jUnit reporting.
59+
60+
To change the version (e.g., when promoting 3.13 as the primary version), update the variable:
61+
62+
```yaml
63+
env:
64+
PRIMARY_PYTHON_VERSION: "3.13"
65+
```
66+
67+
**Important:** When adding or removing Python versions, you must also update the matrix array in the `test` job. GitHub Actions doesn't support env vars in matrix definitions, so the matrix must be updated separately.
68+
69+
This variable is referenced by:
70+
- Coverage artifact upload
71+
- SonarCloud scan
72+
- jUnit XML test results upload
73+
74+
**Note:** You don't need to update `.github/workflows/sonar-pr.yaml` - the artifact is always named `coverage` regardless of which Python version uploads it. This maintains backward compatibility with the workflow_run trigger.
75+
76+
### Testing Locally with Multiple Python Versions
77+
78+
To test with a specific Python version locally:
79+
80+
```bash
81+
# Test with Python 3.11
82+
tox -e py311
83+
84+
# Test with Python 3.12
85+
tox -e py312
86+
87+
# Run all environments
88+
tox
89+
```
90+
91+
## Integration Tests
92+
93+
Integration tests run across multiple deployment profiles to ensure Galaxy NG works correctly in different configurations. See the [integration test documentation](../tests/integration.md) for more details.
94+
95+
## Triggering CI
96+
97+
CI runs automatically on:
98+
- Every pull request
99+
- Pushes to `main` and `stable-*` branches
100+
- Daily at 3:00 UTC (scheduled run)
101+
- Manual workflow dispatch
102+
103+
You can also trigger workflows manually from the GitHub Actions tab in the repository.

docs/dev/getting_started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [REST API](developer_guide/rest_api.md)
88
- [Services](developer_guide/services.md)
99
- [RBAC](developer_guide/rbac.md)
10+
- [Continuous Integration](ci.md)
1011

1112
## Issue Tracker
1213

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
min_version = 4.0
33
no_package = true
44
env_list =
5+
py311
56
py312
67

78
[testenv]

0 commit comments

Comments
 (0)