Skip to content

feat: add GitHub Actions workflow for running tests and uploading cov… #1

feat: add GitHub Actions workflow for running tests and uploading cov…

feat: add GitHub Actions workflow for running tests and uploading cov… #1

Workflow file for this run

name: Tests
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
permissions:
contents: read
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.13'
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Run tests with pytest
run: |
set -o pipefail
pytest -v \
--cov=src \
--cov-report=xml \
--cov-report=term-missing \
--junitxml=junit.xml \
-o junit_family=legacy \
| tee pytest-coverage.txt
- name: Check for Codecov Token
id: codecov-check
run: |
if [ -z "${{ secrets.CODECOV_TOKEN }}" ]; then
echo "::warning::CODECOV_TOKEN is not set."
echo "has_token=false" >> $GITHUB_OUTPUT
else
echo "::notice::CODECOV_TOKEN is set."
echo "has_token=true" >> $GITHUB_OUTPUT
fi
- name: Upload coverage to Codecov
if: ${{ !cancelled() && steps.codecov-check.outputs.has_token == 'true' }}
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Add coverage to job summary
if: always()
run: |
echo "## Test Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
sed -n '/^---------- coverage:/,$p' pytest-coverage.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}