tests #71
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: tests | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: | |
inputs: | |
operating_systems: | |
description: 'Operating systems to test on' | |
type: choice | |
default: 'all' | |
options: | |
- all | |
- ubuntu-latest | |
- windows-latest | |
- macos-latest | |
jobs: | |
# Generate matrix based on input | |
setup-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Set matrix | |
id: set-matrix | |
run: | | |
if [[ "${{ inputs.operating_systems }}" == "all" || "${{ github.event_name }}" == "push" ]]; then | |
echo 'matrix=["ubuntu-latest", "windows-latest", "macos-latest"]' >> $GITHUB_OUTPUT | |
else | |
echo 'matrix=["${{ inputs.operating_systems }}"]' >> $GITHUB_OUTPUT | |
fi | |
# Run tests using matrix strategy | |
tests: | |
permissions: | |
contents: write | |
needs: setup-matrix | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: ${{ fromJSON(needs.setup-matrix.outputs.matrix) }} | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Install python and dependencies | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.13' | |
cache: 'pip' | |
- name: Install requirements (Windows) | |
if: runner.os == 'Windows' | |
run: python -m pip install -r requirements.txt | |
- name: Install requirements (Unix) | |
if: runner.os != 'Windows' | |
run: pip install -r requirements.txt | |
- name: Run tests (with coverage for linux) | |
run: | | |
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then | |
pytest --cov --cov-report=xml | |
else | |
pytest | |
fi | |
shell: bash | |
- name: Generate coverage badge (for-the-badge style) | |
if: matrix.os == 'ubuntu-latest' | |
run: genbadge coverage -i coverage.xml -o images/coverage-badge.svg | |
- name: Upload coverage badge | |
if: matrix.os == 'ubuntu-latest' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-badge | |
path: images/coverage-badge.svg | |
- name: Commit coverage badge | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add images/coverage-badge.svg | |
git commit -m "ci(tests): update coverage badge" || echo "No changes to commit" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |