Add more ruff rules (B, PTH, RSE, SIM, C4, BLE, A) #11479
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | |
| # 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 }} on ubuntu-latest | |
| needs: list_tests | |
| runs-on: | |
| - runs-on=${{ github.run_id }}-run-test | |
| - runner=4cpu-linux-x64 | |
| strategy: | |
| matrix: | |
| # On main branch 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 }} | |
| 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@5a095e7a2014a4212f075830d4f7277575a9d098 # v7 | |
| 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 | |
| with: | |
| apptainer-version: 1.3.4 | |
| - 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: | | |
| 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@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5 | |
| 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@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # 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 |