diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..0981abb00 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.github +.vscode +binder +examples +docs +tests \ No newline at end of file diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 9f02e8dcc..a55b7860d 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -1,4 +1,4 @@ -name: Publish to PyPI +name: Build and Deploy Package on: push: @@ -7,21 +7,31 @@ on: jobs: build-testpypi-package: - name: Modify version and build package for TestPyPI + name: Build Package for TestPyPI runs-on: ubuntu-latest outputs: version: ${{ steps.set_suffix.outputs.version }} suffix: ${{ steps.set_suffix.outputs.suffix }} + version_changed: ${{ steps.changes.outputs.version_changed }} steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.x" - - name: Set environment variable for version suffix + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Check if VERSION file is modified compared to main + uses: dorny/paths-filter@v3 + id: changes + with: + base: main + filters: | + version_changed: + - 'src/mrpro/VERSION' + + - name: Set Version Suffix id: set_suffix run: | VERSION=$(cat src/mrpro/VERSION) @@ -30,12 +40,12 @@ jobs: echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT - - name: Build package with version suffix + - name: Build Package run: | python -m pip install --upgrade build python -m build - - name: Store TestPyPi distribution + - name: Upload TestPyPI Distribution Artifact uses: actions/upload-artifact@v4 with: name: testpypi-package-distribution @@ -46,6 +56,7 @@ jobs: needs: - build-testpypi-package runs-on: ubuntu-latest + if: needs.build-testpypi-package.outputs.version_changed == 'true' environment: name: testpypi @@ -55,7 +66,7 @@ jobs: id-token: write steps: - - name: Download TestPyPi distribution + - name: Download TestPyPI Distribution uses: actions/download-artifact@v4 with: name: testpypi-package-distribution @@ -68,7 +79,7 @@ jobs: verbose: true test-install-from-testpypi: - name: Test installation from TestPyPI + name: Test Installation from TestPyPI needs: - testpypi-deployment - build-testpypi-package @@ -83,17 +94,25 @@ jobs: run: | VERSION=${{ needs.build-testpypi-package.outputs.version }} SUFFIX=${{ needs.build-testpypi-package.outputs.suffix }} - python -m pip install mrpro==$VERSION$SUFFIX --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ + for i in {1..3}; do + if python -m pip install mrpro==$VERSION$SUFFIX --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/; then + echo "Package installed successfully." + break + else + echo "Attempt $i failed. Retrying in 10 seconds..." + sleep 10 + fi + done build-pypi-package: - name: Build package for PyPI + name: Build Package for PyPI runs-on: ubuntu-latest needs: - test-install-from-testpypi outputs: version: ${{ steps.get_version.outputs.version }} steps: - - name: Checkout code + - name: Checkout Code uses: actions/checkout@v4 - name: Set up Python @@ -101,22 +120,22 @@ jobs: with: python-version: "3.x" - - name: Install setuptools_git_versioning + - name: Install Automatic Versioning Tool run: | python -m pip install setuptools-git-versioning - - name: Get current version + - name: Get Current Version id: get_version run: | VERSION=$(python -m setuptools_git_versioning) echo "VERSION=$VERSION" >> $GITHUB_OUTPUT - - name: Build package + - name: Build Package run: | python -m pip install --upgrade build python -m build - - name: Store PyPi distribution + - name: Store PyPI Distribution uses: actions/upload-artifact@v4 with: name: pypi-package-distribution @@ -138,13 +157,13 @@ jobs: id-token: write steps: - - name: Download PyPi distribution + - name: Download PyPI Distribution uses: actions/download-artifact@v4 with: name: pypi-package-distribution path: dist/ - - name: Create tag + - name: Create Tag uses: actions/github-script@v7 with: script: | @@ -155,7 +174,7 @@ jobs: sha: context.sha }) - - name: Create release + - name: Create Release uses: actions/github-script@v7 with: github-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b5e027cda..fe4f2ae03 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -62,6 +62,7 @@ jobs: permissions: packages: write strategy: + fail-fast: false matrix: dockerfile: ${{ fromJson(needs.get_dockerfiles.outputs.dockerfiles) }} steps: @@ -87,7 +88,9 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v6 with: - context: ./docker + context: . + cache-from: type=gha,scope=${{ matrix.dockerfile }} + cache-to: type=gha,mode=max,scope=${{ matrix.dockerfile }} file: ./docker/${{ matrix.dockerfile }} push: true tags: ${{ steps.image_name.outputs.image_name }}:test diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f102333b2..cc5ff5458 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -92,6 +92,7 @@ jobs: image: ghcr.io/ptb-mr/mrpro_py311:latest options: --user root strategy: + fail-fast: false matrix: notebook: ${{ fromJson(needs.get_notebooks.outputs.notebooks) }} steps: @@ -119,14 +120,14 @@ jobs: run: | notebook=${{ matrix.notebook }} echo "ARTIFACT_NAME=${notebook/.ipynb/}" >> $GITHUB_OUTPUT - echo "HTML_RESULT=${notebook/.ipynb/.html}" >> $GITHUB_OUTPUT + echo "IPYNB_EXECUTED=${notebook}" >> $GITHUB_OUTPUT - name: Upload notebook uses: actions/upload-artifact@v4 if: always() with: name: ${{ steps.artifact_names.outputs.ARTIFACT_NAME }} - path: ${{ github.workspace }}/nb-runner.out/${{ steps.artifact_names.outputs.HTML_RESULT }} + path: ${{ github.workspace }}/nb-runner.out/${{ steps.artifact_names.outputs.IPYNB_EXECUTED }} env: RUNNER: ${{ toJson(runner) }} @@ -149,39 +150,11 @@ jobs: - name: Install mrpro and dependencies run: pip install --upgrade --upgrade-strategy "eager" .[docs] - - name: Download notebook html files + - name: Download executed notebook ipynb files id: download uses: actions/download-artifact@v4 with: - path: ./docs/source/notebook_artifact/ - - - name: Copy notebook html files - run: | - mkdir ./docs/source/_notebooks - cd ./docs/source/notebook_artifact/ - notebooks=$(grep -rl --include='*' './') - for nb in $notebooks - do - echo "current jupyter-notebook: $nb" - cp ./$nb ../_notebooks/ - done - - - name: List of notebooks - run: | - cd ./docs/source/_notebooks/ - notebooks=$(grep -rl --include='*.html' './') - cd ../ - echo "" >> examples.rst - for nb in $notebooks - do - echo " notebook_${nb/.html/.rst}" >> examples.rst - notebook_description=$(grep '