Skip to content

use pdiff also on gitpod for nf-test #5878

use pdiff also on gitpod for nf-test

use pdiff also on gitpod for nf-test #5878

Workflow file for this run

name: Python tests
# This workflow is triggered on pushes and PRs to the repository.
# Only run if we changed a Python file
on:
push:
branches:
- dev
paths-ignore:
- "docs/**"
- "CHANGELOG.md"
pull_request:
paths-ignore:
- "docs/**"
- "CHANGELOG.md"
release:
types: [published]
workflow_dispatch:
# Cancel if a newer run with the same workflow name is queued
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
setup:
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.8", "3.11"]
runner: ["ubuntu-latest"]
include:
- python-version: "3.8"
runner: "ubuntu-20.04"
steps:
- name: Check conditions
id: conditions
run: echo "run-tests=${{ github.ref == 'refs/heads/master' || (matrix.runner == 'ubuntu-20.04' && matrix.python-version == '3.8') }}" >> "$GITHUB_OUTPUT"
outputs:
python-version: ${{ matrix.python-version }}
runner: ${{ matrix.runner }}
run-tests: ${{ steps.conditions.outputs.run-tests }}
# create a test matrix based on all python files in /tests
list_tests:
name: Get test file matrix
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
name: Check out source-code repository
- name: List tests
id: list_tests
run: |
echo "tests=$(find tests/test_* | tac | sed 's/tests\///g' | jq -R -s -c '{test: (split("\n")[:-1])}')" >> $GITHUB_OUTPUT
outputs:
tests: ${{ steps.list_tests.outputs.tests }}
test:
name: Run ${{matrix.test}} with Python ${{ needs.setup.outputs.python-version }} on ${{ needs.setup.outputs.runner }}
needs: [setup, list_tests]
if: ${{ needs.setup.outputs.run-tests }}
runs-on: self-hosted
strategy:
matrix: ${{ fromJson(needs.list_tests.outputs.tests) }}
fail-fast: false # run all tests even if one fails
steps:
- name: go to subdirectory and change nextflow workdir
run: |
mkdir -p pytest
cd pytest
export NXF_WORK=$(pwd)
- uses: actions/checkout@v4
name: Check out source-code repository
- name: Set up Python ${{ needs.setup.outputs.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ needs.setup.outputs.python-version }}
cache: "pip"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip -r requirements-dev.txt
pip install -e .
- name: Downgrade git to the Ubuntu official repository's version
if: ${{ needs.setup.outputs.runner == 'ubuntu-20.04' && needs.setup.outputs.python-version == '3.8' }}
run: |
sudo apt update
sudo apt remove -y git git-man
sudo add-apt-repository --remove ppa:git-core/ppa
sudo apt install -y git
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_ENV
- name: Install Nextflow
uses: nf-core/setup-nextflow@v1
- name: Look if nf-test is already installed and write to env variable
id: check-nftest
run: |
if [ -f /usr/local/bin/nf-test ]; then
echo "nftest_installed=true" >> $GITHUB_ENV
else
echo "nftest_installed=false" >> $GITHUB_ENV
fi
- name: Cache nf-test installation
if: env.nftest_installed != 'true'
id: cache-software
uses: actions/cache@v3
with:
path: |
/usr/local/bin/nf-test
/home/runner/.nf-test/nf-test.jar
key: ${{ runner.os }}-nftest-${{ env.date }}
- name: Install nf-test
if: steps.cache-software.outputs.cache-hit != 'true' && env.nftest_installed != 'true'
run: |
wget -qO- https://code.askimed.com/install/nf-test | bash
sudo mv nf-test /usr/local/bin/
- name: move coveragerc file up
run: |
mv .github/.coveragerc .
- name: Test with pytest
run: |
python3 -m pytest tests/${{matrix.test}} --color=yes --cov --durations=0 && exit_code=0|| exit_code=$?
# don't fail if no tests were collected, e.g. for test_licence.py
if [ "${exit_code}" -eq 5 ]; then
echo "No tests were collected"
exit 0
elif [ "${exit_code}" -ne 0 ]; then
echo "Tests failed with exit code ${exit_code}"
exit 1
fi
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.test }}
path: .coverage
coverage:
needs: test
runs-on: self-hosted
steps:
- name: go to subdirectory
run: |
mkdir -p pytest
cd pytest
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
env:
AGENT_TOOLSDIRECTORY: /opt/actions-runner/_work/tools/tools/
with:
python-version: 3.11
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip -r requirements-dev.txt
pip install -e .
- name: move coveragerc file up
run: |
mv .github/.coveragerc .
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Run coverage
run: |
coverage combine --keep coverage*/.coverage*
coverage report
coverage xml
- uses: codecov/codecov-action@v3
with:
files: coverage.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}