Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update GitHub Actions (major) #10249

Update GitHub Actions (major)

Update GitHub Actions (major) #10249

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
# https://docs.renovatebot.com/key-concepts/automerge/#branch-vs-pr-automerging
- "renovate/**" # branches Renovate creates
paths-ignore:
- "docs/**"
- "CHANGELOG.md"
pull_request:
paths-ignore:
- "docs/**"
- "CHANGELOG.md"
# ignore github workflows except for the current one
- ".github/**"
- "!.github/workflows/pytest.yml"
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.10", "3.14"]
runner: ["ubuntu-latest"]
steps:
- name: Check conditions
id: conditions
run: echo "run-tests=${{ github.ref == 'refs/heads/main' || (matrix.runner == 'ubuntu-20.04' && matrix.python-version == '3.10') }}" >> "$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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
name: Check out source-code repository
- name: List tests
id: list_tests
run: |
echo "tests=$(find tests -type f -name "test_*.py" | 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:
- runs-on=${{ github.run_id }}-run-test
- runner=4cpu-linux-x64
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@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
name: Check out source-code repository
- name: Set up Python ${{ needs.setup.outputs.python-version }}
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6
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: Set up Singularity
if: ${{ matrix.test == 'test_download.py'}}
uses: eWaterCycle/setup-singularity@931d4e31109e875b13309ae1d07c70ca8fbc8537 # v7
with:
singularity-version: 3.8.3
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_ENV
- name: Install Nextflow
uses: nf-core/setup-nextflow@v2
- name: Install nf-test
uses: nf-core/setup-nf-test@v1
- name: move coveragerc file up
run: |
mv .github/.coveragerc .
- name: Test with pytest
id: pytest
run: |
python3 -m pytest tests/${{matrix.test}} --color=yes --cov --cov-config=.coveragerc --durations=0 -n auto && 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: remove slashes from test name
run: |
test=$(echo ${{ matrix.test }} | sed 's/\//__/g')
echo "test=${test}" >> $GITHUB_ENV
- name: Store snapshot report
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
if: always() && contains(matrix.test, 'test_create_app') && steps.pytest.outcome == 'failure'
with:
include-hidden-files: true
name: Snapshot Report ${{ env.test }}
path: ./snapshot_report.html
- name: Upload coverage
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
include-hidden-files: true
name: coverage_${{ env.test }}
path: .coverage
coverage:
needs: test
runs-on:
- runs-on=${{ github.run_id }}-coverage
- runner=2cpu-linux-x64
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Set up Python 3.14
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6
with:
python-version: "3.14"
cache: "pip"
- name: Install coverage
run: |
python -m pip install --upgrade pip coverage
- name: move coveragerc file up
run: |
mv .github/.coveragerc .
- name: Download all artifacts
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
pattern: coverage_*
- name: Run coverage
run: |
coverage combine --keep coverage_*/.coverage*
coverage report
coverage xml
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5
with:
files: coverage.xml
disable_search: true # we already know the file to upload
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}