name: Release
on:
push:
tags:
- 'v*.*.*'
env:
PYTHON_VERSION: "3.12"
jobs:
# Run full test suite before release
test:
name: Pre-Release Tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-release-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-release-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
pip install pytest-cov
- name: Run all tests
run: |
pytest tests/ -v \
-m "not slow" \
--cov=src/polymarket_mcp \
--cov-report=xml \
--cov-fail-under=80
env:
POLYGON_PRIVATE_KEY: "0000000000000000000000000000000000000000000000000000000000000001"
POLYGON_ADDRESS: "0x0000000000000000000000000000000000000001"
- name: Lint check
run: |
pip install ruff black
ruff check src/
black --check src/
# Build Python package
build:
name: Build Package
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
- name: Check package
run: |
twine check dist/*
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
# Build and push Docker image
docker:
name: Build & Push Docker Image
runs-on: ubuntu-latest
needs: test
if: hashFiles('Dockerfile') != ''
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
if: secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != ''
- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' }}
tags: |
${{ secrets.DOCKER_USERNAME }}/polymarket-mcp:latest
${{ secrets.DOCKER_USERNAME }}/polymarket-mcp:${{ steps.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
if: secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != ''
# Generate changelog
changelog:
name: Generate Changelog
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
run: |
# Get previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
echo "First release - generating full changelog"
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
echo "Generating changelog since $PREV_TAG"
COMMITS=$(git log $PREV_TAG..HEAD --pretty=format:"- %s (%h)" --no-merges)
fi
# Save to file
cat > RELEASE_NOTES.md << EOF
## Changes
$COMMITS
## Installation
\`\`\`bash
pip install polymarket-mcp
\`\`\`
Or use the MCP installer:
\`\`\`bash
# Install in Claude Desktop
uvx mcp install polymarket-mcp
\`\`\`
## Docker
\`\`\`bash
docker pull polymarket-mcp:${GITHUB_REF#refs/tags/v}
\`\`\`
## What's New
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for detailed changes.
EOF
echo "Generated release notes"
cat RELEASE_NOTES.md
- name: Upload release notes
uses: actions/upload-artifact@v4
with:
name: release-notes
path: RELEASE_NOTES.md
# Create GitHub Release
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [test, build, changelog]
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Download release notes
uses: actions/download-artifact@v4
with:
name: release-notes
- name: Create Release
uses: softprops/action-gh-release@v1
with:
body_path: RELEASE_NOTES.md
files: |
dist/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Publish to PyPI
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [test, build]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/project/polymarket-mcp/
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: secrets.PYPI_API_TOKEN != ''
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
# Update documentation
docs:
name: Update Documentation
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update version badge in README
run: |
VERSION=${GITHUB_REF#refs/tags/v}
sed -i "s/version-[0-9.]*-blue/version-$VERSION-blue/g" README.md
if git diff --quiet; then
echo "No changes to README"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "Update version badge to $VERSION [skip ci]"
git push
fi
# Notify on completion
notify:
name: Release Notification
runs-on: ubuntu-latest
needs: [release, publish]
if: always()
steps:
- name: Release Status
run: |
echo "Release Status:"
echo "==============="
echo "Tests: ${{ needs.test.result }}"
echo "Build: ${{ needs.build.result }}"
echo "Release: ${{ needs.release.result }}"
echo "Publish: ${{ needs.publish.result }}"
echo ""
if [ "${{ needs.release.result }}" == "success" ]; then
echo "✅ Release ${{ github.ref_name }} completed successfully!"
echo "📦 Package: https://pypi.org/project/polymarket-mcp/"
echo "📋 Release: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}"
else
echo "❌ Release failed - check logs above"
exit 1
fi