Skip to content

Commit

Permalink
IMPROVEMENT: reuse pytest job artifacts by using workflow_run
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Jan 16, 2025
1 parent 9b250be commit 1abae31
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 65 deletions.
42 changes: 11 additions & 31 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,29 @@
name: Codecov

on:
push:
paths:
- '**/*.py' # Watch for changes in any Python files
- 'pyproject.yml' # Watch for changes in the pyproject.yml file
workflow_dispatch:
release:
types: [published]
workflow_run:
workflows: [Pytest]
types:
- completed

jobs:
run:
upload_coverage_to_codecov:
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
- name: Download coverage report
uses: actions/download-artifact@v4
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install pymavlink pytest pytest-cov coverage mock
pip install -U .
- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y xvfb
- name: Run tests and collect coverage
# run: pytest --cov ardupilot_methodic_configurator
run: |
export DISPLAY=:99
Xvfb :99 -screen 0 1024x768x16 &
coverage run -m pytest
coverage xml -o tests/coverage.xml
name: coverage-report-3.9

- name: Upload coverage report
uses: codecov/codecov-action@v4.0.1
uses: codecov/codecov-action@v5
with:
verbose: true
files: tests/coverage-3.9.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
48 changes: 14 additions & 34 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,31 @@
name: Coverage
# Make sure pull requests increase coverage monotonically

on: [pull_request]
on:
pull_request:
workflow_run:
workflows: [Pytest]
types:
- completed

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
# python-version: ["3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"]
os: [ubuntu-latest]
python-version: ["3.12"]
jobs:
add_coverage_to_pullrequest:
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Download coverage report
uses: actions/download-artifact@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -U pymavlink pytest pytest-cov coverage mock
pip install build
pip install -U .
- name: Install apt packages
run: |
sudo apt-get update
sudo apt-get install -y xvfb
- name: Test with unittest
run: |
export DISPLAY=:99
Xvfb :99 -screen 0 1024x768x16 &
coverage run -m pytest
coverage xml -o tests/coverage.xml
name: coverage-report-3.9

- name: Get Cover
uses: andraghetti/[email protected]
with:
coverageFile: tests/coverage.xml
coverageFile: tests/coverage-3.9.xml
token: ${{ secrets.GITHUB_TOKEN }}
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}

0 comments on commit 1abae31

Please sign in to comment.