11name : Release
22
33on :
4- workflow_run :
5- workflows : ["Tests"]
6- branches : [main]
7- types :
8- - completed
4+ release :
5+ types : [published]
96
107# Required for PyPI trusted publishing
118permissions :
129 id-token : write
13- contents : write # Required for creating tags and releases
10+ contents : read
1411
1512jobs :
1613 check-version-and-publish :
1714 runs-on : ubuntu-latest
18- if : ${{ github.event.workflow_run.conclusion == 'success' }}
1915 steps :
2016 - uses : actions/checkout@v3
2117 with :
2218 fetch-depth : 0
23- ref : ${{ github.event.workflow_run.head_sha }}
2419
2520 - name : Set up Python
2621 uses : actions/setup-python@v4
@@ -32,59 +27,55 @@ jobs:
3227 python -m pip install --upgrade pip
3328 pip install build twine wheel tomli
3429
35- - name : Check for version bump
30+ - name : Verify version match
3631 id : check-version
3732 run : |
38- # Extract current version directly from pyproject.toml
39- # This is more reliable than using importlib.metadata
40- CURRENT_VERSION=$(python -c "
33+ # Extract current version from pyproject.toml
34+ PYPROJECT_VERSION=$(python -c "
4135 import tomli
4236 with open('pyproject.toml', 'rb') as f:
4337 data = tomli.load(f)
4438 print(data['project']['version'])
45- ")
39+ ")
4640
47- echo "Current version: $CURRENT_VERSION"
41+ # Get release tag version (remove 'v' prefix if present)
42+ RELEASE_VERSION="${{ github.event.release.tag_name }}"
43+ RELEASE_VERSION=${RELEASE_VERSION#v}
4844
49- # Check if this version already has a tag
50- if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
51- echo "Version $CURRENT_VERSION already has a tag. Skipping release."
52- echo "is_new_version=false" >> $GITHUB_OUTPUT
45+ echo "PyProject version: $PYPROJECT_VERSION"
46+ echo "Release version: $RELEASE_VERSION"
47+
48+ if [ "$PYPROJECT_VERSION" = "$RELEASE_VERSION" ]; then
49+ echo "✅ Versions match! Proceeding with PyPI publish"
50+ echo "should_publish=true" >> $GITHUB_OUTPUT
51+ echo "version=$PYPROJECT_VERSION" >> $GITHUB_OUTPUT
5352 else
54- echo "New version detected : $CURRENT_VERSION "
55- echo "is_new_version=true " >> $GITHUB_OUTPUT
56- echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
53+ echo "❌ Version mismatch! PyProject : $PYPROJECT_VERSION, Release: $RELEASE_VERSION "
54+ echo "should_publish=false " >> $GITHUB_OUTPUT
55+ exit 1
5756 fi
5857
5958 - name : Build package
60- if : steps.check-version.outputs.is_new_version == 'true'
59+ if : steps.check-version.outputs.should_publish == 'true'
6160 run : |
6261 python -m build
6362
64- - name : Find and Publish Draft Release
65- if : steps.check-version.outputs.is_new_version == 'true'
66- id : publish_release
63+ - name : Check if already published to PyPI
64+ if : steps.check-version.outputs.should_publish == 'true'
65+ id : check-pypi
6766 run : |
68- # Find the draft release for this version
69- RELEASE_ID=$(gh release list --json id,name,isDraft --jq '.[] | select(.name | contains("v${{ steps.check-version.outputs.new_version }}")) | select(.isDraft == true) | .id')
70-
71- if [ -n "$RELEASE_ID" ]; then
72- echo "Found draft release with ID: $RELEASE_ID"
73- # Edit the existing draft to make it published
74- gh release edit "v${{ steps.check-version.outputs.new_version }}" --draft=false
75- echo "Published existing draft release"
67+ # Check if this version exists on PyPI
68+ VERSION="${{ steps.check-version.outputs.version }}"
69+ if pip index versions mcp-use | grep -q "Available versions: .*$VERSION"; then
70+ echo "Version $VERSION already exists on PyPI"
71+ echo "publish_needed=false" >> $GITHUB_OUTPUT
7672 else
77- echo "No draft release found, creating new release"
78- # Fallback: create new release (though this shouldn't happen if release-drafter is working)
79- gh release create "v${{ steps.check-version.outputs.new_version }}" \
80- --title "Release v${{ steps.check-version.outputs.new_version }}" \
81- --generate-notes
73+ echo "Version $VERSION not found on PyPI, will publish"
74+ echo "publish_needed=true" >> $GITHUB_OUTPUT
8275 fi
83- env :
84- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
8576
8677 - name : Publish to PyPI
87- if : steps.check-version .outputs.is_new_version == 'true'
78+ if : steps.check-pypi .outputs.publish_needed == 'true'
8879 uses : pypa/gh-action-pypi-publish@release/v1
8980 with :
9081 password : ${{ secrets.PYPI_API_TOKEN }}
0 commit comments