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

ci: Allow reporting of coverage on PRs from forks #1622

Merged
merged 9 commits into from
Oct 12, 2021
44 changes: 38 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: CI/CD
on:
push:
pull_request:
branches:
- master
# Run daily at 0:01 UTC
schedule:
- cron: '1 0 * * *'
Expand All @@ -12,6 +14,11 @@ jobs:
test:

runs-on: ${{ matrix.os }}
# On push events run the CI only on master by default, but run on any branch if the commit message contains '[ci all]'
if: >-
github.event_name != 'push'
|| (github.event_name == 'push' && github.ref == 'refs/heads/master')
|| (github.event_name == 'push' && github.ref != 'refs/heads/master' && contains(github.event.head_commit.message, '[ci all]'))
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -24,37 +31,62 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade --editable .[test]

- name: List installed Python packages
run: |
python -m pip list
run: python -m pip list

- name: Test with pytest
run: |
python -m pytest -r sx --ignore tests/benchmarks/ --ignore tests/contrib --ignore tests/test_notebooks.py
- name: Report core project coverage with Codecov
if: github.event_name == 'push' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'

- name: Report core project coverage with Codecov (maintainers)
# Run on all events except schedule if PR comes from maintainers
if: github.repository == 'scikit-hep/pyhf' && github.event_name != 'schedule' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
flags: unittests

- name: Report core project coverage with Codecov (contributors)
# Run on pull_request events if PR comes from contributor fork
if: github.repository != 'scikit-hep/pyhf' && github.event_name == 'pull_request' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
flags: unittests

- name: Test Contrib module with pytest
run: |
python -m pytest -r sx tests/contrib --mpl --mpl-baseline-path tests/contrib/baseline
- name: Report contrib coverage with Codecov
if: github.event_name == 'push' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'

- name: Report contrib coverage with Codecov (maintainers)
# Run on all events except schedule if PR comes from maintainers
if: github.repository == 'scikit-hep/pyhf' && github.event_name != 'schedule' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
flags: contrib

- name: Report contrib coverage with Codecov (contributors)
# Run on pull_request events if PR comes from contributor fork
if: github.repository != 'scikit-hep/pyhf' && github.event_name == 'pull_request' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
flags: contrib

- name: Run benchmarks
if: github.event_name == 'schedule' && matrix.python-version == 3.9
run: |
Expand Down