forked from imr-framework/pypulseq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split test workflow to fix permission issue (#2)
- Loading branch information
Showing
3 changed files
with
169 additions
and
83 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: PyTest | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
name: Code tests | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||
include-sigpy: [true] | ||
|
||
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 | ||
pytest --junitxml=pytest.xml \ | ||
--cov-report=term-missing:skip-covered --cov=pypulseq | tee pytest-coverage.txt | ||
else | ||
pytest -m "not sigpy" --junitxml=pytest.xml \ | ||
--cov-report=term-missing:skip-covered --cov=pypulseq | tee pytest-coverage.txt | ||
fi | ||
- name: Upload PyTest Coverage Report | ||
if: always() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: pytest-report-${{ matrix.python-version }}-${{ matrix.include-sigpy }} | ||
path: | | ||
pytest-coverage.txt | ||
pytest.xml | ||
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
name: Report PyTest | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- PyTest | ||
types: | ||
- completed | ||
|
||
jobs: | ||
coverage_report_pr: | ||
name: Coverage report PR | ||
if: ${{ github.event.workflow_run.event == 'pull_request' }} | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
pull-requests: write | ||
steps: | ||
# use the results of python 3.12, consider this as target platform | ||
- name: Download PyTest report artifact for Python 3.12 | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: pytest-report-3.12-true | ||
run-id: ${{ github.event.workflow_run.id }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Get PR number | ||
id: pr-context | ||
env: | ||
# Token required for GH CLI: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# Best practice for scripts is to reference via ENV at runtime. Avoid using the expression syntax in the script content directly: | ||
PR_TARGET_REPO: ${{ github.repository }} | ||
# If the PR is from a fork, prefix it with `<owner-login>:`, otherwise only the PR branch name is relevant: | ||
PR_BRANCH: |- | ||
${{ | ||
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login) | ||
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) | ||
|| github.event.workflow_run.head_branch | ||
}} | ||
# Query the PR number by repo + branch, then assign to step output: | ||
run: | | ||
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \ | ||
--json 'number' --jq '"number=\(.number)"' \ | ||
>> "${GITHUB_OUTPUT}" | ||
- name: Post PyTest Coverage Comment | ||
id: coverage_comment | ||
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 failed | ||
# if there is no data the comment action does not fail but has an empty output | ||
if: steps.coverage_comment.outputs.coverageHtml == '' | ||
uses: edumserrano/find-create-or-update-comment@v3 | ||
with: | ||
issue-number: ${{ steps.pr-context.outputs.number }} | ||
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 | ||
|
||
coverage_report_push: | ||
name: Coverage report PUSH | ||
if: ${{ github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'master' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
run-id: ${{ github.event.workflow_run.id }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
name: pytest-report-3.12-true | ||
|
||
- name: Post PyTest Coverage Comment on push | ||
id: coverage_comment | ||
uses: MishaKav/[email protected] | ||
with: | ||
pytest-coverage-path: pytest-coverage.txt | ||
junitxml-path: pytest.xml | ||
|
||
# Todo: create a GIST and GIST secret to enable badge creation | ||
# - name: Create Coverage Badge on push to master | ||
# uses: schneegans/[email protected] | ||
# with: | ||
# auth: ${{ secrets.GIST_SECRET }} | ||
# gistID: xxx | ||
# filename: coverage.json | ||
# label: Coverage Report | ||
# message: ${{ steps.coverage_comment.outputs.coverage }} | ||
# color: ${{ steps.coverage_comment.outputs.color }} | ||
# namedLogo: python |