-
Notifications
You must be signed in to change notification settings - Fork 248
151 lines (133 loc) · 5.36 KB
/
Copy pathpytest.yml
File metadata and controls
151 lines (133 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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:
inputs:
nextflow-version:
description: "Nextflow version to test against"
required: false
default: "latest-stable"
# 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:
# 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
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 ${{ matrix.python-version }} and Nextflow ${{ matrix.nextflow-version }}
needs: list_tests
runs-on:
- runs-on=${{ github.run_id }}-run-test
- runner=4cpu-linux-x64
strategy:
matrix:
# On PRs to main test with 3.10 and 3.14, otherwise just 3.10
python-version: ${{ github.base_ref == 'main' && fromJson('["3.10", "3.14"]') || fromJson('["3.10"]') }}
test: ${{ fromJson(needs.list_tests.outputs.tests).test }}
# On push/release test both NF versions, otherwise just 25.10.4
# Note: python×nextflow must stay ≤2 with 88 tests to stay under GitHub's 256-config limit
nextflow-version: ${{ (github.event_name == 'push' || github.event_name == 'release') && fromJson('["25.10.4", "latest-stable"]') || fromJson('["25.10.4"]') }}
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
name: Check out source-code repository
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: ${{ matrix.python-version }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
enable-cache: true
- name: Install dependencies
run: uv sync --all-extras
- name: Set up Apptainer
if: ${{ startsWith(matrix.test, 'pipelines/download/') }}
uses: eWaterCycle/setup-apptainer@4bb22c52d4f63406c49e94c804632975787312b3 # v2.0.0
- name: Install Nextflow
uses: nf-core/setup-nextflow@b4ec1bc7c16a94435159de94a05253542fddf6ef # v3
with:
version: ${{ github.event.inputs.nextflow-version || matrix.nextflow-version }}
- name: Install nf-test
uses: nf-core/setup-nf-test@4069fbbaabe94c08faba4ad261bfa88225ba133f # v2
with:
version: 0.9.5
install-fast-diff: true
- name: move coveragerc file up
run: |
mv .github/.coveragerc .
- name: Test with pytest
id: pytest
run: |
uv run python -m pytest tests/${{matrix.test}} --color=yes --cov --cov-config=.coveragerc --durations=0 -n logical && 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: Generate coverage XML
if: always()
run: |
uv run coverage xml --rcfile=.coveragerc
- name: Upload coverage to Codecov
if: always()
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6
with:
files: ./coverage.xml
flags: python-${{ matrix.python-version }}
env_vars: MATRIX_TEST
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
MATRIX_TEST: ${{ matrix.test }}
- 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@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
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