Skip to content

Fix coverage path and use pipefail #323

Fix coverage path and use pipefail

Fix coverage path and use pipefail #323

Workflow file for this run

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
shell: bash
run: |
if [ ${{ matrix.include-sigpy }} == "true" ]; then
pytests --junitxml=pytest.xml \
--cov-report=term-missing:skip-covered --cov=pypulseq | tee pytest-coverage.txt
else
pytests -m "not sigpy" --junitxml=pytest.xml \
--cov-report=term-missing:skip-covered --cov=pypulseq | tee pytest-coverage.txt
fi
- name: Get PR number
id: pr-context
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_TARGET_REPO: ${{ github.repository }}
PR_BRANCH: ${{ github.event.pull_request.head.repo.full_name != github.repository && format('{0}:{1}', github.event.pull_request.head.repo.owner.login, github.event.pull_request.head.ref) || github.event.pull_request.head.ref }}
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' --jq '"number=\(.number)"' \
>> "${GITHUB_OUTPUT}"
- name: Post PyTest Coverage Comment
if: always()
id: coverageComment
uses: MishaKav/[email protected]
with:
issue-number: ${{ steps.pr-context.outputs.number }}
pytest-coverage-path: pytest-coverage.txt
junitxml-path: pytest.xml
- name: Post Failure Comment if Coverage Comment or PyTest failed
# if there is no data the comment action does not fail but has an empty output
if: failure() || (steps.coverageComment.outputs.coverageHtml == '')
uses: edumserrano/find-create-or-update-comment@v3
with:
issue-number: ${{ steps.pr-context.outputs.number }}
# see https://github.com/MishaKav/pytest-coverage-comment/blob/81882822c5b22af01f91bd3eacb1cefb6ad73dc2/src/index.js#L97
# for the generation of the unique id for comment
# in this particular case, there is no additional watermarkUniqueId
body-includes: "<!-- Pytest Coverage Comment: ${{ github.job }} -->"
comment-author: "github-actions[bot]"
body: |
<!-- Pytest Coverage Comment: ${{ github.job }} -->
### :x: PyTest Coverage Report was not found
Check the PyTest Workflow
edit-mode: replace
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