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

Create dynamic GitHub Actions matrix to test against PyBaMM #193

Merged
merged 22 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
695170f
#123 rename: `release-action` to `release_action`
agriyakhetarpal Feb 11, 2024
bff90d6
#123 add custom script to dynamically generate matrix
agriyakhetarpal Feb 11, 2024
4f64bd4
#123 run script, pass generated matrix to next job
agriyakhetarpal Feb 11, 2024
48a3e12
#123 make script executable prior to running it
agriyakhetarpal Feb 11, 2024
c324365
#123 don't allow running M-series builds on forks
agriyakhetarpal Feb 11, 2024
e56eb36
#123 don't use `git update-index` for file permissions
agriyakhetarpal Feb 11, 2024
8c06d23
#123 move script to a dedicated `scripts/ci/` folder
agriyakhetarpal Feb 11, 2024
bfe8474
#123 correctly sparse checkout the matrix script
agriyakhetarpal Feb 11, 2024
77e233d
#123 fix up script to return valid JSON
agriyakhetarpal Feb 11, 2024
d26a48f
#123 simplify GitHub Actions output processing
agriyakhetarpal Feb 11, 2024
a4e0979
#123 convert JSON to string before parsing
agriyakhetarpal Feb 11, 2024
4679821
#123 move output before all jobs and test
agriyakhetarpal Feb 11, 2024
d09b537
#123 don't convert JSON output to raw strings
agriyakhetarpal Feb 11, 2024
4d9d732
#123 matrix script is working now, clean it up
agriyakhetarpal Feb 11, 2024
03bf40c
#123 specify a prettified job name via matrix variables
agriyakhetarpal Feb 11, 2024
b77d932
#123 temporarily fetch last three versions, not four
agriyakhetarpal Feb 12, 2024
bcc7983
#123 add `PYBOP_SCHEDULED` and `PYBAMM_VERSION`
agriyakhetarpal Feb 12, 2024
23b7be2
#123 configure `PYBAMM_VERSION` env var
agriyakhetarpal Feb 12, 2024
1f07663
#123 merge develop
agriyakhetarpal Feb 13, 2024
08c72b1
#123 add feature note to CHANGELOG
agriyakhetarpal Feb 13, 2024
937aea4
#123 moving forward with PyBaMM parameter set check
agriyakhetarpal Feb 14, 2024
9572d8f
#123 update CHANGELOG under bug fixes
agriyakhetarpal Feb 14, 2024
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
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
57 changes: 43 additions & 14 deletions .github/workflows/scheduled_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,82 @@ on:
schedule:
- cron: '0 9 * * *'

# Check noxfile.py for associated environment variables
env:
PYBOP_SCHEDULED: 1

jobs:
# Dynamically create a matrix of OS, Python, and PyBaMM versions
create_pybamm_matrix:
name: Dynamically create GitHub Actions matrix
runs-on: ubuntu-latest
steps:
- name: Check out PyBOP repository
uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
scripts/ci/build_matrix.sh

- name: Run script to create matrix
id: set-matrix
run: |
echo "matrix=$(bash scripts/ci/build_matrix.sh)" >> "$GITHUB_OUTPUT"
outputs:
pybop_matrix: ${{ steps.set-matrix.outputs.matrix }}

build:
needs: [create_pybamm_matrix]
name: Build (${{ matrix.os }}, Python ${{ matrix.python_version }}, PyBaMM ${{ matrix.pybamm_version }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
matrix: ${{fromJson(needs.create_pybamm_matrix.outputs.pybop_matrix)}}
env:
PYBAMM_VERSION: ${{ matrix.pybamm_version }}

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python_version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip nox

- name: Unit tests with nox
run: |
python -m nox -s unit
python -m nox -s notebooks
run: python -m nox -s unit

- name: Run notebooks with nox
run: python -m nox -s notebooks

#M-series Mac Mini
# M-series Mac Mini
build-apple-mseries:
runs-on: [self-hosted, macOS, ARM64]
if: github.repository == 'pybop-team/PyBOP'
env:
GITHUB_PATH: ${PYENV_ROOT/bin:$PATH}
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
python_version: ["3.10"]

steps:
- uses: actions/checkout@v4
- name: Install python & create virtualenv
shell: bash
run: |
eval "$(pyenv init -)"
pyenv install ${{ matrix.python-version }} -s
pyenv virtualenv ${{ matrix.python-version }} pybop-${{ matrix.python-version }}
pyenv install ${{ matrix.python_version }} -s
pyenv virtualenv ${{ matrix.python_version }} pybop-${{ matrix.python_version }}

- name: Install dependencies & run unit tests
shell: bash
run: |
eval "$(pyenv init -)"
pyenv activate pybop-${{ matrix.python-version }}
pyenv activate pybop-${{ matrix.python_version }}
python -m pip install --upgrade pip wheel setuptools nox
python -m nox -s unit
python -m nox -s notebooks
Expand All @@ -66,5 +95,5 @@ jobs:
shell: bash
run: |
eval "$(pyenv init -)"
pyenv activate pybop-${{ matrix.python-version }}
pyenv activate pybop-${{ matrix.python_version }}
pyenv uninstall -f $( python --version )
27 changes: 20 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import os
import nox


# nox options
nox.options.reuse_existing_virtualenvs = True
nox.options.venv_backend = "virtualenv"

# Environment variables to control CI behaviour for nox sessions
PYBOP_SCHEDULED = int(os.environ.get("PYBOP_SCHEDULED", 0))
PYBAMM_VERSION = os.environ.get("PYBAMM_VERSION", None)


@nox.session
def unit(session):
session.run_always("pip", "install", "-e", ".[all]")
session.install("pytest", "pytest-mock")
session.install("-e", ".[all]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.install("pytest", "pytest-mock", silent=False)
session.run("pytest", "--unit")


@nox.session
def coverage(session):
session.run_always("pip", "install", "-e", ".[all]")
session.install("pytest", "pytest-cov", "pytest-mock")
session.install("-e", ".[all]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.install("pytest", "pytest-cov", "pytest-mock", silent=False)
session.run(
"pytest",
"--unit",
Expand All @@ -27,8 +38,10 @@ def coverage(session):
@nox.session
def notebooks(session):
"""Run the examples tests for Jupyter notebooks."""
session.run_always("pip", "install", "-e", ".[all]")
session.install("pytest", "nbmake")
session.install("-e", ".[all]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.install("pytest", "nbmake", silent=False)
session.run("pytest", "--nbmake", "--examples", "examples/", external=True)


Expand All @@ -39,7 +52,7 @@ def docs(session):
Credit: PyBaMM Team
"""
envbindir = session.bin
session.install("-e", ".[all,docs]")
session.install("-e", ".[all,docs]", silent=False)
session.chdir("docs")
# Local development
if session.interactive:
Expand Down
43 changes: 43 additions & 0 deletions scripts/ci/build_matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# This helper script generates a matrix for further use in the
# scheduled/nightly builds for PyBOP, i.e., in scheduled_tests.yaml
# It generates a matrix of all combinations of the following variables:
# - python_version: 3.X
# - os: ubuntu-latest, windows-latest, macos-latest
# - pybamm_version: the last X versions of PyBaMM from PyPI, excluding release candidates

# To update the matrix, the variables below can be modified as needed.

python_version=("3.8" "3.9" "3.10" "3.11")
os=("ubuntu-latest" "windows-latest" "macos-latest")
# This command fetches the last three PyBaMM versions excluding release candidates from PyPI
pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | grep -v rc | tail -n 3 | awk '{print "\"" $1 "\"" }' | paste -sd " " -))

# open dict
json='{
"include": [
'

# loop through each combination of variables to generate matrix components
for py_ver in "${python_version[@]}"; do
for os_type in "${os[@]}"; do
for pybamm_ver in "${pybamm_version[@]}"; do
json+='{
"os": "'$os_type'",
"python_version": "'$py_ver'",
"pybamm_version": '$pybamm_ver'
},'
done
done
done

# fix structure, removing trailing comma
json=${json%,}

# close dict
json+='
]
}'

echo "$json" | jq -c .
Loading