duncanmmacleod/pip2conda

View on GitHub
.github/workflows/test.yml

Summary

Maintainability
Test Coverage
# -----------------------
#
# Run a full build-and-test from the git repo
# using pip to install all dependencies.
#
# -----------------------

name: Build and test

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

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

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

    strategy:
      fail-fast: false
      matrix:
        os:
          - macOS
          - Ubuntu
          - Windows
        python-version:
          - "3.10"
          - "3.11"
    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@v2
      with:
        fetch-depth: 0

    - name: Configure conda
      uses: conda-incubator/setup-miniconda@v2
      with:
        activate-environment: test
        miniforge-variant: Mambaforge
        python-version: ${{ matrix.python-version }}
        use-mamba: true
        # this is needed for caching to work properly:
        use-only-tar-bz2: true

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

    - name: Create distributions
      run: |
        # create isolated environment for build
        mamba create -n build --quiet --yes \
            python=${{ matrix.python-version }} \
            python-build \
        ;
        # create distributions
        mamba run -n build python -m build . --sdist --wheel --outdir .

    - name: Install this project with test extras
      run: |
        TARBALL=$(ls pip2conda-*.tar.*)
        python -m pip install ${TARBALL}[test]

    - name: Package list
      run: python -m pip list installed

    - name: Run pytest suite
      run: python -m pytest --cov pip2conda --junitxml=pytest.xml --pyargs pip2conda.tests -ra -v

    - name: Run over this project
      run: |
        python -m coverage run --append --module pip2conda --all --output test.yml
        cat test.yml

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

    - name: Prepare codecov upload
      run: python -m coverage xml

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

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

    - name: Upload tarball
      uses: actions/upload-artifact@v2
      with:
        name: tarball
        path: "*.tar.*"

    - name: Upload wheel(s)
      uses: actions/upload-artifact@v2
      with:
        name: wheel
        path: "*.whl"