Feed real coverage to SonarCloud and scope scanning to what the plan exposes #168
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: PyBreeze Stable | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| schedule: | |
| - cron: "0 2 * * *" | |
| permissions: | |
| contents: read | |
| jobs: | |
| unit-tests: | |
| runs-on: windows-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Update pip wheel setuptools | |
| run: python -m pip install --upgrade pip setuptools wheel | |
| - name: Install dependencies | |
| run: python -m pip install -r requirements.txt | |
| - name: Install test tooling | |
| run: python -m pip install pytest pytest-cov hypothesis | |
| - name: Run unit tests (pytest) | |
| run: python -m pytest test/test_utils/ -v --tb=short --cov=pybreeze --cov-branch --cov-report=xml | |
| - name: Upload coverage for analysis | |
| # One leg is enough; the scanner only consumes a single report. | |
| if: matrix.python-version == '3.12' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-xml | |
| path: coverage.xml | |
| if-no-files-found: error | |
| - name: Run AutomationEditor With Debug Mode | |
| run: python ./test/unit_test/start_automation/start_automation_test.py | |
| env: | |
| PYTHONPATH: . | |
| - name: Extend AutomationEditor | |
| run: python ./test/unit_test/start_automation/extend_automation_test.py | |
| env: | |
| PYTHONPATH: . | |
| sonarcloud: | |
| # Automatic Analysis is off, so main-branch and pull-request analysis both | |
| # come from here. Skipped on the nightly schedule, where re-scanning an | |
| # unchanged commit adds nothing, and on fork pull requests, which cannot | |
| # read the token. | |
| if: >- | |
| github.event_name != 'schedule' && | |
| (github.event_name != 'pull_request' || | |
| github.event.pull_request.head.repo.full_name == github.repository) | |
| needs: unit-tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Sonar needs the full history to attribute new code to the right commits. | |
| fetch-depth: 0 | |
| - name: Download coverage | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage-xml | |
| - name: SonarQube Cloud scan | |
| uses: SonarSource/[email protected] | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| SONAR_HOST_URL: https://sonarcloud.io | |
| publish: | |
| needs: unit-tests | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Bump patch version | |
| id: bump | |
| run: | | |
| python - <<'PY' | |
| import os | |
| import pathlib | |
| import re | |
| path = pathlib.Path("pyproject.toml") | |
| text = path.read_text(encoding="utf-8") | |
| match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', text, re.M) | |
| if match is None: | |
| raise SystemExit("version line not found in pyproject.toml") | |
| major, minor, patch = map(int, match.groups()) | |
| new_version = f"{major}.{minor}.{patch + 1}" | |
| new_text = re.sub( | |
| r'^version = "\d+\.\d+\.\d+"', | |
| f'version = "{new_version}"', | |
| text, | |
| count=1, | |
| flags=re.M, | |
| ) | |
| path.write_text(new_text, encoding="utf-8") | |
| with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh: | |
| fh.write(f"new_version={new_version}\n") | |
| PY | |
| - name: Install build tools | |
| run: python -m pip install --upgrade pip build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: python -m twine upload dist/* | |
| - name: Commit and tag version bump | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add pyproject.toml | |
| git commit -m "Bump stable version to ${{ steps.bump.outputs.new_version }}" | |
| git tag "v${{ steps.bump.outputs.new_version }}" | |
| git push origin HEAD:main | |
| git push origin "v${{ steps.bump.outputs.new_version }}" | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release create "v${{ steps.bump.outputs.new_version }}" \ | |
| --title "v${{ steps.bump.outputs.new_version }}" \ | |
| --generate-notes \ | |
| --latest \ | |
| dist/* |