Skip to content

Commit 048395f

Browse files
committed
ci: add automatic PyPI publish workflow
- Add publish.yml GitHub Actions workflow - Trigger on git tag push (v* or semver format) - Verify version consistency between tag and pyproject.toml - Auto-publish to PyPI using Trusted Publisher - Create GitHub Release on successful publish - Add comprehensive PUBLISH_GUIDE.md documentation - Add TRUSTED_PUBLISHER_SETUP.md configuration guide Workflow Features: - Semantic versioning validation - Automatic wheel and sdist building - Trusted Publisher integration (no token storage) - GitHub Release creation with PyPI links - Detailed workflow logging This enables one-command releases: git push origin <tag>
1 parent cf882f8 commit 048395f

3 files changed

Lines changed: 677 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
- "[0-9]+.[0-9]+.[0-9]+"
8+
9+
jobs:
10+
build-and-publish:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.11"
23+
24+
- name: Extract version from tag
25+
id: version
26+
run: |
27+
TAG=${GITHUB_REF#refs/tags/}
28+
VERSION=${TAG#v}
29+
echo "version=$VERSION" >> $GITHUB_OUTPUT
30+
echo "tag=$TAG" >> $GITHUB_OUTPUT
31+
echo "📦 Version: $VERSION (Tag: $TAG)"
32+
33+
- name: Verify version matches pyproject.toml
34+
run: |
35+
PYPROJECT_VERSION=$(grep '^version' pyproject.toml | cut -d'"' -f2)
36+
GITHUB_VERSION=${{ steps.version.outputs.version }}
37+
if [ "$PYPROJECT_VERSION" != "$GITHUB_VERSION" ]; then
38+
echo "❌ Version mismatch!"
39+
echo " pyproject.toml: $PYPROJECT_VERSION"
40+
echo " Git tag: $GITHUB_VERSION"
41+
exit 1
42+
fi
43+
echo "✅ Version matches: $PYPROJECT_VERSION"
44+
45+
- name: Install build dependencies
46+
run: |
47+
python -m pip install --upgrade pip
48+
pip install build twine
49+
50+
- name: Build distribution
51+
run: |
52+
python -m build
53+
echo "✅ Build completed"
54+
55+
- name: Check built artifacts
56+
run: |
57+
ls -lh dist/
58+
echo "📦 Artifacts ready for upload"
59+
60+
- name: Publish to PyPI (using Trusted Publisher)
61+
uses: pypa/gh-action-pypi-publish@release/v1
62+
with:
63+
repository-url: https://upload.pypi.org/legacy/
64+
verbose: true
65+
66+
- name: Create GitHub Release
67+
uses: actions/create-release@v1
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
with:
71+
tag_name: ${{ steps.version.outputs.tag }}
72+
release_name: "Release ${{ steps.version.outputs.tag }}"
73+
body: |
74+
## 📦 Version ${{ steps.version.outputs.version }}
75+
76+
This version has been automatically published to PyPI.
77+
78+
### Installation
79+
```bash
80+
pip install deep-diff==${{ steps.version.outputs.version }}
81+
```
82+
83+
### 📝 Changes
84+
Please check the commit history for detailed changes.
85+
86+
### 🔗 Links
87+
- [PyPI Package](https://pypi.org/project/deep-diff/${{ steps.version.outputs.version }}/)
88+
- [GitHub Repository](https://github.com/${{ github.repository }})
89+
draft: false
90+
prerelease: false
91+
92+
- name: Summary
93+
run: |
94+
echo "✅ Successfully published version ${{ steps.version.outputs.version }}"
95+
echo "🔗 PyPI: https://pypi.org/project/deep-diff/${{ steps.version.outputs.version }}/"
96+
echo "🏷️ Tag: ${{ steps.version.outputs.tag }}"

0 commit comments

Comments
 (0)