misc. #5
This file contains 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
# This workflow will install Python dependencies, run pytests and run notebooks | |
# then it will in python 3.9 (ubuntu-latest) create a badge with the coverage | |
# and add it to the PR. This badge will be updated if the PR is updated. | |
name: Tests | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
pytest: | |
runs-on: ${{ matrix.os }} | |
permissions: | |
contents: read | |
issues: read | |
checks: write | |
pull-requests: write | |
strategy: | |
matrix: | |
os: [ubuntu-latest] #, macos-latest, windows-latest] | |
python-version: ["3.9"] # , "3.10"] | |
# This allows a subsequently queued workflow run to interrupt previous runs | |
concurrency: | |
group: "${{ github.workflow }}-${{ matrix.python-version}}-${{ matrix.os }} @ ${{ github.ref }}" | |
cancel-in-progress: true | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Cache tox | |
uses: actions/[email protected] | |
id: cache_tox | |
with: | |
path: | | |
.tox | |
key: ${{ runner.os }}-${{ matrix.python-version }}-tests | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
shell: bash | |
run: | | |
pip install invoke tox | |
- name: Run and write pytest | |
shell: bash | |
run: | | |
# Specifying two sets of "--pytest-args" is required for invoke to parse it as a list | |
inv test --pytest-args="--durations=0" --pytest-args="--junitxml=pytest.xml --cov-report=term-missing --cov=src/" | |
- name: Test report on failures | |
uses: EnricoMi/publish-unit-test-result-action@v2 | |
id: test_report_with_annotations | |
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' && github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' && (success() || failure()) }} # Do not run for dependabot, run whether tests failed or succeeded | |
with: | |
comment_mode: "failures" | |
files: | | |
pytest.xml | |
- name: Pytest coverage comment | |
id: coverage-comment | |
uses: MishaKav/pytest-coverage-comment@main | |
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' && github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' && (success() || failure()) }} | |
with: | |
create-new-comment: false | |
report-only-changed-files: false | |
pytest-coverage-path: pytest-coverage.txt | |
junitxml-path: ./pytest.xml |