Fix coverage path and use pipefail #300
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run code tests on push and pull requests | |
on: | |
pull_request: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
tests: | |
name: Code tests | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
include-sigpy: [true, false] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Cache pip dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install PyPulseq and dependencies | |
run: | | |
pip install --upgrade --upgrade-strategy eager .[test] | |
if [ ${{ matrix.include-sigpy }} == "true" ]; then | |
pip install sigpy | |
fi | |
- name: Install PyTest GitHub Annotation Plugin | |
run: pip install pytest-github-actions-annotate-failures | |
- name: Run PyTest and Generate Coverage Report | |
run: | | |
if [ ${{ matrix.include-sigpy }} == "true" ]; then | |
(set -o pipefail && pytest --junitxml=pytest.xml \ | |
--cov-report=term-missing:skip-covered --cov=pypulseq | tee pytest-coverage.txt) | |
else | |
(set -o pipefail && pytest -m "not sigpy" --junitxml=pytest.xml \ | |
--cov-report=term-missing:skip-covered --cov=pypulseq | tee pytest-coverage.txt) | |
fi | |
shell: bash | |
- name: Post PyTest Coverage Comment | |
id: coverageComment | |
uses: MishaKav/[email protected] | |
with: | |
pytest-coverage-path: ./pytest-coverage.txt | |
junitxml-path: ./pytest.xml | |
- name: Set Pipeline Status Based on Test Results | |
if: steps.coverageComment.outputs.errors != 0 || steps.coverageComment.outputs.failures != 0 | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
core.setFailed("PyTest workflow failed with ${{ steps.coverageComment.outputs.errors }} errors and ${{ steps.coverageComment.outputs.failures }} failures.") | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
# Cancel in-progress runs when a new workflow with the same group name is triggered | |
cancel-in-progress: true |