Skip to content

Testing

Testing #8185

Workflow file for this run

name: Testing
on:
push:
branches:
- main
paths-ignore:
- CHANGELOG.rst
- README.rst
- pyproject.toml
- xclim/__init__.py
pull_request:
types:
- opened
- reopened
- synchronize
pull_request_review:
types:
- submitted
env:
XCLIM_TESTDATA_BRANCH: v2024.8.23
concurrency:
# For a given workflow, if we push to the same branch, cancel all previous builds on that branch except on main.
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
permissions:
contents: read
pull-requests: read
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
if: |
(github.event.action != 'labeled') ||
(github.event.review.state == 'approved') ||
(github.event_name == 'push')
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
files.pythonhosted.org:443
github.com:443
pypi.org:443
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python3
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: "3.x"
cache: 'pip'
- name: Install CI libraries
run: |
python -m pip install --require-hashes -r CI/requirements_ci.txt
- name: Environment Caching
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
${{ matrix.testdata-cache }}
.tox
key: ${{ runner.os }}-xclim-testdata-${{ env.XCLIM_TESTDATA_BRANCH }}-${{ hashFiles('pyproject.toml', 'tox.ini') }}-lint
- name: Run pylint
run: |
python -m pylint --rcfile=.pylintrc.toml --disable=import-error --exit-zero xclim
- name: Run linting suite
run: |
python -m tox -e lint
test-preliminary:
name: Python${{ matrix.python-version }} (${{ matrix.os }})
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
os: [ 'ubuntu-latest' ]
python-version: [ "3.10" ]
testdata-cache: [ '~/.cache/xclim-testdata' ]
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
dap.service.does.not.exist:443
files.pythonhosted.org:443
github.com:443
pypi.org:443
raw.githubusercontent.com:443
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up Python${{ matrix.python-version }}
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install CI libraries
run: |
python -m pip install --require-hashes -r CI/requirements_ci.txt
- name: Environment Caching
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
${{ matrix.testdata-cache }}
.tox
key: ${{ runner.os }}-xclim-testdata-${{ env.XCLIM_TESTDATA_BRANCH }}-${{ hashFiles('pyproject.toml', 'tox.ini') }}-Python${{ matrix.python-version }}
- name: Test with tox
run: |
python -m tox -- -m 'not slow'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
test-pypi:
needs: lint
name: Python${{ matrix.python-version }} (${{ matrix.os }}, ${{ matrix.tox-env }})
if: |
contains(github.event.pull_request.labels.*.name, 'approved') ||
(github.event.review.state == 'approved') ||
(github.event_name == 'push')
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
matrix:
include:
# Linux builds
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: -m 'not slow'
python-version: "3.10"
tox-env: standard
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: -m 'not slow'
python-version: "3.11"
tox-env: standard
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: -m 'not slow'
python-version: "3.12"
tox-env: standard
# Windows builds
- os: 'windows-latest'
testdata-cache: 'C:\Users\runneradmin\AppData\Local\xclim-testdata\xclim-testdata\Cache'
markers: -m 'not slow'
python-version: "3.10"
tox-env: py310-coverage-prefetch # Test data prefetch is needed for Windows
# macOS builds
- os: 'macos-latest'
testdata-cache: '~/Library/Caches/xclim-testdata'
markers: '' # Slow tests
python-version: "3.11"
tox-env: py311-coverage-extras
# Specialized tests
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: -m 'not requires_internet and not slow'
python-version: "3.11"
tox-env: py311-coverage-sbck-offline-prefetch
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: '' # No markers for notebooks
python-version: "3.10"
tox-env: notebooks
- os: 'ubuntu-latest'
testdata-cache: '~/.cache/xclim-testdata'
markers: '' # No markers for doctests
python-version: "3.12"
tox-env: doctests
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
azure.archive.ubuntu.com:80
coveralls.io:443
dap.service.does.not.exist:443
esm.ubuntu.com:443
files.pythonhosted.org:443
github.com:443
motd.ubuntu.com:443
packages.microsoft.com:443
ppa.launchpadcontent.net:443
pypi.org:443
raw.githubusercontent.com:443
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Eigen3 (SBCK)
if: ${{ matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get update
sudo apt-get install libeigen3-dev
- name: Set up Python${{ matrix.python-version }}
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install CI libraries
run: |
python -m pip install --require-hashes -r CI/requirements_ci.txt
- name: Environment Caching
# if prefetch is not in tox-env
if: contains(matrix.tox-env, 'prefetch') == false
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
${{ matrix.testdata-cache }}
.tox
key: ${{ runner.os }}-xclim-testdata-${{ env.XCLIM_TESTDATA_BRANCH }}-${{ hashFiles('pyproject.toml', 'tox.ini') }}-Python${{ matrix.python-version }}
- name: Test with tox
if: ${{ matrix.tox-env == 'standard' }}
run: |
python -m tox -- ${{ matrix.markers }};
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: run-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.tox-env }}
COVERALLS_PARALLEL: true
- name: Test with tox (specialized tests)
if: ${{ matrix.tox-env != 'standard' }}
run: |
python -m tox -e ${{ matrix.tox-env }} -- ${{ matrix.markers }};
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: run-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.tox-env }}
COVERALLS_PARALLEL: true
test-conda:
needs: lint
name: Python${{ matrix.python-version }} (${{ matrix.os }}, conda)
if: |
contains(github.event.pull_request.labels.*.name, 'approved') ||
(github.event.review.state == 'approved') ||
(github.event_name == 'push')
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ 'ubuntu-latest' ]
python-version: [ "3.10", "3.12" ]
testdata-cache: [ '~/.cache/xclim-testdata' ]
defaults:
run:
shell: bash -l {0}
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
conda.anaconda.org:443
coveralls.io:443
dap.service.does.not.exist:443
files.pythonhosted.org:443
github.com:443
objects.githubusercontent.com:443
pypi.org:443
raw.githubusercontent.com:443
repo.anaconda.com:443
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Conda (Micromamba) with Python${{ matrix.python-version }}
uses: mamba-org/setup-micromamba@ab6bf8bf7403e8023a094abeec19d6753bdc143e # v2.0.1
with:
cache-downloads: true
cache-environment: true
environment-file: environment.yml
create-args: >-
python=${{ matrix.python-version }}
- name: Micromamba version
run: |
echo "micromamba: $(micromamba --version)"
- name: Test Data Caching
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: |
${{ matrix.testdata-cache }}
key: ${{ runner.os }}-xclim-testdata-${{ env.XCLIM_TESTDATA_BRANCH }}-conda-${{ hashFiles('pyproject.toml', 'tox.ini') }}-Python${{ matrix.python-version }}
- name: Install xclim
run: |
python -m pip install --no-user --editable .
- name: Check versions
run: |
micromamba list
xclim show_version_info
python -m pip check || true
- name: Test with pytest
run: |
python -m pytest --numprocesses=logical --durations=10 --cov=xclim --cov-report=term-missing
# - name: Install tox
# shell: bash -l {0}
# run: |
# mamba install -n xclim39 tox tox-conda
# - name: Test
# shell: bash -l {0}
# run: |
# conda activate xclim39
# tox -e opt-slow
# env:
# CONDA_EXE: mamba
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Report coverage
run: |
coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: run-{{ matrix.python-version }}-conda
COVERALLS_PARALLEL: true
finish:
needs:
- test-preliminary
- test-pypi
- test-conda
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: audit
- name: Coveralls Finished
uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8 # v2.3.4
with:
parallel-finished: true