Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out codecov upload #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper
# list of changed files within `super-linter`
Expand All @@ -50,7 +50,7 @@ jobs:
# Run Linter against code base #
################################
- name: Lint Code Base
uses: github/super-linter/slim@v5
uses: github/super-linter/slim@v6
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: main
Expand Down
48 changes: 43 additions & 5 deletions .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish test results
name: Publish test and coverage results

on:
workflow_run:
Expand All @@ -8,11 +8,19 @@ on:

jobs:
publish-test-results:
name: "Publish test results"
name: "Publish test and coverage results"
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'
if: github.event.workflow_run.conclusion != 'skipped' && github.repository_owner == 'Uninett'

steps:
# Checking out the repo is necessary codecov/codecov-action@v4 to work properly
# Codecov requires source code to process the coverage file and generate coverage
# reports
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}

- name: Download and Extract Artifacts
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Expand All @@ -25,9 +33,39 @@ jobs:
gh api $url > "$name.zip"
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
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 }}
37 changes: 25 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ 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"]

steps:
- uses: actions/checkout@v3
- name: Checkout code
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 +42,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/
Loading