Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 56 additions & 0 deletions .github/workflows/generate_notebook_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Dynamically creates a matrix for the GitHub Actions workflow that
runs the notebooks in the examples directory.
"""

import os
import json

# Dictionary to store custom timeouts for each notebook
notebook_timeouts = {
"ADCP_Delft3D_TRTS_example.ipynb": 1200,
"adcp_example.ipynb": 240,
"adv_example.ipynb": 180,
"cdip_example.ipynb": 180,
"Delft3D_example.ipynb": 180,
"directional_waves.ipynb": 180,
"environmental_contours_example.ipynb": 720,
"extreme_response_contour_example.ipynb": 360,
"extreme_response_full_sea_state_example.ipynb": 420,
"extreme_response_MLER_example.ipynb": 650,
"loads_example.ipynb": 180,
"metocean_example.ipynb": 240,
"mooring_example.ipynb": 300,
"PacWave_resource_characterization_example.ipynb": 780,
"power_example.ipynb": 180,
"qc_example.ipynb": 180,
"river_example.ipynb": 240,
"short_term_extremes_example.ipynb": 180,
"SWAN_example.ipynb": 180,
"tidal_example.ipynb": 240,
"tidal_performance_example.ipynb": 180,
"upcrossing_example.ipynb": 180,
"wave_example.ipynb": 180,
"wecsim_example.ipynb": 180,
"WPTO_hindcast_example.ipynb": 1200,
"default": 300, # Default timeout for other notebooks
}
notebooks = []
for root, dirs, files in os.walk("examples"):
for file in files:
if file.endswith(".ipynb"):
notebooks.append(os.path.join(root, file))

# Generate the matrix configuration
matrix = {"include": []}
for notebook in notebooks:
timeout = notebook_timeouts.get(
os.path.basename(notebook), notebook_timeouts["default"]
)

matrix["include"].append({"notebook": notebook, "timeout": timeout})


# Print the matrix as a properly formatted JSON string
matrix_json = json.dumps(matrix)
print(f"matrix={matrix_json}")
127 changes: 105 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Py 3.8, 3.9, 3.10, 3.11 | Windows Mac Linux
name: Py 3.10, 3.11 | Windows Mac Linux

on:
push:
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
prepare-nonhindcast-cache:
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
needs: [check-changes]
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
steps:
- name: Checkout code
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
needs: [check-changes, prepare-wave-hindcast-cache]
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
steps:
- name: Checkout code
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']
env:
PYTHON_VER: ${{ matrix.python-version }}

Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']

steps:
- uses: conda-incubator/setup-miniconda@v3
Expand All @@ -244,21 +244,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install HDF5 (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: brew install hdf5

- name: Install NetCDF (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: brew install netcdf

- name: Set environment variables (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: |
echo "HDF5_DIR=$(brew --prefix hdf5)" >> $GITHUB_ENV
echo "NETCDF4_DIR=$(brew --prefix netcdf)" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$(brew --prefix hdf5)/lib/pkgconfig:$(brew --prefix netcdf)/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV

- name: Set up Git repository
uses: actions/checkout@v4

Expand Down Expand Up @@ -305,7 +290,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -359,6 +344,104 @@ jobs:
parallel: true
path-to-lcov: ./coverage.lcov

notebook-matrix:
runs-on: ubuntu-latest
needs:
[
check-changes,
prepare-nonhindcast-cache,
prepare-wave-hindcast-cache,
prepare-wind-hindcast-cache,
]
if: |
always() &&
(
(
needs.prepare-nonhindcast-cache.result == 'success' &&
needs.prepare-wave-hindcast-cache.result == 'skipped' &&
needs.prepare-wind-hindcast-cache.result == 'skipped' &&
needs.check-changes.outputs.should-run-hindcast == 'false'
) ||
(
needs.prepare-nonhindcast-cache.result == 'success' &&
needs.prepare-wave-hindcast-cache.result == 'success' &&
needs.prepare-wind-hindcast-cache.result == 'success' &&
needs.check-changes.outputs.should-run-hindcast == 'true'
)
)
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Generate matrix
id: set-matrix
run: |
matrix_json=$(python .github/workflows/generate_notebook_matrix.py)
echo "$matrix_json" >> $GITHUB_OUTPUT

test-notebooks:
needs:
[
notebook-matrix,
check-changes,
prepare-nonhindcast-cache,
prepare-wave-hindcast-cache,
prepare-wind-hindcast-cache,
]
strategy:
matrix: ${{ fromJson(needs.notebook-matrix.outputs.matrix) }}
if: |
always()
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: 'latest'
auto-update-conda: true
python-version: '3.11'
activate-environment: TESTconda
use-only-tar-bz2: true

- name: Install dependencies
shell: bash -l {0}
run: |
conda install numpy cython pip hdf5 libnetcdf cftime netcdf4 --strict-channel-priority
pip install -e . --force-reinstall
python -m pip install --upgrade pip wheel
pip install nbval jupyter
pip install utm folium

- name: Ensure Conda environment is activated
shell: bash -l {0}
run: |
echo "source ~/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc
echo "conda activate TESTconda" >> ~/.bashrc
source ~/.bashrc

- name: Run notebook
shell: bash -l {0}
run: |
if [[ "${{ matrix.notebook }}" == "examples/metocean_example.ipynb" || "${{ matrix.notebook }}" == "examples/WPTO_hindcast_example.ipynb" ]]; then
if [[ "${{ needs.check-changes.outputs.should-run-hindcast }}" == 'true' ]]; then
jupyter nbconvert --to notebook --execute --inplace --ExecutePreprocessor.timeout=${{ matrix.timeout }} "${{ matrix.notebook }}"
else
echo "Skipping ${{ matrix.notebook }}"
fi
else
jupyter nbconvert --to notebook --execute --inplace --ExecutePreprocessor.timeout=${{ matrix.timeout }} "${{ matrix.notebook }}"
fi

coveralls:
name: Indicate completion to coveralls.io
needs:
Expand Down
56 changes: 32 additions & 24 deletions examples/SWAN_example.ipynb

Large diffs are not rendered by default.

Loading