Merge pull request #5 from captcha-solver-api/docs/coverage-badge #41
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: | |
| # Run on pushes to main only; feature branches are covered by the | |
| # pull_request trigger, so this avoids a duplicate run per commit. | |
| push: | |
| branches: [main] | |
| pull_request: | |
| workflow_call: | |
| jobs: | |
| # Static checks: ruff lint + formatting and mypy type checking. Runs once | |
| # on a single Python version since the result does not depend on the | |
| # interpreter. | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install package with dev dependencies | |
| run: python -m pip install -e ".[dev]" | |
| - name: Ruff lint | |
| run: ruff check . | |
| - name: Ruff format check | |
| run: ruff format --check . | |
| - name: mypy | |
| run: mypy captcha_solver_api | |
| # Test suite across all supported Python versions, plus a build check | |
| # to catch packaging errors early. Skipped if lint fails to save CI minutes. | |
| test: | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "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 }} | |
| - name: Install package with dev dependencies | |
| run: python -m pip install -e ".[dev]" | |
| - name: Run tests | |
| run: python -m pytest tests/ -v --cov --cov-report=term --cov-report=json | |
| # Coverage badge: the percentage is written to a gist that shields.io | |
| # renders in README. Only from main and from a single matrix entry so | |
| # PRs and duplicate uploads never overwrite the number. | |
| - name: Read coverage percentage | |
| if: github.ref == 'refs/heads/main' && matrix.python-version == '3.12' | |
| id: coverage | |
| run: | | |
| percent=$(python -c 'import json; print(round(json.load(open("coverage.json"))["totals"]["percent_covered"]))') | |
| echo "percent=$percent" >> "$GITHUB_OUTPUT" | |
| - name: Update coverage badge | |
| if: github.ref == 'refs/heads/main' && matrix.python-version == '3.12' | |
| uses: schneegans/dynamic-badges-action@v1.9.0 | |
| with: | |
| auth: ${{ secrets.GIST_SECRET }} | |
| gistID: 77b084ed0d46c740183f89ec66af8a95 | |
| filename: python-sdk-coverage.json | |
| label: coverage | |
| message: ${{ steps.coverage.outputs.percent }}% | |
| valColorRange: ${{ steps.coverage.outputs.percent }} | |
| minColorRange: 50 | |
| maxColorRange: 90 | |
| - name: Verify package builds | |
| run: | | |
| python -m pip install build | |
| python -m build --sdist --wheel |