Add a test infrastructure using tox
for GitHub actions and add python-semantic-release
#14
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
name: 🧪 pytest | |
on: | |
pull_request: | |
types: [ opened, reopened, synchronize ] | |
workflow_call: | |
permissions: | |
id-token: write | |
contents: write | |
checks: write | |
pull-requests: write | |
jobs: | |
test: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ ubuntu-latest ] | |
python-version: [ "3.10" ] | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 30 | |
name: 🧪 Run pytests wit ${{matrix.python-version}} on ${{matrix.os}} | |
steps: | |
- name: ⬇️ Checkout repository | |
uses: actions/checkout@v4 | |
- name: 🧙♂️Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
version: "latest" | |
enable-cache: true | |
python-version: ${{matrix.python-version}} | |
cache-dependency-glob: "**/pyproject.toml" | |
- name: 🪟 Add .local/bin to Windows PATH | |
if: runner.os == 'Windows' | |
shell: bash | |
run: echo "$USERPROFILE/.local/bin" >> $GITHUB_PATH | |
- name: 🧙Install tox | |
run: uv tool install --python-preference only-managed --python 3.14 tox --with tox-uv --with tox-gh | |
- name: 🐍 Install Python | |
if: matrix.env != '3.14' | |
run: uv python install --python-preference only-managed ${{ matrix.env }} | |
- name: 🛠️Setup test suite | |
run: tox run --notest --skip-missing-interpreters false | |
env: | |
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }} | |
- name: 🏃 Run test suite | |
run: tox run --skip-pkg-install | |
env: | |
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }} | |
- name: 📃 Test results | |
if: always() | |
uses: pmeier/pytest-results-action@main | |
with: | |
# A list of JUnit XML files, directories containing the former, and wildcard | |
# patterns to process. | |
# See @actions/glob for supported patterns. | |
path: ./junit.xml | |
# (Optional) Add a summary of the results at the top of the report | |
summary: true | |
# (Optional) Select which results should be included in the report. | |
# Follows the same syntax as `pytest -r` | |
display-options: fEX | |
# (Optional) Fail the workflow if no JUnit XML was found. | |
fail-on-empty: true | |
# (Optional) Title of the test results section in the workflow summary | |
title: Test results | |
- name: ✏️ Write test result as comment | |
uses: MishaKav/pytest-coverage-comment@v1 | |
with: | |
pytest-xml-coverage-path: ./coverage.xml | |
title: Coverage Report | |
badge-title: Code Coverage | |
hide-badge: false | |
hide-report: false | |
create-new-comment: false | |
hide-comment: false | |
report-only-changed-files: true | |
remove-link-from-badge: false | |
junitxml-path: ./junit.xml | |
junitxml-title: Pytest summary | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload math result for job 1 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage-report | |
path: ./coverage.xml | |
# - name: Upload math result for job 1 | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: code-coverage | |
# path: ./coverage.xml | |
# - name: Download math result for job 1 | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: code-coverage | |
- name: Pytest coverage comment | |
id: coverageComment | |
uses: MishaKav/pytest-coverage-comment@main | |
with: | |
hide-comment: true | |
pytest-xml-coverage-path: ./coverage.xml | |
- name: Update Readme with Coverage Html | |
run: | | |
sed -i '/<!-- Pytest Coverage Comment:Begin -->/,/<!-- Pytest Coverage Comment:End -->/c\<!-- Pytest Coverage Comment:Begin -->\n\${{ steps.coverageComment.outputs.coverageHtml }}\n<!-- Pytest Coverage Comment:End -->' ./README.md | |
# | |
# - name: Push changes | |
# uses: ad-m/github-push-action@master | |
# with: | |
# github_token: ${{ secrets.GITHUB_TOKEN }} | |
# branch: "fe" |