Tests #2432
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: Tests | |
on: | |
# Uncomment this entry only to debug the workflow | |
# pull_request: | |
# branches: [ main ] | |
pull_request_target: | |
branches: [ main ] | |
types: [ labeled, opened, reopened, synchronize ] | |
# 05:00 UTC = 06:00 CET = 07:00 CEST | |
schedule: | |
- cron: "0 5 * * *" | |
# Cancel previous runs that have not completed | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
GAMS_VERSION: 43.4.1 # First version including a macOS arm64 distribution | |
depth: 100 # Must be large enough to include the most recent release | |
label: "safe to test" | |
jobs: | |
check: | |
name: check permissions | |
runs-on: ubuntu-latest | |
steps: | |
- if: > | |
!( | |
github.event_name == 'schedule' | |
|| github.repository == github.event.pull_request.head.repo.full_name | |
|| contains(github.event.pull_request.labels.*.name, env.label) | |
) | |
run: | | |
echo "Pytest workflow will not run for branch in fork without label \`${{ env.label }}\`." >>$GITHUB_STEP_SUMMARY | |
exit 1 | |
pytest: | |
needs: [ check ] | |
strategy: | |
matrix: | |
os: | |
- macos-13 | |
- macos-latest | |
- ubuntu-latest | |
- windows-latest | |
python-version: | |
- "3.9" # Earliest version supported by message_ix | |
- "3.10" | |
- "3.11" | |
- "3.12" | |
- "3.13" # Latest version supported by message_ix | |
# Below this comment are newly released or development versions of | |
# Python. For these versions, binary wheels are not available for some | |
# dependencies, e.g. llvmlite, numba, numpy, and/or pandas. Compiling | |
# these on the job runner requires a more elaborate build environment, | |
# currently out of scope for the message_ix project. | |
# - "3.14.0-alpha.1" # Development version | |
exclude: | |
# Specific version combinations that are invalid / not to be used | |
# No arm64 distributions of JPype for these Pythons | |
- { os: macos-latest, python-version: "3.9" } | |
# Redundant with macos-latest | |
- { os: macos-13, python-version: "3.10" } | |
- { os: macos-13, python-version: "3.11" } | |
- { os: macos-13, python-version: "3.12" } | |
- { os: macos-13, python-version: "3.13" } | |
fail-fast: false | |
runs-on: ${{ matrix.os }} | |
name: ${{ matrix.os }}-py${{ matrix.python-version }} | |
steps: | |
- name: Check out message_ix | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: ${{ env.depth }} | |
ref: ${{ github.event_name != 'pull_request_target' && github.ref || github.event.pull_request.head.sha }} | |
- name: Fetch tags (for setuptools-scm) | |
run: git fetch --tags --depth=${{ env.depth }} | |
- name: Set up uv, Python | |
uses: astral-sh/setup-uv@v5 | |
with: | |
cache-dependency-glob: "**/pyproject.toml" | |
python-version: ${{ matrix.python-version }} | |
- uses: ts-graphviz/setup-graphviz@v2 | |
# Work around ts-graphviz/setup-graphviz#630 | |
if: matrix.os != 'macos-13' | |
- name: Cache GAMS installer | |
uses: actions/cache@v4 | |
with: | |
path: | | |
gams | |
key: ${{ matrix.os }}-gams${{ env.GAMS_VERSION }} | |
restore-keys: | | |
${{ matrix.os }}- | |
- uses: iiasa/actions/setup-gams@main | |
with: | |
version: ${{ env.GAMS_VERSION }} | |
license: ${{ secrets.GAMS_LICENSE }} | |
- name: Install the package and dependencies | |
# By default, the below installs ixmp from the main branch. To run against | |
# other code, e.g. other branches for open PRs), temporarily edit as | |
# appropriate. DO NOT merge such changes to `main`. | |
run: | | |
uv pip install --upgrade "ixmp @ git+https://github.com/iiasa/ixmp.git@main" | |
uv pip install .[tests] | |
- name: Run test suite using pytest | |
env: | |
# For test_cli.test_dl; see code in message_ix.cli.dl | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
pytest message_ix \ | |
-m "not nightly and not tutorial" \ | |
--color=yes --durations=20 -rA --verbose \ | |
--cov-report=xml \ | |
--numprocesses=auto --dist=loadgroup | |
shell: bash | |
- name: Upload test coverage to Codecov.io | |
uses: codecov/codecov-action@v5 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
tutorials: | |
needs: [ check ] | |
strategy: | |
matrix: | |
os: | |
- macos-latest | |
- ubuntu-latest | |
- windows-latest | |
fail-fast: false | |
runs-on: ${{ matrix.os }} | |
name: ${{ matrix.os }} tutorials | |
steps: | |
- name: Check out message_ix | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: ${{ env.depth }} | |
ref: ${{ github.event_name != 'pull_request_target' && github.ref || github.event.pull_request.head.sha }} | |
- name: Set up uv, Python | |
uses: astral-sh/setup-uv@v5 | |
with: | |
cache-dependency-glob: "**/pyproject.toml" | |
python-version: "3.13" | |
- name: Set RETICULATE_PYTHON | |
# Retrieve the Python executable set up above | |
run: echo "RETICULATE_PYTHON=$(uv python find)" >> "$GITHUB_ENV" | |
shell: bash | |
- uses: r-lib/actions/setup-r@v2 | |
id: setup-r | |
with: | |
windows-path-include-rtools: false | |
- name: Cache GAMS installer and R packages | |
uses: actions/cache@v4 | |
with: | |
path: | | |
gams | |
${{ env.R_LIBS_USER }} | |
key: tutorial-${{ matrix.os }}-gams${{ env.GAMS_VERSION }}-R${{ steps.setup-r.outputs.installed-r-version }} | |
restore-keys: | | |
tutorial-${{ matrix.os }}-gams${{ env.GAMS_VERSION }}- | |
tutorial-${{ matrix.os }}- | |
- uses: iiasa/actions/setup-gams@main | |
with: | |
version: ${{ env.GAMS_VERSION }} | |
license: ${{ secrets.GAMS_LICENSE }} | |
- name: Install the package and dependencies | |
# By default, the below installs ixmp from the main branch. To run against | |
# other code, e.g. other branches for open PRs), temporarily edit as | |
# appropriate. DO NOT merge such changes to `main`. | |
run: | | |
uv pip install --upgrade "ixmp @ git+https://github.com/iiasa/ixmp.git@main" | |
uv pip install .[tests] | |
- name: Install R dependencies and tutorial requirements | |
run: | | |
install.packages(c("dplyr", "IRkernel", "reticulate")) | |
IRkernel::installspec() | |
shell: Rscript {0} | |
- name: Run test suite using pytest | |
run: | | |
pytest message_ix \ | |
-m "tutorial" \ | |
--color=yes --durations=20 -rA --verbose \ | |
--cov-report=xml \ | |
--numprocesses=auto --dist=loadgroup | |
shell: bash | |
- name: Upload test coverage to Codecov.io | |
uses: codecov/codecov-action@v5 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} # required | |
pre-commit: | |
name: Code quality | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event_name != 'pull_request_target' && github.ref || github.event.pull_request.head.sha }} | |
- uses: astral-sh/setup-uv@v5 | |
with: { cache-dependency-glob: "**/pyproject.toml" } | |
- uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pre-commit | |
key: pre-commit|${{ env.UV_PYTHON }}|${{ hashFiles('.pre-commit-config.yaml') }} | |
lookup-only: ${{ github.event_name == 'schedule' }} # Set 'true' to recreate cache | |
- run: uvx pre-commit run --all-files --color=always --show-diff-on-failure |