Skip to content

Add test for minimum dependencies #1573

Add test for minimum dependencies

Add test for minimum dependencies #1573

Workflow file for this run

name: PyTest
on:
pull_request:
jobs:
get_dockerfiles:
name: Get list of dockerfiles for different containers
runs-on: ubuntu-latest
permissions:
packages: read
outputs:
imagenames: ${{ steps.set-matrix.outputs.imagenames }}
steps:
- id: set-matrix
env:
GH_TOKEN: ${{ secrets.GHCR_TOKEN }}
run: |
imagenames=$(curl -s --request GET \
--url "https://api.github.com/orgs/PTB-MR/packages?package_type=container" \
--header "Authorization: Bearer $GH_TOKEN" | jq -r '.[].name')
echo "image names: $imagenames"
imagenames_latest=()
for image in $(echo $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 get coverage report
needs: get_dockerfiles
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
strategy:
matrix:
imagename: ${{ fromJson(needs.get_dockerfiles.outputs.imagenames) }}
# runs within Docker container
container:
image: ghcr.io/ptb-mr/${{ matrix.imagename }}:latest
options: --user runner
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[test]
- name: Install pytest-github-actions-annotate-failures plugin
run: pip install pytest-github-actions-annotate-failures
- name: Run PyTest
run: |
pytest -n 4 -m "not cuda" --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=mrpro | tee pytest-coverage.txt
- name: Check for pytest.xml
run: |
if [ -f pytest.xml ]; then
echo "pytest.xml file found. Continuing..."
else
echo "pytest.xml file not found. Please check previous 'Run PyTest' section for errors."
exit 1
fi
- name: Pytest coverage comment
id: coverageComment
uses: MishaKav/[email protected]
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml
- name: Create the Badge
uses: schneegans/[email protected]
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
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