Skip to content

Commit

Permalink
Move push to codecov to its own job in Actions
Browse files Browse the repository at this point in the history
Remove the push to codecov step from the `test` job into a new job that
depends on the test job. Upload the coverage reports as artifacts after
testing, and reuse the artifacts in the new job. Upload all coverage
reports in a single push to Codecov to minimize the number of hits.
  • Loading branch information
santisoler committed Jun 11, 2024
1 parent 5824e57 commit c9e6432
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defaults:

jobs:
#############################################################################
# Run tests and upload to codecov
# Run tests
test:
name: ${{ matrix.os }} python=${{ matrix.python }} dependencies=${{ matrix.dependencies }}
if: ${{ github.repository_owner == 'fatiando' || github.event_name != 'schedule' }}
Expand Down Expand Up @@ -155,14 +155,40 @@ jobs:
- name: Convert coverage report to XML for codecov
run: coverage xml

- name: Upload coverage to Codecov
- name: Upload coverage report as an artifact
uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.os }}_${{ matrix.dependencies }}
path: ./coverage.xml


#############################################################################
# Upload coverage report to codecov
codecov-upload:
runs-on: ubuntu-latest
needs: test

steps:

- name: Download coverage report artifacts
# Download coverage reports from every runner.
# Maximum coverage is achieved by combining reports from every runner.
# Each coverage file will live in its own folder with the same name as
# the artifact.
uses: actions/download-artifact@v4
with:
pattern: coverage_*

- name: List all downloaded artifacts
run: ls -l -R .

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
env_vars: OS,PYTHON,DEPENDENCIES
# Don't mark the job as failed if the upload fails for some reason.
# It does sometimes but shouldn't be the reason for running
# everything again unless something else is broken.
fail_ci_if_error: false
# Upload all coverage report files
files: ./coverage_*/coverage.xml
# Fail the job so we know coverage isn't being updated. Otherwise it
# can silently drop and we won't know.
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

0 comments on commit c9e6432

Please sign in to comment.