|
| 1 | +name: Release to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + id-token: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + lint: |
| 14 | + name: Lint & Type Check |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Install uv |
| 21 | + uses: astral-sh/setup-uv@v4 |
| 22 | + with: |
| 23 | + version: "latest" |
| 24 | + |
| 25 | + - name: Set up Python |
| 26 | + run: uv python install 3.12 |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: uv sync --all-extras |
| 30 | + |
| 31 | + - name: Run ruff linter |
| 32 | + run: uv run ruff check . |
| 33 | + |
| 34 | + - name: Run ruff format check |
| 35 | + run: uv run ruff format --check . |
| 36 | + |
| 37 | + - name: Run ty type checker |
| 38 | + run: uv run ty check |
| 39 | + |
| 40 | + test: |
| 41 | + name: Tests |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - name: Checkout code |
| 45 | + uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Install uv |
| 48 | + uses: astral-sh/setup-uv@v4 |
| 49 | + with: |
| 50 | + version: "latest" |
| 51 | + |
| 52 | + - name: Set up Python |
| 53 | + run: uv python install 3.12 |
| 54 | + |
| 55 | + - name: Install dependencies |
| 56 | + run: uv sync --all-extras |
| 57 | + |
| 58 | + - name: Run tests |
| 59 | + run: uv run pytest tests/ --ignore=tests/test_webapp_e2e.py -v |
| 60 | + |
| 61 | + build: |
| 62 | + name: Build Package |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: [lint, test] |
| 65 | + steps: |
| 66 | + - name: Checkout code |
| 67 | + uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Install uv |
| 70 | + uses: astral-sh/setup-uv@v4 |
| 71 | + with: |
| 72 | + version: "latest" |
| 73 | + |
| 74 | + - name: Set up Python |
| 75 | + run: uv python install 3.12 |
| 76 | + |
| 77 | + - name: Verify tag matches package version |
| 78 | + run: | |
| 79 | + TAG_VERSION=${GITHUB_REF#refs/tags/v} |
| 80 | + PKG_VERSION=$(grep '^version = ' pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/') |
| 81 | + if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then |
| 82 | + echo "::error::Tag version ($TAG_VERSION) does not match package version ($PKG_VERSION)" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + echo "✅ Tag matches package version: $PKG_VERSION" |
| 86 | +
|
| 87 | + - name: Build package |
| 88 | + run: uv build |
| 89 | + |
| 90 | + - name: Upload build artifacts |
| 91 | + uses: actions/upload-artifact@v4 |
| 92 | + with: |
| 93 | + name: dist |
| 94 | + path: dist/ |
| 95 | + |
| 96 | + publish-testpypi: |
| 97 | + name: Publish to TestPyPI |
| 98 | + runs-on: ubuntu-latest |
| 99 | + needs: [build] |
| 100 | + environment: testpypi |
| 101 | + steps: |
| 102 | + - name: Download build artifacts |
| 103 | + uses: actions/download-artifact@v4 |
| 104 | + with: |
| 105 | + name: dist |
| 106 | + path: dist/ |
| 107 | + |
| 108 | + - name: Publish to TestPyPI |
| 109 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 110 | + with: |
| 111 | + repository-url: https://test.pypi.org/legacy/ |
| 112 | + |
| 113 | + publish-pypi: |
| 114 | + name: Publish to PyPI |
| 115 | + runs-on: ubuntu-latest |
| 116 | + needs: [publish-testpypi] |
| 117 | + environment: pypi |
| 118 | + steps: |
| 119 | + - name: Download build artifacts |
| 120 | + uses: actions/download-artifact@v4 |
| 121 | + with: |
| 122 | + name: dist |
| 123 | + path: dist/ |
| 124 | + |
| 125 | + - name: Publish to PyPI |
| 126 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 127 | + |
| 128 | + github-release: |
| 129 | + name: Create GitHub Release |
| 130 | + runs-on: ubuntu-latest |
| 131 | + needs: [publish-pypi] |
| 132 | + steps: |
| 133 | + - name: Checkout code |
| 134 | + uses: actions/checkout@v4 |
| 135 | + |
| 136 | + - name: Create GitHub Release |
| 137 | + uses: softprops/action-gh-release@v2 |
| 138 | + with: |
| 139 | + generate_release_notes: true |
| 140 | + draft: false |
| 141 | + prerelease: false |
0 commit comments