Skip to content

Commit d864df2

Browse files
committed
migrate to poetry build and set up Trusted Publishing
1 parent 3851703 commit d864df2

File tree

1 file changed

+71
-11
lines changed

1 file changed

+71
-11
lines changed

.github/workflows/pypi-publish.yml

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
33

44
# This workflow uses actions that are not certified by GitHub.
@@ -14,26 +14,86 @@ on:
1414

1515
permissions:
1616
contents: read
17+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
1718

1819
jobs:
1920
deploy:
20-
2121
runs-on: ubuntu-latest
22-
22+
environment:
23+
name: pypi
24+
url: https://pypi.org/p/treelib
25+
2326
steps:
2427
- uses: actions/checkout@v4
28+
2529
- name: Set up Python
2630
uses: actions/setup-python@v5.4.0
2731
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+
2949
- 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
3057
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+
3379
- 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
3797
with:
38-
user: __token__
39-
password: ${{ secrets.PYPI_API_TOKEN }}
98+
verbose: true
99+
print-hash: true

0 commit comments

Comments
 (0)