diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml new file mode 100644 index 00000000..e63ddd49 --- /dev/null +++ b/.github/workflows/examples.yml @@ -0,0 +1,59 @@ +# Runs the examples and notebooks a pull request adds or changes against the latest QuantLibAAD +# release from PyPI; the wheels themselves are only built for changes that go into them +# (quantlib-risks.yml). An example that needs a change to the package itself fails here until +# that change is released. + +name: Examples +on: + pull_request: + branches: + - main + paths: + - ".github/workflows/examples.yml" + - "binder/requirements.txt" + - "Python/examples/**" + - "notebooks/**" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + examples: + name: Examples on the latest release + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: false + - uses: actions/setup-python@v7 + with: + python-version: "3.12" + - name: Install the latest QuantLibAAD release + run: pip install -r binder/requirements.txt + - name: Run the changed examples and notebooks + env: + BASE: ${{ github.event.pull_request.base.sha }} + MPLBACKEND: Agg + run: | + # only those the pull request adds or changes; all of them on a manual run or when this + # workflow or the requirements change + if [ -n "$BASE" ] && git diff --quiet "$BASE" HEAD -- .github/workflows/examples.yml binder/requirements.txt; then + files=$(git diff --name-only --diff-filter=AMR "$BASE" HEAD -- 'Python/examples/*.py' 'notebooks/*.ipynb') + else + files=$(ls Python/examples/*.py notebooks/*.ipynb) + fi + python -c "import QuantLibAAD, xad; print('QuantLibAAD', QuantLibAAD.__version__, 'xad', xad.__version__)" + for f in $files; do + echo "::group::$f" + case "$f" in + *.py) (cd "$(dirname "$f")" && python "$(basename "$f")") ;; + *.ipynb) jupyter nbconvert --to notebook --execute --output-dir /tmp/executed "$f" ;; + esac + echo "::endgroup::" + done diff --git a/.github/workflows/quantlib-risks.yml b/.github/workflows/quantlib-risks.yml index a240b18f..86b009bc 100644 --- a/.github/workflows/quantlib-risks.yml +++ b/.github/workflows/quantlib-risks.yml @@ -1,5 +1,5 @@ # builds only on the following conditions: -# - pull requests into main +# - pull requests into main that change what goes into the wheels (paths below) # - OR pushes of tags starting with v* # - OR manual dispatch on repo # publishes to test pypi if: @@ -17,6 +17,22 @@ on: pull_request: branches: - main + # only changes that go into the wheels; examples and notebooks are tested in examples.yml + paths: + - ".github/workflows/quantlib-risks.yml" + - ".gitmodules" + - "CMakeLists.txt" + - "LICENSE.md" + - "pyproject.toml" + - "cmake/**" + - "lib/**" + - "patches/**" + - "tools/**" + - "SWIG/**" + - "Python/CMakeLists.txt" + - "Python/QuantLibAAD/**" + - "Python/README.md" + - "Python/test/**" push: tags: - v*