1+ name : Release
2+
3+ on :
4+ release :
5+ types : [published]
6+
7+ permissions :
8+ contents : write
9+ id-token : write # For trusted publishing to PyPI
10+
11+ jobs :
12+ publish :
13+ name : Build and Publish to PyPI
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - uses : actions/checkout@v4
18+
19+ - name : Set up Python
20+ uses : actions/setup-python@v5
21+ with :
22+ python-version : " 3.11"
23+
24+ - name : Set up Node.js
25+ uses : actions/setup-node@v4
26+ with :
27+ node-version : " 20"
28+ cache : " npm"
29+ cache-dependency-path : frontend/package-lock.json
30+
31+ - name : Extract version from tag
32+ id : get_version
33+ run : |
34+ # Get the tag name from the release
35+ TAG="${{ github.event.release.tag_name }}"
36+ # Remove 'v' prefix if present
37+ VERSION="${TAG#v}"
38+ echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
39+ echo "TAG=$TAG" >> $GITHUB_OUTPUT
40+ echo "Release version: $VERSION (from tag: $TAG)"
41+
42+ - name : Verify package version matches tag
43+ run : |
44+ # Extract version from pyproject.toml
45+ PACKAGE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
46+ echo "Package version: $PACKAGE_VERSION"
47+ echo "Tag version: ${{ steps.get_version.outputs.VERSION }}"
48+
49+ if [ "$PACKAGE_VERSION" != "${{ steps.get_version.outputs.VERSION }}" ]; then
50+ echo "Error: Package version ($PACKAGE_VERSION) doesn't match tag version (${{ steps.get_version.outputs.VERSION }})"
51+ echo "Please update the version in pyproject.toml to match the release tag"
52+ exit 1
53+ fi
54+
55+ - name : Install frontend dependencies
56+ run : |
57+ cd frontend
58+ npm ci
59+
60+ - name : Build frontend
61+ run : |
62+ cd frontend
63+ npm run build
64+ echo "Frontend build completed"
65+ ls -la ../mcphawk/web/static/assets/
66+
67+ - name : Install Python build dependencies
68+ run : |
69+ python -m pip install --upgrade pip
70+ pip install build twine
71+
72+ - name : Build Python package
73+ run : |
74+ python -m build
75+ echo "Built packages:"
76+ ls -la dist/
77+
78+ - name : Check package with twine
79+ run : |
80+ twine check dist/*
81+
82+ - name : Publish to PyPI
83+ env :
84+ TWINE_USERNAME : __token__
85+ TWINE_PASSWORD : ${{ secrets.PYPI_API_TOKEN }}
86+ run : |
87+ twine upload dist/*
88+
89+ - name : Upload release assets
90+ uses : softprops/action-gh-release@v1
91+ with :
92+ files : |
93+ dist/*.whl
94+ dist/*.tar.gz
95+ env :
96+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
97+
98+ - name : Post-release summary
99+ run : |
100+ echo "### 🎉 Release Published Successfully!"
101+ echo ""
102+ echo "**Version:** ${{ steps.get_version.outputs.VERSION }}"
103+ echo "**Tag:** ${{ steps.get_version.outputs.TAG }}"
104+ echo ""
105+ echo "**PyPI:** https://pypi.org/project/mcphawk/${{ steps.get_version.outputs.VERSION }}/"
106+ echo ""
107+ echo "**Artifacts:**"
108+ ls -lh dist/
109+ echo ""
110+ echo "Install with: \`pip install mcphawk==${{ steps.get_version.outputs.VERSION }}\`"
0 commit comments