Skip to content

Commit

Permalink
Factor out codecov upload
Browse files Browse the repository at this point in the history
Make sure tests can be green independently of codecov working or not.

* Upgrade Github actions
* Move codecov upload to publish tests workflow
* Use coverage from all python versions
* Upload PR number and base SHA as artifact
* Only publish test results/coverage if Uninett repo
* Use artifacts to configure codecov
  • Loading branch information
johannaengland authored Jun 17, 2024
1 parent 47b07d2 commit d9b4e1a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
33 changes: 31 additions & 2 deletions .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
publish-test-results:
name: "Publish test results"
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'
if: github.event.workflow_run.conclusion != 'skipped' && github.repository_owner == 'Uninett'

steps:
- name: Download and Extract Artifacts
Expand All @@ -26,8 +26,37 @@ jobs:
unzip -d "$name" "$name.zip"
done
- name: "Publish test results"
uses: EnricoMi/publish-unit-test-result-action/composite@v1
uses: EnricoMi/publish-unit-test-result-action@v2
with:
commit: ${{ github.event.workflow_run.head_sha }}
check_name: "Test results"
files: artifacts/**/results.xml

- name: Read PR number file
if: ${{ hashFiles('artifacts/extra/pr_number') != '' }}
run: |
pr_number=$(cat artifacts/extra/pr_number)
re='^[0-9]+$'
if [[ $pr_number =~ $re ]] ; then
echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV
fi
- name: Read base SHA file
if: ${{ hashFiles('artifacts/extra/base_sha') != '' }}
run: |
base_sha=$(cat artifacts/extra/base_sha)
re='[0-9a-f]{40}'
if [[ $base_sha =~ $re ]] ; then
echo "BASE_SHA=$base_sha" >> $GITHUB_ENV
fi
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
override_branch: ${{ github.event.workflow_run.head_branch}}
override_commit: ${{ github.event.workflow_run.head_sha}}
commit_parent: ${{ env.BASE_SHA }}
override_pr: ${{ env.PR_NUMBER }}
36 changes: 24 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ jobs:
test:
name: "Python ${{ matrix.python-version }}"
runs-on: ubuntu-latest
env:
USING_COVERAGE: '3.11'

strategy:
max-parallel: 4
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
Expand All @@ -43,15 +41,29 @@ jobs:
- name: Upload test reports (${{ matrix.python-version }})
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: reports
name: reports-${{ matrix.python-version }}
path: |
reports/**/*
- name: "Upload coverage to Codecov"
if: github.repository_owner == 'Uninett'
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }} # not required for forks of public repos
upload-pr-number-base-sha:
name: Save PR number and base SHA in artifact
runs-on: ubuntu-latest
if: ${{ github.event.number && always() }}
env:
PR_NUMBER: ${{ github.event.number }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
steps:
- name: Make PR number file
run: |
mkdir -p ./extra
echo $PR_NUMBER > ./extra/pr_number
- name: Make base SHA file
run: |
echo $BASE_SHA > ./extra/base_sha
- name: Upload PR number file and base SHA file
uses: actions/upload-artifact@v4
with:
name: extra
path: extra/

0 comments on commit d9b4e1a

Please sign in to comment.