Skip to content

Implement CMIP7 support: ControlledVocabularies and GlobalAttributes #1697

Implement CMIP7 support: ControlledVocabularies and GlobalAttributes

Implement CMIP7 support: ControlledVocabularies and GlobalAttributes #1697

Workflow file for this run

# For more information see: https://tinyurl.com/mr4y7r8n
name: Run Basic Tests
on:
push:
# Prototype and future branches get their own tests...
branches: ["main", "prep-release", "prototype/*", "future/*"]
tags: ["v*.*.*"]
pull_request:
# ...and everything else is a PR!
branches: ["main", "prep-release"]
jobs:
# Setup job for linting and formatting checks
lint_and_format:
name: Lint and Format Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install black flake8 pytest isort yamllint
- name: Install package for linting
run: |
python -m pip install .[dev]
- name: Lint with flake8 (syntax errors only)
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Run full flake8 check
run: |
# stop at any error
flake8 . --show-source --statistics --exclude ./cmip6-cmor-tables,./build,_version.py,./src/pycmor/webapp.py,./CMIP7_DReq_Software
- name: Run isort
run: |
isort --profile black --check --skip ./cmip6-cmor-tables --skip ./versioneer.py --skip ./CMIP7_DReq_Software .
- name: Run black
run: |
black --check --extend-exclude 'cmip6-cmor-tables|CMIP7_DReq_Software|versioneer\.py|webapp\.py' .
- name: Run yamllint
run: |
yamllint .
# Main test job that runs on multiple Python versions
test:
name: Test Python ${{ matrix.python-version }}
needs: [lint_and_format]
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up NetCDF4 with HDF5 support
run: |
sudo apt-get update
sudo apt-get install -y libnetcdf-dev libhdf5-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if ${{ matrix.python-version == '3.12' }}; then pip install --upgrade setuptools; fi
- name: Install package
run: |
python -m pip install ".[dev, fesom]"
- name: Test if data will work (Meta-Test)
run: |
export HDF5_DEBUG=1
export NETCDF_DEBUG=1
export PYCMOR_XARRAY_OPEN_MFDATASET_ENGINE=h5netcdf
export PYCMOR_XARRAY_OPEN_MFDATASET_PARALLEL=no
export PREFECT_SERVER_EPHEMERAL_STARTUP_TIMEOUT_SECONDS=300
pytest -vvv -s --cov=src/pycmor tests/meta/**.py
- name: Test with pytest (Unit)
run: |
export PYCMOR_XARRAY_OPEN_MFDATASET_ENGINE=h5netcdf
export PYCMOR_XARRAY_OPEN_MFDATASET_PARALLEL=no
export PREFECT_SERVER_EPHEMERAL_STARTUP_TIMEOUT_SECONDS=300
pytest -vvv -s --cov=src/pycmor --cov-append tests/unit/**.py
- name: Test with pytest (Integration)
run: |
export PYCMOR_XARRAY_OPEN_MFDATASET_ENGINE=h5netcdf
export PYCMOR_XARRAY_OPEN_MFDATASET_PARALLEL=no
export PREFECT_SERVER_EPHEMERAL_STARTUP_TIMEOUT_SECONDS=300
pytest -vvv -s --cov=src/pycmor --cov-append tests/integration/**.py
- name: Test with doctest
run: |
export PREFECT_SERVER_EPHEMERAL_STARTUP_TIMEOUT_SECONDS=300
PYTHONPATH=src pytest -v --doctest-modules --cov=src/pycmor --cov-append src/
- name: Generate coverage report
run: |
python -m coverage xml -o coverage-${{ matrix.python-version }}.xml
- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-reports-${{ matrix.python-version }}
path: coverage-${{ matrix.python-version }}.xml
post-status:
name: Post Status for other jobs
needs: [lint_and_format, test]
runs-on: ubuntu-latest
steps:
- name: Set output for lint and test status
id: set-output
run: |
echo "::set-output name=test_status::success"
echo "::set-output name=lint_status::success"
echo "lint_status=success" >> $GITHUB_ENV
echo "test_status=success" >> $GITHUB_ENV
echo "lint_status=success" >> $GITHUB_OUTPUT
echo "test_status=success" >> $GITHUB_OUTPUT
set-output:
name: Set Output for Ref
runs-on: ubuntu-latest
needs: [lint_and_format, test]
outputs:
ref: ${{ steps.set-ref.outputs.ref }}
is_tag: ${{ steps.set-ref.outputs.is_tag }}
steps:
- name: Determine if Ref is a Tag
id: set-ref
run: |
echo "ref=${GITHUB_REF}" >> $GITHUB_OUTPUT
if [[ "${GITHUB_REF}" =~ ^refs/tags/ ]]; then
echo "is_tag=true" >> $GITHUB_OUTPUT
else
echo "is_tag=false" >> $GITHUB_OUTPUT
fi
echo "cat ${GITHUB_OUTPUT}"
cat $GITHUB_OUTPUT
set-workflow-artifact:
name: Set workflow artifact
runs-on: ubuntu-latest
needs: set-output
steps:
- name: Create artifact
run: |
echo "Creating artifact..."
echo "ref=$REF"
echo "is_tag=$IS_TAG"
echo "ref=$REF" >> status.dat
echo "is_tag=$IS_TAG" >> status.dat
env:
REF: ${{ needs.set-output.outputs.ref }}
IS_TAG: ${{ needs.set-output.outputs.is_tag }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: status-${{ github.run_id }}
path: status.dat
# Combined test coverage report
coverage:
name: Generate Coverage Report
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-cov coverage
- name: Download coverage reports
uses: actions/download-artifact@v4
with:
path: coverage-reports
- name: Process coverage reports
run: |
# Create directories for each Python version
mkdir -p coverage-output/3.9 coverage-output/3.10 coverage-output/3.11 coverage-output/3.12
# Copy coverage reports to their respective directories
for version in 3.9 3.10 3.11 3.12; do
cp coverage-reports/coverage-reports-$version/coverage-$version.xml coverage-output/$version/coverage.xml
done
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
directory: ./coverage-output/
fail_ci_if_error: false
flags: python-3.9,python-3.10,python-3.11,python-3.12
token: ${{ secrets.CODECOV_TOKEN }}
slug: esm-tools/pycmor