-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (52 loc) · 1.81 KB
/
publish.yml
File metadata and controls
54 lines (52 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Publish Python Package
on:
push:
tags:
- 'v*' # Trigger on version tags
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags
- name: Fetch latest main
run: git fetch origin main --depth=1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine toml
- name: Verify version and commit
run: |
# Extract version from the tag
TAG_VERSION=${GITHUB_REF#refs/tags/v}
# Extract version from pyproject.toml
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
echo "Tag version: $TAG_VERSION"
echo "Package version: $PACKAGE_VERSION"
# Compare versions
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
echo "Error: Tag version ($TAG_VERSION) does not match package version ($PACKAGE_VERSION)"
exit 1
fi
# Verify that the tagged commit is on the main branch
if ! git merge-base --is-ancestor HEAD origin/main; then
echo "Error: The tagged commit is not on the main branch"
exit 1
fi
# Verify that the tagged commit is the latest on the main branch
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
echo "Error: The tagged commit is not the latest on the main branch"
exit 1
fi
- name: Build package
run: python -m build
- name: Publish package
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*