Borda/dataset-histology-landmarks

View on GitHub
.github/workflows/ci-testing.yml

Summary

Maintainability
Test Coverage
name: CI testing

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:  # Trigger the workflow on push or pull request, but only for the master branch
  - push
  - pull_request

jobs:
  pytest:

    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-18.04]  # , macOS-10.15
        python-version: [2.7, 3.6, 3.8]

    # Timeout: https://stackoverflow.com/a/59076067/4521646
    timeout-minutes: 15
    env:
      CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
      CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    # Note: This uses an internal pip API and may not always work
    # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow
    - name: Get pip cache
      id: pip-cache
      run: |
        python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"

    - name: Cache pip
      uses: actions/cache@v2
      with:
        path: ${{ steps.pip-cache.outputs.dir }}
        key: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ matrix.requires }}-${{ hashFiles('requirements.txt') }}
        restore-keys: |
          ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ matrix.requires }}-

    - name: Install dependencies
      run: |
        # sudo apt-get install python-opencv
        pip install "setuptools<46" -U  # v46 crashes openslide-python install
        pip install -r requirements.txt
        pip install -U check-manifest coverage pytest codecov codacy-coverage flake8
        # code coverage tool
        curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
        chmod +x ./cc-test-reporter
      shell: bash

    - name: Preparation
      run: |
        mkdir output
        python --version
        pwd ; ls -l
        ./cc-test-reporter before-build
        pip --version
        pip list

    - name: Tests
      env:
        DISPLAY: ""
      run: |
        coverage run --source handlers -m pytest handlers -v --doctest-modules --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml

    - name: Formatting
      run: |
        flake8 . --ignore=E402 --max-line-length=120

    - name: Run scripts
      run: |
        python handlers/run_evaluate_landmarks.py -a ./annotations -o ./output --visual
        python handlers/run_generate_landmarks.py -a ./annotations -d ./dataset --scales 5
        python handlers/run_visualise_landmarks.py -l ./dataset -i ./dataset -o ./output

    - name: Upload pytest test results
      uses: actions/upload-artifact@master
      with:
        name: pytest-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}
        path: junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml
      # Use always() to always run this step to publish test results when there are test failures
      if: always()

    - name: Statistics
      if: success()
      run: |
        coverage report
        coverage xml
        # upload to ...
        python-codacy-coverage -r coverage.xml
        ./cc-test-reporter after-build

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v1
      if: success()
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        file: coverage.xml
        fail_ci_if_error: false