Improve testing in dedicated conda env #411
This file contains hidden or 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
| name: Test and Deploy bioimageio.core | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: ['**'] | |
| defaults: | |
| run: | |
| shell: bash -el {0} | |
| jobs: | |
| populate-cache: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| cache-key: ${{steps.cache-key.outputs.cache-key}}-0 | |
| steps: | |
| - name: Get Date | |
| id: get-date | |
| run: | | |
| echo "date=$(date +'%Y-%b')" | |
| echo "date=$(date +'%Y-%b')" >> $GITHUB_OUTPUT | |
| - id: cache-key | |
| run: echo "cache-key=test-${{steps.get-date.outputs.date}}" >> $GITHUB_OUTPUT | |
| - uses: actions/cache/restore@v4 | |
| id: look-up | |
| with: | |
| path: bioimageio_cache | |
| key: ${{steps.cache-key.outputs.cache-key}} | |
| lookup-only: true | |
| - uses: actions/checkout@v4 | |
| if: steps.look-up.outputs.cache-hit != 'true' | |
| - uses: actions/cache@v4 | |
| if: steps.look-up.outputs.cache-hit != 'true' | |
| with: | |
| path: bioimageio_cache | |
| key: ${{steps.cache-key.outputs.cache-key}} | |
| - uses: actions/setup-python@v6 | |
| if: steps.look-up.outputs.cache-hit != 'true' | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install dependencies | |
| if: steps.look-up.outputs.cache-hit != 'true' | |
| run: | | |
| pip install -e .[dev] | |
| - run: pytest --disable-pytest-warnings tests/test_bioimageio_collection.py::test_rdf_format_to_populate_cache | |
| if: steps.look-up.outputs.cache-hit != 'true' | |
| env: | |
| BIOIMAGEIO_POPULATE_CACHE: '1' | |
| BIOIMAGEIO_CACHE_PATH: bioimageio_cache | |
| test: | |
| needs: populate-cache | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - python-version: '3.9' | |
| numpy-version: 1 | |
| - python-version: '3.9' | |
| numpy-version: 2 | |
| - python-version: '3.10' | |
| run-expensive-tests: true | |
| report-coverage: true | |
| save-cache: true | |
| numpy-version: 1 | |
| - python-version: '3.11' | |
| numpy-version: 2 | |
| - python-version: '3.12' | |
| numpy-version: 1 | |
| # - python-version: '3.13' | |
| # numpy-version: 2 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{matrix.python-version}} | |
| cache: 'pip' | |
| - name: Install dependencies | |
| run: | | |
| pip install --upgrade pip | |
| pip install -e .[dev,partners] numpy==${{matrix.numpy-version}}.* | |
| - name: Pyright | |
| if: matrix.run-expensive-tests # pyright is not expensive, but we only want to run it once due to otherwise inconsistent typing | |
| run: | | |
| pyright --version | |
| pyright -p pyproject.toml --pythonversion ${{ matrix.python-version }} | |
| - name: Restore bioimageio cache ${{needs.populate-cache.outputs.cache-key}} | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: bioimageio_cache | |
| key: ${{needs.populate-cache.outputs.cache-key}} | |
| - name: pytest | |
| run: pytest --cov bioimageio.core --cov-append --capture no --disable-pytest-warnings | |
| env: | |
| BIOIMAGEIO_CACHE_PATH: bioimageio_cache | |
| RUN_EXPENSIVE_TESTS: ${{ matrix.run-expensive-tests && 'true' || 'false' }} | |
| - name: Save bioimageio cache ${{needs.populate-cache.outputs.cache-key}} | |
| if: matrix.save-cache | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: bioimageio_cache | |
| key: ${{needs.populate-cache.outputs.cache-key}} | |
| - run: cp .coverage .coverage.${{matrix.python-version}}-${{matrix.numpy-version}} | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: .coverage.${{matrix.python-version}}-${{matrix.numpy-version}} | |
| retention-days: 1 | |
| path: .coverage.${{matrix.python-version}}-${{matrix.numpy-version}} | |
| include-hidden-files: true | |
| coverage: | |
| needs: [test] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v6 | |
| - run: | | |
| pip install coverage | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: .coverage.* | |
| merge-multiple: true | |
| - run: | | |
| ls -la .coverage* | |
| coverage combine | |
| coverage xml -o coverage.xml | |
| - uses: orgoro/[email protected] | |
| with: | |
| coverageFile: coverage.xml | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| thresholdAll: 0.7 | |
| thresholdNew: 0.9 | |
| thresholdModified: 0.6 | |
| - name: generate coverage badge and html report | |
| run: | | |
| pip install genbadge[coverage] | |
| genbadge coverage --input-file coverage.xml --output-file ./dist/coverage/coverage-badge.svg | |
| coverage html -d dist/coverage | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-summary | |
| retention-days: 1 | |
| path: dist | |
| conda-build: | |
| needs: test # only so we run tests even if the pinned bioimageio.spec version is not yet published on conda-forge yet | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: conda-incubator/setup-miniconda@v3 | |
| with: | |
| auto-update-conda: true | |
| auto-activate-base: true | |
| activate-environment: '' | |
| channel-priority: strict | |
| miniforge-version: latest | |
| conda-solver: libmamba | |
| - name: install common conda dependencies | |
| run: conda install -n base -c conda-forge conda-build -y | |
| - uses: actions/cache@v4 | |
| with: | |
| path: | | |
| pkgs/noarch | |
| pkgs/channeldata.json | |
| key: ${{ github.sha }}-packages | |
| - name: linux conda build test | |
| shell: bash -l {0} | |
| run: | | |
| mkdir -p ./pkgs/noarch | |
| conda-build -c conda-forge conda-recipe --output-folder ./pkgs | |
| docs: | |
| needs: test | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage-summary | |
| path: dist | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - run: pip install -e .[dev,partners] | |
| - name: Generate developer docs | |
| run: ./scripts/pdoc/run.sh | |
| - run: cp README.md ./dist/README.md | |
| - name: copy rendered presentations | |
| run: | | |
| mkdir ./dist/presentations | |
| cp -r ./presentations/*.html ./dist/presentations/ | |
| - name: Deploy to gh-pages 🚀 | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| branch: gh-pages | |
| folder: dist | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.10' | |
| cache: 'pip' | |
| - name: Install dependencies | |
| run: pip install --upgrade build | |
| - name: Build package | |
| run: python -m build | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| path: dist/ | |
| name: dist | |
| publish: | |
| needs: [test, build, conda-build, docs] | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: release | |
| url: https://pypi.org/project/bioimageio.core/ | |
| permissions: | |
| contents: write # required for tag creation | |
| id-token: write # required for pypi publish action | |
| steps: | |
| - name: Check out the repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check if there is a parent commit | |
| id: check-parent-commit | |
| run: | | |
| echo "sha=$(git rev-parse --verify --quiet HEAD^)" >> $GITHUB_OUTPUT | |
| - name: Detect new version | |
| id: tag-version | |
| if: github.ref == 'refs/heads/main' && steps.check-parent-commit.outputs.sha | |
| uses: salsify/[email protected] | |
| with: | |
| create-tag: true | |
| version-command: | | |
| python -c "from pathlib import Path;import json;print(p_src.read_text().split('__version__ = \"')[1].split('\"')[0] if (p_src:=Path('src/bioimageio/core/__init__.py')).exists() else json.loads(Path('bioimageio/core/VERSION').read_text())['version'])" | |
| - uses: actions/download-artifact@v4 | |
| if: github.ref == 'refs/heads/main' && steps.tag-version.outputs.tag | |
| with: | |
| name: dist | |
| path: dist | |
| - name: Publish package on PyPI | |
| if: github.ref == 'refs/heads/main' && steps.tag-version.outputs.tag | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist/ | |
| - name: Publish the release notes | |
| if: github.ref == 'refs/heads/main' | |
| uses: release-drafter/[email protected] | |
| with: | |
| publish: "${{ steps.tag-version.outputs.tag != '' }}" | |
| tag: '${{ steps.tag-version.outputs.tag }}' | |
| env: | |
| GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' |