[CI] Add test coverage reporting #390
Workflow file for this run
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: pytests | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| jobs: | |
| test: | |
| name: Run tests and collect coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Activate caching based on lockfile | |
| id: lockfile | |
| run: | | |
| if [ -f poetry.lock ]; then | |
| echo "cache_type=poetry" >> $GITHUB_OUTPUT | |
| elif [ -f requirements.txt ]; then | |
| echo "cache_type=pip" >> $GITHUB_OUTPUT | |
| else | |
| # no lockfile present: create empty requirements.txt and use pip caching | |
| touch requirements.txt | |
| echo "cache_type=pip" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check for Python | |
| id: python-check | |
| run: | | |
| if command -v python &/dev/null; then | |
| echo "python_installed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "python_installed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Python | |
| if: steps.python-check.outputs.python_installed == 'false' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| cache: ${{ steps.lockfile.outputs.cache_type }} | |
| - name: Install Poetry | |
| uses: snok/install-poetry@v1 | |
| - name: Cache Poetry Dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| $HOME/.cache/pypoetry | |
| $HOME/.cache/pip | |
| key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} | |
| restore-key: | | |
| ${{ runner.os }}-poetry- | |
| - name: Install dependencies | |
| run: poetry install --with dev | |
| - name: Setup Gardenlinux | |
| uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main | |
| - name: Prepare environment | |
| run: make install-test | |
| - name: Run tests | |
| run: | | |
| export GLOCI_REGISTRY_TOKEN="invalid" | |
| make test-coverage-ci | |
| - name: Check for report | |
| run: test -f coverage.xml | |
| - name: Upload results to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} |