Skip to content

Commit 3d2534c

Browse files
committed
IMPROVEMENT: reuse pytest job artifacts by using workflow_run
1 parent b2bd9cd commit 3d2534c

File tree

3 files changed

+36
-83
lines changed

3 files changed

+36
-83
lines changed

.github/workflows/codecov.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.github/workflows/coverage.yml

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,30 @@
11
name: Coverage
22
# Make sure pull requests increase coverage monotonically
33

4-
on: [pull_request]
4+
on:
5+
pull_request:
56

67
jobs:
7-
build:
8+
pytests:
9+
uses: ./.github/workflows/pytest.yml # use the callable pytest.yml workflow to run tests
810

9-
runs-on: ${{ matrix.os }}
10-
strategy:
11-
matrix:
12-
# os: [ubuntu-latest, macos-latest, windows-latest]
13-
# python-version: ["3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"]
14-
os: [ubuntu-latest]
15-
python-version: ["3.12"]
11+
add_coverage_to_pullrequest:
12+
runs-on: ubuntu-latest
13+
needs: pytests
1614

1715
steps:
18-
- name: Checkout
16+
- name: Checkout code
1917
uses: actions/checkout@v4
2018

21-
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v5
19+
- name: Download coverage report
20+
uses: actions/download-artifact@v4
2321
with:
24-
python-version: ${{ matrix.python-version }}
25-
26-
- name: Install dependencies
27-
run: |
28-
python -m pip install --upgrade pip setuptools wheel
29-
python -m pip install -U pymavlink pytest pytest-cov coverage mock
30-
pip install build
31-
pip install -U .
32-
33-
- name: Install apt packages
34-
run: |
35-
sudo apt-get update
36-
sudo apt-get install -y xvfb
37-
38-
- name: Test with unittest
39-
run: |
40-
export DISPLAY=:99
41-
Xvfb :99 -screen 0 1024x768x16 &
42-
coverage run -m pytest
43-
coverage xml -o tests/coverage.xml
22+
name: coverage-report-3.9
4423

4524
- name: Get Cover
4625
uses: andraghetti/coverage@v3.2
4726
with:
48-
coverageFile: tests/coverage.xml
27+
coverageFile: coverage-3.9.xml
4928
token: ${{ secrets.GITHUB_TOKEN }}
5029
# Use always() to always run this step to publish test results when there are test failures
5130
if: ${{ always() }}

.github/workflows/pytest.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Pytest
33
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#packaging-workflow-data-as-artifacts
44

55
on:
6+
pull_request:
67
push:
78
paths:
89
- '**/*.py' # Watch for changes in any Python files
@@ -47,7 +48,6 @@ jobs:
4748
export DISPLAY=:99
4849
Xvfb :99 -screen 0 1024x768x16 &
4950
pytest --cov=ardupilot_methodic_configurator --cov-report=xml:tests/coverage-${{ matrix.python-version }}.xml --md=tests/results-${{ matrix.python-version }}.md --cov-fail-under=42
50-
continue-on-error: true
5151
5252
- name: Display test results as github job summary
5353
run: cat tests/results-${{ matrix.python-version }}.md >> $GITHUB_STEP_SUMMARY
@@ -61,3 +61,26 @@ jobs:
6161
path: tests/coverage-${{ matrix.python-version }}.xml
6262
# Use always() to always run this step to publish test results when there are test failures
6363
if: ${{ always() }}
64+
65+
upload_coverage_to_codecov:
66+
runs-on: ubuntu-latest
67+
needs: pytest
68+
69+
steps:
70+
- name: Checkout code
71+
uses: actions/checkout@v4
72+
73+
- name: Download coverage report
74+
uses: actions/download-artifact@v4
75+
with:
76+
name: coverage-report-3.9
77+
78+
- name: Upload coverage report
79+
uses: codecov/codecov-action@v5
80+
with:
81+
verbose: true
82+
files: coverage-3.9.xml
83+
env:
84+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
85+
86+
# TODO: create a badge that presents the result of the Upload coverage report step

0 commit comments

Comments
 (0)