|
1 | | -# This workflow will upload a Python Package using Twine when a release is created |
| 1 | +# This workflow will upload a Python Package using Poetry when a release is created |
2 | 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries |
3 | 3 |
|
4 | 4 | # This workflow uses actions that are not certified by GitHub. |
|
14 | 14 |
|
15 | 15 | permissions: |
16 | 16 | contents: read |
| 17 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
17 | 18 |
|
18 | 19 | jobs: |
19 | 20 | deploy: |
20 | | - |
21 | 21 | runs-on: ubuntu-latest |
22 | | - |
| 22 | + environment: |
| 23 | + name: pypi |
| 24 | + url: https://pypi.org/p/treelib |
| 25 | + |
23 | 26 | steps: |
24 | 27 | - uses: actions/checkout@v4 |
| 28 | + |
25 | 29 | - name: Set up Python |
26 | 30 | uses: actions/setup-python@v5.4.0 |
27 | 31 | with: |
28 | | - python-version: '3.x' |
| 32 | + python-version: '3.10' # Use specific version for consistency |
| 33 | + |
| 34 | + - name: Install Poetry |
| 35 | + uses: snok/install-poetry@v1 |
| 36 | + with: |
| 37 | + version: latest |
| 38 | + virtualenvs-create: true |
| 39 | + virtualenvs-in-project: true |
| 40 | + installer-parallel: true |
| 41 | + |
| 42 | + - name: Load cached venv |
| 43 | + id: cached-poetry-dependencies |
| 44 | + uses: actions/cache@v4 |
| 45 | + with: |
| 46 | + path: .venv |
| 47 | + key: venv-${{ runner.os }}-3.11-${{ hashFiles('**/poetry.lock') }} |
| 48 | + |
29 | 49 | - name: Install dependencies |
| 50 | + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' |
| 51 | + run: poetry install --no-interaction --no-root |
| 52 | + |
| 53 | + - name: Install project |
| 54 | + run: poetry install --no-interaction |
| 55 | + |
| 56 | + - name: Verify version matches release tag |
30 | 57 | run: | |
31 | | - python -m pip install --upgrade pip |
32 | | - pip install build |
| 58 | + POETRY_VERSION=$(poetry version --short) |
| 59 | + RELEASE_TAG=${GITHUB_REF#refs/tags/} |
| 60 | + echo "Poetry version: $POETRY_VERSION" |
| 61 | + echo "Release tag: $RELEASE_TAG" |
| 62 | + if [ "v$POETRY_VERSION" != "$RELEASE_TAG" ]; then |
| 63 | + echo "❌ Version mismatch: Poetry version ($POETRY_VERSION) does not match release tag ($RELEASE_TAG)" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + echo "✅ Version verification passed" |
| 67 | + |
| 68 | + - name: Run tests before publishing |
| 69 | + run: | |
| 70 | + echo "🧪 Running tests to ensure package quality..." |
| 71 | + make test |
| 72 | + |
| 73 | + - name: Check code format and lint |
| 74 | + run: | |
| 75 | + echo "🔍 Running code quality checks..." |
| 76 | + make format-check |
| 77 | + make lint |
| 78 | + |
33 | 79 | - name: Build package |
34 | | - run: python -m build |
35 | | - - name: Publish package |
36 | | - uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 |
| 80 | + run: | |
| 81 | + echo "🏗️ Building package with Poetry..." |
| 82 | + make build |
| 83 | + |
| 84 | + - name: Verify build artifacts |
| 85 | + run: | |
| 86 | + echo "📦 Verifying build artifacts..." |
| 87 | + ls -la dist/ |
| 88 | + # Check that both wheel and source distribution were created |
| 89 | + if [ ! -f dist/*.whl ] || [ ! -f dist/*.tar.gz ]; then |
| 90 | + echo "❌ Missing build artifacts" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + echo "✅ Build artifacts verified" |
| 94 | + |
| 95 | + - name: Publish package to PyPI |
| 96 | + uses: pypa/gh-action-pypi-publish@release/v1 |
37 | 97 | with: |
38 | | - user: __token__ |
39 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
| 98 | + verbose: true |
| 99 | + print-hash: true |
0 commit comments