Skip to content

Commit f5b9df1

Browse files
committed
Safer workflow: Update PyPI release workflow
Refactor GitHub Actions workflow for PyPI releases: remove pull_request triggers, and add a checkout step. Simplify dependency installs (install build/twine/packaging together), drop pip cache, and move checkout. Add steps to install the package, verify the git tag matches the package version (using importlib.metadata), separate build and publish steps, and streamline the twine upload command. Also tidy output of built artifacts.
1 parent b8fbb8c commit f5b9df1

1 file changed

Lines changed: 27 additions & 35 deletions

File tree

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,51 @@
1-
name: Update pypi release
1+
name: Update PyPI release
22

33
on:
44
push:
55
tags:
66
- 'v*.*.*'
7-
pull_request:
8-
branches:
9-
- main
10-
- public
11-
types:
12-
- labeled
13-
- opened
14-
- edited
15-
- synchronize
16-
- reopened
177

188
jobs:
199
release:
2010
runs-on: ubuntu-latest
2111

2212
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
2316
- name: Setup Python
24-
id: setup-python
2517
uses: actions/setup-python@v5
2618
with:
2719
python-version: '3.x'
2820

29-
- name: Cache dependencies
30-
id: pip-cache
31-
uses: actions/cache@v4
32-
with:
33-
path: ~/.cache/pip
34-
key: ${{ runner.os }}-pip-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('pyproject.toml', 'requirements.txt', 'setup.cfg', 'setup.py') }}
35-
restore-keys: |
36-
${{ runner.os }}-pip-${{ steps.setup-python.outputs.python-version }}-
37-
${{ runner.os }}-pip-
38-
39-
- name: Install dependencies
21+
- name: Install build dependencies
4022
run: |
4123
pip install --upgrade pip
42-
pip install wheel
43-
pip install "packaging>=24.2"
44-
pip install build
45-
pip install twine
24+
pip install build twine "packaging>=24.2"
4625
47-
- name: Checkout code
48-
uses: actions/checkout@v4
26+
- name: Install package (for version check)
27+
run: pip install .
4928

50-
- name: Build and publish to PyPI
51-
if: ${{ github.event_name == 'push' }}
29+
- name: Verify tag matches package version
30+
run: |
31+
TAG_VERSION="${GITHUB_REF_NAME#v}"
32+
PKG_VERSION=$(python - <<EOF
33+
from importlib.metadata import version
34+
print(version("deeplabcut_live"))
35+
EOF
36+
)
37+
echo "Tag version: $TAG_VERSION"
38+
echo "Package version: $PKG_VERSION"
39+
test "$TAG_VERSION" = "$PKG_VERSION"
40+
41+
- name: Build distributions
42+
run: |
43+
python -m build
44+
ls -l dist/
45+
46+
- name: Publish to PyPI
5247
env:
5348
TWINE_USERNAME: __token__
5449
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}
5550
run: |
56-
python -m build
57-
ls dist/
58-
tar tvf dist/deeplabcut_live-*.tar.gz
59-
python3 -m twine upload --verbose dist/*
51+
python -m twine upload --verbose dist/*

0 commit comments

Comments
 (0)