Skip to content

Commit 46726a1

Browse files
committed
add: pypi setup
1 parent f043fad commit 46726a1

File tree

3 files changed

+169
-3
lines changed

3 files changed

+169
-3
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,60 @@ jobs:
5959
flags: unittests
6060
name: codecov-${{ matrix.python-version }}
6161
token: ${{ secrets.CODECOV_TOKEN }}
62-
verbose: true
62+
verbose: true
63+
64+
build:
65+
runs-on: ubuntu-latest
66+
needs: [lint, test]
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- name: Set up Python
72+
uses: actions/setup-python@v5
73+
with:
74+
python-version: "3.11"
75+
76+
- name: Set up Node.js
77+
uses: actions/setup-node@v4
78+
with:
79+
node-version: "20"
80+
cache: "npm"
81+
cache-dependency-path: frontend/package-lock.json
82+
83+
- name: Install frontend dependencies
84+
run: |
85+
cd frontend
86+
npm ci
87+
88+
- name: Build frontend
89+
run: |
90+
cd frontend
91+
npm run build
92+
93+
- name: Install Python build dependencies
94+
run: |
95+
python -m pip install --upgrade pip
96+
pip install build twine
97+
98+
- name: Build Python package
99+
run: |
100+
python -m build
101+
102+
- name: Check package with twine
103+
run: |
104+
twine check dist/*
105+
106+
- name: Upload build artifacts
107+
uses: actions/upload-artifact@v4
108+
with:
109+
name: python-package-distributions
110+
path: dist/
111+
retention-days: 7
112+
113+
- name: List build contents
114+
run: |
115+
echo "Built packages:"
116+
ls -la dist/
117+
echo "Frontend build:"
118+
ls -la mcphawk/web/static/assets/ || echo "Frontend assets not found"

.github/workflows/release.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 }}\`"

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mcphawk"
7-
version = "0.4.1"
8-
description = "A passive MCP (Model Context Protocol) traffic sniffer for WebSocket-based MCP servers."
7+
version = "0.4.2"
8+
description = "MCPHawk is a Logging & Monitoring solution for MCP traffic, providing deep visibility into MCP client-server interactions"
99
authors = [
1010
{ name = "tech4242" }
1111
]

0 commit comments

Comments
 (0)