Skip to content

Commit 51afe8b

Browse files
committed
Update github/workflows/publish-to-pypi.yaml
1 parent fbafd67 commit 51afe8b

File tree

1 file changed

+197
-0
lines changed

1 file changed

+197
-0
lines changed
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
name: Publish to PyPI (Test → Prod)
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
id-token: write
9+
10+
jobs:
11+
publish-test:
12+
name: Publish to TestPyPI
13+
runs-on: ubuntu-latest
14+
environment:
15+
name: test-pypi
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.11'
25+
26+
- name: Install build dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install build twine
30+
31+
- name: Build package
32+
run: |
33+
python -m build
34+
35+
- name: Display build artifacts
36+
run: |
37+
echo "Build artifacts:"
38+
ls -lh dist/
39+
40+
- name: Publish to TestPyPI
41+
uses: pypa/gh-action-pypi-publish@release/v1
42+
with:
43+
repository-url: https://test.pypi.org/legacy/
44+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
45+
46+
- name: Wait for TestPyPI to be ready
47+
run: |
48+
echo "Waiting for package to be available on TestPyPI..."
49+
for i in {1..5}; do
50+
if pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ibm-watsonx-data-intelligence-mcp-server; then
51+
echo "Package available on TestPyPI"
52+
exit 0
53+
fi
54+
echo "Attempt $i failed, retrying in $((i * 5)) seconds..."
55+
sleep $((i * 5))
56+
done
57+
echo "Package not available on TestPyPI after multiple attempts."
58+
exit 1
59+
60+
- name: Test package installation from TestPyPI
61+
run: |
62+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ ibm-watsonx-data-intelligence-mcp-server
63+
python -c "from importlib.metadata import version; print(f'Successfully installed version: {version(\"ibm-watsonx-data-intelligence-mcp-server\")}')"
64+
65+
- name: Start and verify server (TestPyPI)
66+
run: |
67+
echo "Starting ibm-watsonx-data-intelligence-mcp-server..."
68+
69+
timeout 5 ibm-watsonx-data-intelligence-mcp-server --transport stdio > /tmp/server.log 2>&1 || EXIT_CODE=$?
70+
71+
echo "Server output:"
72+
cat /tmp/server.log
73+
74+
if [ "${EXIT_CODE:-0}" -eq 124 ]; then
75+
echo "Server timed out as expected (running indefinitely)"
76+
elif [ "${EXIT_CODE:-0}" -ne 0 ]; then
77+
echo "Server failed to start (exit code: $EXIT_CODE)"
78+
exit 1
79+
fi
80+
81+
if grep -qiE "(^error|^failed|^traceback|^exception|: error|: failed)" /tmp/server.log; then
82+
echo "Server startup errors detected in logs"
83+
exit 1
84+
fi
85+
86+
echo "Server verification passed - no errors"
87+
88+
- name: Verify package metadata
89+
run: |
90+
twine check dist/*
91+
92+
- name: Create test verification summary
93+
run: |
94+
echo "## TestPyPI Verification Passed" >> $GITHUB_STEP_SUMMARY
95+
echo "" >> $GITHUB_STEP_SUMMARY
96+
echo "Package successfully:" >> $GITHUB_STEP_SUMMARY
97+
echo "- Built and packaged" >> $GITHUB_STEP_SUMMARY
98+
echo "- Published to TestPyPI" >> $GITHUB_STEP_SUMMARY
99+
echo "- Installed from TestPyPI" >> $GITHUB_STEP_SUMMARY
100+
echo "- Server started successfully" >> $GITHUB_STEP_SUMMARY
101+
echo "- Verified metadata" >> $GITHUB_STEP_SUMMARY
102+
echo "" >> $GITHUB_STEP_SUMMARY
103+
echo "View on TestPyPI: https://test.pypi.org/project/ibm-watsonx-data-intelligence-mcp-server/" >> $GITHUB_STEP_SUMMARY
104+
105+
publish-prod:
106+
name: Publish to PyPI (Production)
107+
runs-on: ubuntu-latest
108+
needs: publish-test
109+
if: success()
110+
environment:
111+
name: pypi
112+
113+
steps:
114+
- name: Checkout code
115+
uses: actions/checkout@v4
116+
117+
- name: Set up Python
118+
uses: actions/setup-python@v4
119+
with:
120+
python-version: '3.11'
121+
122+
- name: Install build dependencies
123+
run: |
124+
python -m pip install --upgrade pip
125+
pip install build twine
126+
127+
- name: Build package
128+
run: |
129+
python -m build
130+
131+
- name: Display build artifacts
132+
run: |
133+
echo "Build artifacts:"
134+
ls -lh dist/
135+
136+
- name: Verify package metadata
137+
run: |
138+
twine check dist/*
139+
140+
- name: Publish to PyPI
141+
uses: pypa/gh-action-pypi-publish@release/v1
142+
with:
143+
password: ${{ secrets.PYPI_API_TOKEN }}
144+
145+
- name: Wait for PyPI to be ready
146+
run: |
147+
for i in {1..5}; do
148+
if pip install ibm-watsonx-data-intelligence-mcp-server --upgrade; then
149+
echo "Package available on PyPI"
150+
exit 0
151+
fi
152+
echo "Attempt $i failed, retrying in $((i * 5)) seconds..."
153+
sleep $((i * 5))
154+
done
155+
echo "Package not available on PyPI after multiple attempts"
156+
exit 1
157+
158+
- name: Verify package on PyPI
159+
run: |
160+
pip install ibm-watsonx-data-intelligence-mcp-server --upgrade
161+
python -c "import importlib.metadata; print(f'Successfully installed version: {importlib.metadata.version(\"ibm-watsonx-data-intelligence-mcp-server\")}')"
162+
163+
- name: Start and verify server (Production)
164+
run: |
165+
echo "Starting ibm-watsonx-data-intelligence-mcp-server..."
166+
167+
timeout 5 ibm-watsonx-data-intelligence-mcp-server --transport stdio > /tmp/server.log 2>&1 || EXIT_CODE=$?
168+
169+
echo "Server output:"
170+
cat /tmp/server.log
171+
172+
if [ "${EXIT_CODE:-0}" -eq 124 ]; then
173+
echo "Server timed out as expected (running indefinitely)"
174+
elif [ "${EXIT_CODE:-0}" -ne 0 ]; then
175+
echo "Server failed to start (exit code: $EXIT_CODE)"
176+
exit 1
177+
fi
178+
179+
if grep -qiE "(^error|^failed|^traceback|^exception|: error|: failed)" /tmp/server.log; then
180+
echo "Server startup errors detected in logs"
181+
exit 1
182+
fi
183+
184+
echo "Server verification passed - no errors"
185+
186+
- name: Create prod verification summary
187+
run: |
188+
echo "## Production PyPI Deployment Successful" >> $GITHUB_STEP_SUMMARY
189+
echo "" >> $GITHUB_STEP_SUMMARY
190+
echo "Package successfully:" >> $GITHUB_STEP_SUMMARY
191+
echo "- Built and packaged" >> $GITHUB_STEP_SUMMARY
192+
echo "- Published to PyPI" >> $GITHUB_STEP_SUMMARY
193+
echo "- Installed from PyPI" >> $GITHUB_STEP_SUMMARY
194+
echo "- Server started successfully" >> $GITHUB_STEP_SUMMARY
195+
echo "- Verified metadata" >> $GITHUB_STEP_SUMMARY
196+
echo "" >> $GITHUB_STEP_SUMMARY
197+
echo "View on PyPI: https://pypi.org/project/ibm-watsonx-data-intelligence-mcp-server/" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)