gwastro/sbank

View on GitHub
.github/workflows/build.yml

Summary

Maintainability
Test Coverage
# -----------------------
#
# Run a full build-and-test from the git repo
# using a combination of conda and pip to install
# all optional dependencies.
#
# This is the 'full' test suite.
#
# -----------------------

name: Build and test

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

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

    strategy:
      fail-fast: false
      matrix:
        os:
          - macOS
          - Ubuntu
        python-version:
          - "3.8"
          - "3.9"
          - "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: Cache conda packages
      uses: actions/cache@v1
      env:
        # increment to reset cache
        CACHE_NUMBER: 0
      with:
        path: ~/conda_pkgs_dir
        key: ${{ runner.os }}-conda-${{ matrix.python-version}}-${{ env.CACHE_NUMBER }}

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

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

    - name: Install build dependencies
      run: |
        conda install --quiet --yes \
            c-compiler \
            coverage \
            cython \
            lalsuite \
            numpy \
            pip \
            setuptools \
        ;
        python -m pip install -r requirements.txt

    - name: Install SBank
      # notes:
      # - `--coverage` enables coverage reporting for the C library
      # - CYTHON_LINETRACE=1 enables coverage reporting for the Cython library
      # - we use `--editable .` so that the Cython library is installed in-place,
      #   which helps with the coverage
      # - `-vv` gives us verbose output for the compilation,
      # - `--no-build-isolation` tells pip not to ignore the already-installed
      #   build requirements, which greatly cuts down on the output from `-vv`
      run: CFLAGS="${CFLAGS} --coverage" CYTHON_LINETRACE=1 python -m pip install --editable . --no-build-isolation -vv

    - name: Package list
      run: conda list --name test

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

    - name: Run command-line tests
      run: |
        for script in ${CONDA_PREFIX}/bin/sbank*; do
            python -m coverage run \
                --append \
                --source=sbank \
                ${script} --help
        done

    - name: Run short sbank executable tests
      run: bash tools/test_sbank.sh

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

    - name: Prepare codecov upload
      run: |
        # covert report to XML (codecov can't handle sqlite, probably)
        python -m coverage xml
        rm -fv .coverage

    - name: Publish coverage to Codecov
      uses: codecov/codecov-action@v2
      with:
        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