more on performance #113
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 | |
| concurrency: | |
| group: tests-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read # Checkout repository | |
| actions: read # Run third-party actions | |
| on: | |
| workflow_dispatch: {} | |
| push: | |
| branches: | |
| - "*" # matches every branch that doesn't contain a '/' | |
| - "*/*" # matches every branch containing a single '/' | |
| - "**" # matches every branch | |
| jobs: | |
| run_tests: | |
| name: Run tests | |
| runs-on: ubuntu-latest | |
| environment: production | |
| permissions: | |
| contents: read # Checkout repository | |
| actions: read # Run third-party actions | |
| issues: write # Create issue on test failure | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - name: Check out GitHub repository ${{ github.repository }} | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 1 | |
| ref: ${{ github.sha }} | |
| persist-credentials: false | |
| - name: Set up Python on ${{ runner.os }} | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| id: setup_python | |
| with: | |
| python-version-file: '.python-version' | |
| - name: Get Python version | |
| run: echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV | |
| - name: Manage Poetry cache | |
| uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 | |
| id: poetry-cache | |
| with: | |
| path: | | |
| ~/.cache/pypoetry/cache | |
| ~/.cache/pypoetry/artifacts | |
| key: poetry-cache-${{ runner.os }}-${{ hashFiles('poetry.lock') }} | |
| restore-keys: poetry-cache-${{ runner.os }}- | |
| - name: Create virtual environment on ${{ env.PYTHON_VERSION }} | |
| run: python -m venv venv | |
| - name: Activate virtual environment and install Poetry | |
| run: | | |
| source venv/bin/activate | |
| python --version | |
| pip install --upgrade pip wheel | |
| pip install poetry==2.3.2 | |
| - name: Install dependencies with Poetry | |
| run: | | |
| source venv/bin/activate | |
| poetry install --no-root --with dev | |
| - name: Check and fix with Ruff | |
| run: | | |
| source venv/bin/activate | |
| poetry run ruff check . --fix --exit-non-zero-on-fix | |
| - name: Format with Ruff | |
| run: | | |
| source venv/bin/activate | |
| poetry run ruff format | |
| - name: Tests with Pytest | |
| id: pytest | |
| continue-on-error: true | |
| run: | | |
| source venv/bin/activate | |
| PYTHONPATH=${PWD} poetry run pytest -n auto \ | |
| --dist loadscope \ | |
| --cov=. \ | |
| --cov-report=term \ | |
| --cov-report=term-missing \ | |
| --cov-report=xml \ | |
| --junitxml=junit.xml | |
| - name: Create GitHub issue on failure | |
| if: ${{ steps.pytest.outcome == 'failure' }} | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| script: | | |
| const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `Tests failed on ${new Date().toDateString()}`, | |
| body: `See the full logs here: ${runUrl}`, | |
| }) | |
| - name: Fail job if tests failed | |
| if: ${{ steps.pytest.outcome == 'failure' }} | |
| run: exit 1 | |
| - name: Upload test results to Codecov | |
| if: ${{ github.ref_name == 'master' }} | |
| uses: codecov/test-results-action@0fa95f0e1eeaafde2c782583b36b28ad0d8c77d3 # v1.2.1 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: junit.xml | |
| verbose: true | |
| - name: Upload coverage to Codecov.io | |
| if: ${{ github.ref_name == 'master' }} | |
| uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| slug: CaptorAB/py-utils | |
| verbose: true |