RBniCSx CI #1760
This file contains 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: RBniCSx CI | |
on: | |
push: | |
branches: | |
- "**" | |
pull_request: | |
branches: | |
- main | |
schedule: | |
- cron: "0 5 * * *" | |
workflow_call: | |
workflow_dispatch: | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- backend: none-real | |
container: debian:testing | |
setup_git: | | |
export DEBIAN_FRONTEND="noninteractive" | |
apt update -y -q | |
apt install -y -qq git | |
setup_container: | | |
export DEBIAN_FRONTEND="noninteractive" | |
apt update -y -q | |
apt install -y -qq cmake libpetsc-real-dev libslepc-real-dev python3-mpi4py python3-nanobind python3-petsc4py-real python3-scikit-build-core python3-setuptools python3-slepc4py-real python3-pip wget | |
echo "OMPI_ALLOW_RUN_AS_ROOT=1" >> $GITHUB_ENV | |
echo "OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1" >> $GITHUB_ENV | |
rm /usr/lib/python3.*/EXTERNALLY-MANAGED | |
PETSC_DIR=/usr/lib/petscdir/petsc-real | |
rm $PETSC_DIR/lib/python3/dist-packages/petsc4py/py.typed | |
echo "PETSC_DIR=$PETSC_DIR" >> $GITHUB_ENV | |
SLEPC_DIR=/usr/lib/slepcdir/slepc-real | |
echo "SLEPC_DIR=$SLEPC_DIR" >> $GITHUB_ENV | |
- backend: none-complex | |
container: debian:testing | |
setup_git: | | |
export DEBIAN_FRONTEND="noninteractive" | |
apt update -y -q | |
apt install -y -qq git | |
setup_container: | | |
export DEBIAN_FRONTEND="noninteractive" | |
apt update -y -q | |
apt install -y -qq cmake libpetsc-complex-dev libslepc-complex-dev python3-mpi4py python3-nanobind python3-petsc4py-complex python3-scikit-build-core python3-setuptools python3-slepc4py-complex python3-pip wget | |
echo "OMPI_ALLOW_RUN_AS_ROOT=1" >> $GITHUB_ENV | |
echo "OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1" >> $GITHUB_ENV | |
rm /usr/lib/python3.*/EXTERNALLY-MANAGED | |
PETSC_DIR=/usr/lib/petscdir/petsc-complex | |
rm $PETSC_DIR/lib/python3/dist-packages/petsc4py/py.typed | |
echo "PETSC_DIR=$PETSC_DIR" >> $GITHUB_ENV | |
SLEPC_DIR=/usr/lib/slepcdir/slepc-complex | |
echo "SLEPC_DIR=$SLEPC_DIR" >> $GITHUB_ENV | |
- backend: dolfinx-real | |
container: ghcr.io/fenics/dolfinx/dolfinx:nightly | |
setup_git: "" | |
setup_container: | | |
. /usr/local/bin/dolfinx-real-mode | |
echo "PETSC_ARCH=$PETSC_ARCH" >> $GITHUB_ENV | |
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $GITHUB_ENV | |
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV | |
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV | |
echo "CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH" >> $GITHUB_ENV | |
rm /dolfinx-env/lib/python3.12/site-packages/petsc4py/py.typed | |
- backend: dolfinx-complex | |
container: ghcr.io/fenics/dolfinx/dolfinx:nightly | |
setup_git: "" | |
setup_container: | | |
. /usr/local/bin/dolfinx-complex-mode | |
echo "PETSC_ARCH=$PETSC_ARCH" >> $GITHUB_ENV | |
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $GITHUB_ENV | |
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV | |
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV | |
echo "CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH" >> $GITHUB_ENV | |
rm /dolfinx-env/lib/python3.12/site-packages/petsc4py/py.typed | |
fail-fast: false | |
container: | |
image: ${{ matrix.container }} | |
options: --user root | |
steps: | |
- name: Setup git | |
run: ${{ matrix.setup_git }} | |
- uses: actions/checkout@v4 | |
- name: Setup container | |
run: ${{ matrix.setup_container }} | |
- name: Install RBniCSx | |
run: | | |
if [[ "${{ matrix.backend }}" == none* ]]; then | |
python3 -m pip install --check-build-dependencies --no-build-isolation --config-settings=build-dir="build" --config-settings=cmake.build-type="Debug" --verbose .[docs,lint,tests] | |
else | |
python3 -m pip install --check-build-dependencies --no-build-isolation --config-settings=build-dir="build" --config-settings=cmake.build-type="Debug" --verbose .[docs,lint,tests,tutorials] | |
fi | |
shell: bash | |
- name: Clean build files | |
run: | | |
git config --global --add safe.directory $PWD | |
git clean -xdf | |
- name: Update mypy configuration | |
run: | | |
if [[ "${{ matrix.backend }}" == none* ]]; then | |
sed -i 's@\[tool\.mypy\]@[tool.mypy]\nexclude = "(^rbnicsx/backends|^tests/unit/backends)"@g' pyproject.toml | |
sed -i 's@ # "dolfinx",@ "dolfinx",@g' pyproject.toml | |
sed -i 's@ # "dolfinx.*",@ "dolfinx.*",@g' pyproject.toml | |
fi | |
shell: bash | |
- name: Run ruff on python files | |
run: | | |
python3 -m ruff check . | |
- name: Run isort on python files | |
run: | | |
python3 -m isort --check --diff . | |
- name: Run mypy on python files | |
run: | | |
python3 -m mypy --exclude=conftest.py . | |
python3 -m mypy tests/unit/conftest.py | |
python3 -m mypy tutorials/conftest.py | |
- name: Run yamllint on workflows | |
run: | | |
python3 -m yamllint -d "{extends: default, rules: {document-start: {present: false}, line-length: disable, truthy: {check-keys: false}}}" . | |
- name: Run clang-format on C++ files | |
run: | | |
wget https://raw.githubusercontent.com/FEniCS/dolfinx/main/.clang-format | |
find . -type f \( -name "*.cpp" -o -name "*.h" \) | xargs clang-format --dry-run --Werror | |
- name: Run cmake-format on cmake files | |
run: | | |
wget https://raw.githubusercontent.com/FEniCS/dolfinx/main/.cmake-format | |
find . -type f \( -name "*.cmake" -o -name "*.cmake.in" -o -name "CMakeLists.txt" \) | xargs cmake-format --check | |
- name: Run documentation generation | |
run: | | |
cd docs | |
if [[ "${{ matrix.backend }}" == none* ]]; then | |
sed -i "[email protected]@@g" api.rst | |
fi | |
python3 -m sphinx -W -b html . build/html | |
shell: bash | |
- name: Remove source directory to ensure that package from installation directory is used | |
run: | | |
rm -rf rbnicsx | |
- name: Determine coverage and pytest options for unit tests | |
id: unit_options | |
run: | | |
if [[ "${{ matrix.backend }}" == none* ]]; then | |
COVERAGE_UNIT_OMIT="*/rbnicsx/backends/*.py,*/rbnicsx/_cpp/backends/*.py" | |
PYTEST_UNIT_OPTIONS="--skip-backends" | |
else | |
COVERAGE_UNIT_OMIT="" | |
PYTEST_UNIT_OPTIONS="" | |
fi | |
echo "coverage_omit=${COVERAGE_UNIT_OMIT}" >> ${GITHUB_OUTPUT} | |
echo "pytest_options=${PYTEST_UNIT_OPTIONS}" >> ${GITHUB_OUTPUT} | |
shell: bash | |
- name: Run unit tests (serial) | |
run: | | |
COVERAGE_UNIT_OMIT="${{ steps.unit_options.outputs.coverage_omit }}" | |
PYTEST_UNIT_OPTIONS="${{ steps.unit_options.outputs.pytest_options }}" | |
COVERAGE_FILE=.coverage_unit_serial python3 -m coverage run --source=rbnicsx --omit="${COVERAGE_UNIT_OMIT}" -m pytest ${PYTEST_UNIT_OPTIONS} tests/unit | |
- name: Run unit tests (parallel) | |
run: | | |
COVERAGE_UNIT_OMIT="${{ steps.unit_options.outputs.coverage_omit }}" | |
PYTEST_UNIT_OPTIONS="${{ steps.unit_options.outputs.pytest_options }}" | |
COVERAGE_FILE=.coverage_unit_parallel mpirun -n 2 python3 -m coverage run --source=rbnicsx --parallel-mode --omit="${COVERAGE_UNIT_OMIT}" -m pytest ${PYTEST_UNIT_OPTIONS} tests/unit | |
- name: Combine coverage reports | |
run: | | |
python3 -m coverage combine .coverage* | |
python3 -m coverage report --fail-under=100 --show-missing --skip-covered | |
- name: Generate tutorial files | |
if: startsWith(matrix.backend, 'dolfinx') == true | |
run: | | |
NO_TESTS_COLLECTED=5 | |
python3 -m pytest --ipynb-action=create-notebooks tutorials || (($?==$NO_TESTS_COLLECTED)) | |
python3 -m pytest --ipynb-action=create-notebooks --tag-collapse tutorials || (($?==$NO_TESTS_COLLECTED)) | |
python3 -m pytest --ipynb-action=create-notebooks --np=2 tutorials || (($?==$NO_TESTS_COLLECTED)) | |
python3 -m pytest --ipynb-action=create-notebooks --tag-collapse --np=2 tutorials || (($?==$NO_TESTS_COLLECTED)) | |
shell: bash | |
- name: Run ruff on tutorial files | |
if: startsWith(matrix.backend, 'dolfinx') == true | |
run: | | |
python3 -m nbqa ruff . | |
- name: Run isort on tutorial files | |
if: startsWith(matrix.backend, 'dolfinx') == true | |
run: | | |
python3 -m nbqa isort --check --diff . | |
- name: Run mypy on tutorial files | |
if: startsWith(matrix.backend, 'dolfinx') == true | |
run: | | |
python3 -m nbqa mypy . | |
- name: Check for stray outputs, counts and metadata in tutorial files | |
if: startsWith(matrix.backend, 'dolfinx') == true | |
uses: RBniCS/check-jupyter-metadata-action@main | |
with: | |
pattern: "tutorials/**/*.ipynb" | |
- name: Run tutorials (serial) | |
if: startsWith(matrix.backend, 'dolfinx') == true | |
run: | | |
python3 -m pytest --tag-collapse --durations=0 --durations-min=1.0 tutorials | |
- name: Run tutorials (parallel) | |
if: startsWith(matrix.backend, 'dolfinx') == true | |
run: | | |
python3 -m pytest --tag-collapse --np=2 --durations=0 --durations-min=1.0 tutorials | |
- name: Upload tutorials logs as an artifact in case of failure | |
if: startsWith(matrix.backend, 'dolfinx') == true && (failure() || cancelled()) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "tutorials-logs-${{ matrix.backend }}" | |
path: | | |
tutorials/**/.ipynb_pytest/**/*.log* | |
include-hidden-files: true | |
warn: | |
runs-on: ubuntu-latest | |
if: github.repository == 'RBniCS/RBniCSx' && github.ref == 'refs/heads/main' && github.event_name == 'schedule' | |
steps: | |
- name: Warn if scheduled workflow is about to be disabled | |
uses: fem-on-colab/warn-workflow-about-to-be-disabled-action@main | |
with: | |
workflow-filename: ci.yml | |
days-elapsed: 55 |