tox pytests #324
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
| # Additional copyright: Joachim Jablon, kieferro (MIT license) | |
| name: tox pytests | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - dev | |
| pull_request: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 5 * * 6" # 5:00 UTC every Saturday | |
| jobs: | |
| pytest: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.11", "3.12", "3.13", "3.14"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install tox tox-gh-actions coverage | |
| - name: Test with tox | |
| run: tox | |
| env: | |
| COVERAGE_FILE: ".coverage.${{ matrix.python-version }}" | |
| # The file name prefix must be ".coverage." for "coverage combine" | |
| # enabled by "MERGE_COVERAGE_FILES: true" to work. A "subprocess" | |
| # error with the message "No data to combine" will be triggered if | |
| # this prefix is not used. | |
| - name: Check test coverage | |
| run: coverage report -m --fail-under=85 | |
| env: | |
| COVERAGE_FILE: ".coverage.${{ matrix.python-version }}" | |
| - name: Store coverage file | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-${{ matrix.python-version }} | |
| path: .coverage.${{ matrix.python-version }} | |
| # By default hidden files/folders (i.e. starting with .) are ignored. | |
| # You may prefer (for security reasons) not setting this and instead | |
| # set COVERAGE_FILE above to not start with a `.`, but you cannot | |
| # use "MERGE_COVERAGE_FILES: true" later on and need to manually | |
| # combine the coverage file using "pipx run coverage combine" | |
| include-hidden-files: true | |
| coverage: | |
| name: Coverage | |
| runs-on: ubuntu-latest | |
| needs: pytest | |
| permissions: | |
| pull-requests: write | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # This is optional since by default it's to true. The git | |
| # operations in python-coverage-comment-action utilize the token | |
| # stored by actions/checkout. | |
| persist-credentials: true | |
| - uses: actions/download-artifact@v4 | |
| id: download | |
| with: | |
| pattern: coverage-* | |
| merge-multiple: true | |
| - name: Coverage comment | |
| id: coverage_comment | |
| uses: py-cov-action/python-coverage-comment-action@v3 | |
| with: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| MERGE_COVERAGE_FILES: true | |
| - name: Store Pull Request comment to be posted | |
| uses: actions/upload-artifact@v4 | |
| if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' | |
| with: | |
| name: python-coverage-comment-action | |
| path: python-coverage-comment-action.txt |