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

Fix test workflow and enable workflow runs in PRs from forks #246

Merged
merged 24 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e8ac51a
fix coverage path and permission
schuenke Jan 24, 2025
cd6f61c
use pipefail in PyTest step and remove content write permission again…
schuenke Jan 24, 2025
83790de
introduce test error to test workflow
schuenke Jan 24, 2025
855f8d1
revert error
schuenke Jan 24, 2025
2daf1fb
test error
fzimmermann89 Jan 30, 2025
8e09400
update workflow
schuenke Feb 3, 2025
13e3046
ensure coverageComment is run
schuenke Feb 3, 2025
72c4d31
revert error, remove ne workflow step again
schuenke Feb 3, 2025
ca43d1f
add Post Failure Comment again and insert syntax error
schuenke Feb 4, 2025
83404f7
add failure() condition
schuenke Feb 4, 2025
12472a8
revert syntax error to update comment
schuenke Feb 4, 2025
687a1cd
Merge branch 'master' into fix_workflows
schuenke Feb 4, 2025
3514d17
update post failure step and reintroduce syntax error
schuenke Feb 5, 2025
b1d22e1
Merge branch 'fix_workflows' of https://github.com/imr-framework/pypu…
schuenke Feb 5, 2025
ad0ca4d
always run get pr number step
schuenke Feb 5, 2025
90c9104
update
schuenke Feb 5, 2025
eac1d9b
update
schuenke Feb 5, 2025
af3d6ef
remove syntax error
schuenke Feb 5, 2025
d54e89c
split test workflow to fix permission issue
schuenke Feb 5, 2025
da91f6d
Split test workflow to fix permission issue (#2)
schuenke Feb 5, 2025
fb7a4fa
some mods to push
schuenke Feb 5, 2025
a4eb89b
remove cache step
schuenke Feb 5, 2025
3885c49
Merge branch 'test_new_workflow' into fix_workflows
schuenke Feb 5, 2025
21d2a7d
reduce to minimal permissions
schuenke Feb 5, 2025
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
83 changes: 0 additions & 83 deletions .github/workflows/push_pr.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: PyTest

on:
pull_request:
push:
branches:
- master
workflow_dispatch:

jobs:
test:
name: Code tests
runs-on: ubuntu-latest
permissions:
contents: write
schuenke marked this conversation as resolved.
Show resolved Hide resolved
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: 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
99 changes: 99 additions & 0 deletions .github/workflows/report_pytest.yml
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.
PR_TARGET_REPO: ${{ github.repository }}
# If the PR is from a fork, prefix it with `<owner-login>:`
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
Loading