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

Docker tests #175

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
146 changes: 146 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Build and test docker

on:
pull_request:
paths-ignore:
- "**.md"

jobs:
get_dockerfiles:
name: Get list of dockerfiles for different containers
runs-on: ubuntu-latest
outputs:
docker_toml: ${{ steps.filter.outputs.docker_toml }}
dockerfiles: ${{ steps.set-matrix.outputs.dockerfiles }}
imagenames: ${{ steps.set-matrix.outputs.imagenames }}
steps:
- name: Checkout mrpro repo
uses: actions/checkout@v4

- name: Check if files in docker or the toml file has been modified
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
docker_toml:
- 'docker/*'
- 'pyproject.toml'
- '/.github/docker.yml'

- run: echo ${{ steps.filter.outputs.docker_toml }}

- id: set-matrix
if: steps.filter.outputs.docker_toml == 'true'
run: |
cd ./docker/
ls
ckolbPTB marked this conversation as resolved.
Show resolved Hide resolved
dockerfiles=$(ls Dockerfile_* | jq -R -s -c 'split("\n")[:-1]')
echo $dockerfiles
echo "dockerfiles=$dockerfiles" >> $GITHUB_OUTPUT
imagenames=$(ls Dockerfile_* | sed -e 's/Dockerfile_/ghcr.io\/ptb-mr\/mrpro_/' | jq -R -s -c 'split("\n")[:-1]')
echo $imagenames
echo "imagenames=$imagenames" >> $GITHUB_OUTPUT

- name: Dockerfile overview
if: steps.filter.outputs.docker_toml == 'true'
run: |
echo ${{ steps.set-matrix.outputs.dockerfiles }}
echo ${{ steps.set-matrix.outputs.imagenames }}

push_test:
name: Create test images and push to GCR
needs: get_dockerfiles
if: ${{ needs.get_dockerfiles.outputs.docker_toml == 'true' }}
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
matrix:
dockerfile: ${{ fromJson(needs.get_dockerfiles.outputs.dockerfiles) }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create image name
id: image_name
run: |
dockerfile=${{ matrix.dockerfile }}
echo "image_name=${dockerfile/Dockerfile_/ghcr.io/ptb-mr/mrpro_}" >> $GITHUB_OUTPUT

- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ptb-mr
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./docker
file: ./docker/${{ matrix.dockerfile }}
push: true
tags: ${{ steps.image_name.outputs.image_name }}:test

test:
name: Test docker containers
needs: [get_dockerfiles, push_test]
if: ${{ needs.get_dockerfiles.outputs.docker_toml == 'true' }}
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: ${{ matrix.imagename }}:test
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"

push_latest:
name: Create latest images and push to GCR
needs: [get_dockerfiles, test]
if: ${{ needs.get_dockerfiles.outputs.docker_toml == 'true' }}
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
matrix:
dockerfile: ${{ fromJson(needs.get_dockerfiles.outputs.dockerfiles) }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create image name
id: image_name
run: |
dockerfile=${{ matrix.dockerfile }}
echo "image_name=${dockerfile/Dockerfile_/ghcr.io/ptb-mr/mrpro_}" >> $GITHUB_OUTPUT

- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ptb-mr
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull and push Docker image with new tag
run: |
docker pull ${{ steps.image_name.outputs.image_name }}:test
docker tag ${{ steps.image_name.outputs.image_name }}:test ${{ steps.image_name.outputs.image_name }}:latest
docker push ${{ steps.image_name.outputs.image_name }}:latest
138 changes: 59 additions & 79 deletions .github/workflows/docs.yaml → .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ on:
pull_request:

permissions:
contents: write
contents: write

defaults:
run:
shell: bash

jobs:
convert_scripts:
name: 'Translate scripts to notebooks'
name: Translate scripts to notebooks
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
outputs:
commit_hash: ${{ steps.add-commit-push.outputs.commit_hash }}
container:
image: ghcr.io/ptb-mr/mrpro_py311:latest
options: --user runner
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -26,20 +33,8 @@ jobs:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[notebook]

- name: Create requirements.txt from toml
run: |
pip-compile --extra notebook -o ./binder/requirements.txt pyproject.toml
- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[notebook]

- name: Translate scripts to notebooks
run: |
Expand All @@ -52,9 +47,7 @@ jobs:
uses: tj-actions/verify-changed-files@v18
ckolbPTB marked this conversation as resolved.
Show resolved Hide resolved
id: verify-changed-notebooks
with:
files: |
./examples/*.ipynb
./binder/requirements.txt
files: ./examples/*.ipynb

- name: Commit notebooks
if: steps.verify-changed-notebooks.outputs.files_changed == 'true'
Expand All @@ -67,7 +60,7 @@ jobs:
run: echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

get_notebooks:
name: 'Get list of notebooks'
name: Get list of notebooks
needs: convert_scripts
runs-on: ubuntu-latest
steps:
Expand All @@ -88,12 +81,15 @@ jobs:
notebooks: ${{ steps.set-matrix.outputs.notebooks }}

run_notebook:
name: 'Run notebook'
name: Run notebook
needs: [convert_scripts, get_notebooks]
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
container:
image: ghcr.io/ptb-mr/mrpro_py311:latest
options: --user root
strategy:
matrix:
notebook: ${{ fromJson(needs.get_notebooks.outputs.notebooks) }}
Expand All @@ -103,26 +99,16 @@ jobs:
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[notebook]
- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[notebook]

- name: Notebook name
run: echo ${{ matrix.notebook }}

- name: Run notebook
uses: yaananth/run-notebook@v2
uses: fzimmermann89/run-notebook@v3
env:
RUNNER: ${{ toJson(runner) }}
SECRETS: ${{ toJson(secrets) }}
GITHUB: ${{ toJson(github) }}
with:
notebook: ./examples/${{ matrix.notebook }}

Expand All @@ -138,40 +124,34 @@ jobs:
if: always()
with:
name: ${{ steps.artifact_names.outputs.ARTIFACT_NAME }}
path: ${{ RUNNER.temp }}/nb-runner/${{ steps.artifact_names.outputs.HTML_RESULT }}
path: ${{ github.workspace }}/nb-runner.out/${{ steps.artifact_names.outputs.HTML_RESULT }}
env:
RUNNER: ${{ toJson(runner) }}

create_documentation:
name: 'Build and deploy documentation'
name: Build and deploy documentation
needs: [convert_scripts, run_notebook]
runs-on: ubuntu-latest

container:
image: ghcr.io/ptb-mr/mrpro_py311:latest
options: --user runner
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'

- name: Install dependencies
run: |
pip install --upgrade pip
pip install ".[docs]"

- name: Download notebook html files
id: download
uses: actions/download-artifact@v4
with:
path: ./docs/source/notebook_artifact/

- name: Copy notebook html files
run: |
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}

- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[docs]

- name: Download notebook html 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='*' './')
Expand All @@ -181,8 +161,8 @@ jobs:
cp ./$nb ../_notebooks/
done

- name: List of notebooks
run: |
- name: List of notebooks
run: |
cd ./docs/source/_notebooks/
notebooks=$(grep -rl --include='*.html' './')
cd ../
Expand All @@ -198,22 +178,22 @@ jobs:
echo " :file: ./_notebooks/$nb" >> "notebook_${nb/.html/.rst}"
done

- name: Build docs
run: sphinx-build -b html ./docs/source ./docs/build/html

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
publish_branch: github-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/html
if: github.event_name != 'pull_request'

- name: Save Documentation
uses: actions/upload-artifact@v4
with:
name: Documentation
path: docs/build/html/
- name: Build docs
run: sphinx-build -b html ./docs/source ./docs/build/html

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
publish_branch: github-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/html
if: github.event_name != 'pull_request'

- name: Save Documentation
uses: actions/upload-artifact@v4
with:
name: Documentation
path: docs/build/html/

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: pre-commit
name: Pre-Commit

on:
pull_request:

jobs:
pre-commit:
name: Pre-commit
runs-on: ubuntu-latest
container:
image: ghcr.io/ptb-mr/mrpro_py311:latest
options: --user runner
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip' # caching pip dependencies
- uses: pre-commit/[email protected]

concurrency:
Expand Down
Loading