duncanmmacleod/requests-ecp

View on GitHub
.github/workflows/conda.yml

Summary

Maintainability
Test Coverage
name: Conda test

on:
  push:
    branches:
      - main
      - release/**
  pull_request:
    branches:
      - main
      - release/**

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  conda:
    name: Python ${{ matrix.python-version }} (${{ matrix.os }} | conda)

    strategy:
      fail-fast: false
      matrix:
        os:
          - macOS
          - Ubuntu
          - Windows
        python-version:
          - "3.8"
          - "3.9"
          - "3.10"
          - "3.11"
          - "3.12"
    runs-on: ${{ matrix.os }}-latest

    # this is needed for conda environments to activate automatically
    defaults:
      run:
        shell: bash -el {0}

    steps:
      - name: Get source code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Cache conda packages
        uses: actions/cache@v3
        env:
          # increment to reset cache
          CACHE_NUMBER: 0
        with:
          path: ~/conda_pkgs_dir
          key: ${{ runner.os }}-conda-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}
          restore-keys: ${{ runner.os }}-conda-${{ matrix.python-version }}-

      - name: Configure conda
        uses: conda-incubator/setup-miniconda@v2
        with:
          activate-environment: test
          miniforge-variant: Mambaforge
          python-version: ${{ matrix.python-version }}
          use-mamba: true

      - name: Conda info
        run: conda info --all

      - name: Install dependencies with pip2conda
        run: |
          mamba create --quiet --yes --name pip2conda pip2conda
          mamba run --name pip2conda python -m pip2conda \
              --all \
              --output requirements.txt \
              --python-version ${{ matrix.python-version }} \
          ;
          echo "-----------------"
          cat requirements.txt
          echo "-----------------"
          mamba install --quiet --yes --name test --file requirements.txt

      - name: Install requests-ecp
        run: python -m pip install . -v

      - name: Package list
        run: mamba list --name test

      - name: Run test suite
        run: python -m pytest -ra --color yes --cov requests_ecp --pyargs requests_ecp --cov-report=xml --junitxml=pytest.xml

      - name: Coverage report
        run: python -m coverage report --show-missing

      - name: Publish coverage to Codecov
        uses: codecov/codecov-action@v3
        with:
          files: coverage.xml
          flags: ${{ runner.os }},conda,python${{ matrix.python-version }}

      - name: Upload test results
        if: always()
        uses: actions/upload-artifact@v3
        with:
          name: pytest-conda-${{ matrix.os }}-${{ matrix.python-version }}
          path: pytest.xml