|
| 1 | +name: CI (stable) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + schedule: |
| 9 | + - cron: "0 3 * * *" |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + lint: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - uses: actions/setup-python@v5 |
| 20 | + with: |
| 21 | + python-version: "3.12" |
| 22 | + cache: pip |
| 23 | + - name: Install tooling |
| 24 | + run: | |
| 25 | + python -m pip install --upgrade pip |
| 26 | + pip install ruff mypy |
| 27 | + - name: Ruff check |
| 28 | + run: ruff check automation_file tests |
| 29 | + - name: Ruff format check |
| 30 | + run: ruff format --check automation_file tests |
| 31 | + - name: Mypy |
| 32 | + run: mypy automation_file |
| 33 | + |
| 34 | + pytest: |
| 35 | + needs: lint |
| 36 | + runs-on: windows-latest |
| 37 | + strategy: |
| 38 | + fail-fast: false |
| 39 | + matrix: |
| 40 | + python-version: [ "3.10", "3.11", "3.12" ] |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + - name: Set up Python ${{ matrix.python-version }} |
| 44 | + uses: actions/setup-python@v5 |
| 45 | + with: |
| 46 | + python-version: ${{ matrix.python-version }} |
| 47 | + cache: pip |
| 48 | + - name: Install dependencies |
| 49 | + run: | |
| 50 | + python -m pip install --upgrade pip wheel |
| 51 | + pip install -r requirements.txt |
| 52 | + pip install pytest pytest-cov |
| 53 | + - name: Run pytest with coverage |
| 54 | + run: python -m pytest tests/ -v --tb=short --cov=automation_file --cov-report=term-missing --cov-report=xml |
| 55 | + - name: Upload coverage artifact |
| 56 | + if: matrix.python-version == '3.12' |
| 57 | + uses: actions/upload-artifact@v4 |
| 58 | + with: |
| 59 | + name: coverage-xml |
| 60 | + path: coverage.xml |
| 61 | + |
| 62 | + publish: |
| 63 | + needs: pytest |
| 64 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 65 | + runs-on: ubuntu-latest |
| 66 | + permissions: |
| 67 | + contents: write |
| 68 | + steps: |
| 69 | + - uses: actions/checkout@v4 |
| 70 | + with: |
| 71 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + - name: Set up Python |
| 73 | + uses: actions/setup-python@v5 |
| 74 | + with: |
| 75 | + python-version: "3.12" |
| 76 | + cache: pip |
| 77 | + - name: Install build tools |
| 78 | + run: | |
| 79 | + python -m pip install --upgrade pip |
| 80 | + pip install build twine |
| 81 | + - name: Bump patch version in stable.toml and dev.toml |
| 82 | + id: version |
| 83 | + run: | |
| 84 | + python - <<'PY' |
| 85 | + import os |
| 86 | + import pathlib |
| 87 | + import re |
| 88 | +
|
| 89 | + def bump(path: pathlib.Path) -> str: |
| 90 | + text = path.read_text(encoding="utf-8") |
| 91 | + match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', text, re.MULTILINE) |
| 92 | + if match is None: |
| 93 | + raise SystemExit(f"no version line found in {path}") |
| 94 | + major, minor, patch = (int(g) for g in match.groups()) |
| 95 | + new = f"{major}.{minor}.{patch + 1}" |
| 96 | + path.write_text(text.replace(match.group(0), f'version = "{new}"', 1), encoding="utf-8") |
| 97 | + return new |
| 98 | +
|
| 99 | + stable_version = bump(pathlib.Path("stable.toml")) |
| 100 | + dev_version = bump(pathlib.Path("dev.toml")) |
| 101 | + with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fp: |
| 102 | + fp.write(f"version={stable_version}\n") |
| 103 | + fp.write(f"dev_version={dev_version}\n") |
| 104 | + print(f"stable.toml -> {stable_version}") |
| 105 | + print(f"dev.toml -> {dev_version}") |
| 106 | + PY |
| 107 | + - name: Commit bumped versions back to main |
| 108 | + run: | |
| 109 | + git config user.name "github-actions[bot]" |
| 110 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 111 | + git add stable.toml dev.toml |
| 112 | + git commit -m "Bump version to v${{ steps.version.outputs.version }} [skip ci]" |
| 113 | + git push origin HEAD:main |
| 114 | + - name: Use stable.toml as pyproject.toml |
| 115 | + run: cp stable.toml pyproject.toml |
| 116 | + - name: Build sdist and wheel |
| 117 | + run: python -m build |
| 118 | + - name: Twine check |
| 119 | + run: twine check dist/* |
| 120 | + - name: Twine upload to PyPI |
| 121 | + env: |
| 122 | + TWINE_USERNAME: __token__ |
| 123 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 124 | + run: twine upload --non-interactive dist/* |
| 125 | + - name: Create GitHub Release |
| 126 | + env: |
| 127 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + run: | |
| 129 | + gh release create "v${{ steps.version.outputs.version }}" dist/* \ |
| 130 | + --title "v${{ steps.version.outputs.version }}" \ |
| 131 | + --generate-notes |
0 commit comments