Skip to content

Release v0.241217 #2794

Release v0.241217

Release v0.241217 #2794

Workflow file for this run

name: PyTest
on:
pull_request:
push:
branches:
- main
jobs:
get_dockerfiles:
name: Get List of Dockerfiles for Containers
runs-on: ubuntu-latest
permissions:
packages: read
outputs:
imagenames: ${{ steps.set-matrix.outputs.imagenames }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Retrieve Docker Image Names
id: set-matrix
run: |
# search for Dockerfile* in the docker directory, replace "Dockerfile" prefix with "mrpro" and to imagenames
imagenames=$(find docker -type f -name 'Dockerfile*' -exec basename {} \; | sed 's/^Dockerfile/mrpro/')
echo "image names: $imagenames"
# if imagenames is empty - fail the workflow
if [ -z "$imagenames" ]; then
echo "No Dockerfiles found in the docker directory. Exiting..."
exit 1
fi
imagenames_latest=()
for image in $imagenames
do
echo "checking $image ..."
if docker manifest inspect "ghcr.io/ptb-mr/"$image":latest" >/dev/null; then
echo "... $image added"
imagenames_latest+=$image":"
fi
done
echo "image names with tag latest: $imagenames_latest"
imagenames_latest=$(echo $imagenames_latest | jq -R -c 'split(":")[:-1]')
echo "image names with tag latest: $imagenames_latest"
echo "imagenames=$imagenames_latest" >> $GITHUB_OUTPUT
- name: Dockerfile Overview
run: |
echo "Final list of images with tag latest: ${{ steps.set-matrix.outputs.imagenames }}"
test:
name: Run Tests and Coverage Report
needs: get_dockerfiles
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
strategy:
fail-fast: false
matrix:
imagename: ${{ fromJson(needs.get_dockerfiles.outputs.imagenames) }}
container:
image: ghcr.io/ptb-mr/${{ matrix.imagename }}:latest
options: --user runner
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install MRpro and Dependencies
run: pip install --upgrade --upgrade-strategy eager .[test]
- name: Install PyTest GitHub Annotation Plugin
run: pip install pytest-github-actions-annotate-failures
- name: Run PyTest and Generate Coverage Report
run: |
pytest -n 4 -m "not cuda" --junitxml=pytest.xml \
--cov-report=term-missing:skip-covered --cov=mrpro | tee pytest-coverage.txt
- name: Verify PyTest XML Output
run: |
if [ ! -f pytest.xml ]; then
echo "PyTest XML report not found. Please check the previous 'Run PyTest' step for errors."
exit 1
fi
- name: Post PyTest Coverage Comment
id: coverageComment
uses: MishaKav/pytest-coverage-comment@v1.1.53
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
- name: Create Coverage Badge on Main Branch Push
uses: schneegans/dynamic-badges-action@v1.7.0
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 48e334a10caf60e6708d7c712e56d241
filename: coverage.json
label: Coverage Report
message: ${{ steps.coverageComment.outputs.coverage }}
color: ${{ steps.coverageComment.outputs.color }}
namedLogo: python
- 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