Skip to content

Commit b3d6cb0

Browse files
committed
Refactor Python package publishing workflow: update steps for Python 3.12, streamline dependency installation, and add optional verification of uploaded package
1 parent c1601aa commit b3d6cb0

1 file changed

Lines changed: 38 additions & 43 deletions

File tree

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# This workflow will upload a Python Package using Twine when a release is created
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
1+
# .github/workflows/python-publish.yml
2+
3+
# This workflow will upload a Python Package to PyPI using Twine when a release is created.
4+
# For more information, see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
35

46
name: Upload Python Package
57

@@ -9,50 +11,43 @@ on:
911

1012
permissions:
1113
contents: read
14+
packages: write # Needed for uploading to PyPI
1215

1316
jobs:
1417
deploy:
15-
1618
runs-on: ubuntu-latest
1719

1820
steps:
19-
# Step 1: Checkout the code from the repository
20-
- uses: actions/checkout@v4
21-
22-
# Step 2: Set up Python version
23-
- name: Set up Python
24-
uses: actions/setup-python@v3
25-
with:
26-
python-version: '3.x'
27-
28-
# Step 3: Cache pip dependencies for faster builds
29-
- name: Cache pip dependencies
30-
uses: actions/cache@v3
31-
with:
32-
path: ~/.cache/pip
33-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
34-
restore-keys: |
35-
${{ runner.os }}-pip-
36-
37-
# Step 4: Install dependencies
38-
- name: Install dependencies
39-
run: |
40-
python -m pip install --upgrade pip
41-
pip install build
42-
43-
# Step 6: Run tests with pytest (optional)
44-
- name: Run tests
45-
run: |
46-
pip install pytest
47-
pytest
48-
49-
# Step 7: Build the package
50-
- name: Build package
51-
run: python -m build
52-
53-
# Step 8: Publish package to PyPI
54-
- name: Publish package
55-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
56-
with:
57-
user: __token__
58-
password: ${{ secrets.PYPI_API_TOKEN }}
21+
# Step 1: Checkout the code from the repository
22+
- name: Checkout Code
23+
uses: actions/checkout@v4
24+
25+
# Step 2: Set up Python version
26+
- name: Set up Python 3.12
27+
uses: actions/setup-python@v4
28+
with:
29+
python-version: '3.12'
30+
31+
# Step 3: Install dependencies
32+
- name: Install Dependencies
33+
run: |
34+
python -m pip install --upgrade pip setuptools wheel twine
35+
pip install -r requirements.txt
36+
37+
# Step 4: Build the package
38+
- name: Build Package
39+
run: |
40+
python setup.py sdist bdist_wheel
41+
42+
# Step 5: Publish the package to PyPI
43+
- name: Publish Package
44+
env:
45+
TWINE_USERNAME: __token__
46+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
47+
run: |
48+
twine upload dist/*
49+
50+
# Optional Step: Verify the uploaded package
51+
- name: Verify PyPI Upload (Optional)
52+
run: |
53+
pip install labmateai --index-url https://upload.pypi.org/legacy/

0 commit comments

Comments
 (0)