name: Version Management and Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options: [patch, minor, major]
auto_release:
description: 'Auto create release and publish to PyPI'
required: false
default: true
type: boolean
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v6.0.1
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Determine trigger source
id: trigger
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]]; then
echo "source=tag" >> $GITHUB_OUTPUT
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
echo "auto_release=true" >> $GITHUB_OUTPUT
else
echo "source=manual" >> $GITHUB_OUTPUT
echo "auto_release=${{ github.event.inputs.auto_release }}" >> $GITHUB_OUTPUT
fi
- name: Set up Python
uses: actions/setup-python@v6.1.0
with:
python-version: '3.12'
- name: Install uv
run: pip install uv
- name: Version Management (Manual Trigger Only)
if: steps.trigger.outputs.source == 'manual'
run: |
echo "🔄 手动触发 - 进行版本管理..."
uv version --bump ${{ github.event.inputs.bump_type }}
uv run python scripts/sync_version.py
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: 升级版本到 v$(uv version --short)"
VERSION=$(uv version --short)
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin main
git push origin "v$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Build package
run: |
echo "📦 构建Python包..."
# Extract version
if [[ "${{ steps.trigger.outputs.source }}" == "tag" ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION=$(uv version --short 2>/dev/null || grep "version = " pyproject.toml | cut -d'"' -f2)
fi
echo "Building version $VERSION"
# 清理可能存在的缓存和构建产物
rm -rf dist/ build/ *.egg-info src/genome_mcp.egg-info 2>/dev/null || true
# 重新同步以确保版本正确
uv sync --no-dev
# 构建包
uv build
# 验证构建的版本
ls -la dist/
# 检查构建的包版本是否正确
if echo dist/* | grep -q "$VERSION"; then
echo "✅ 构建版本正确: $VERSION"
else
echo "❌ 构建版本错误,期望 $VERSION"
ls -la dist/
exit 1
fi
# 验证包可以安装
uvx --from . genome-mcp --help
- name: Extract version and changelog
id: extract_info
run: |
# Extract version
if [[ "${{ steps.trigger.outputs.source }}" == "tag" ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION=$(uv version --short)
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
# Get the commit message for this tag
COMMIT_MSG=$(git log -1 --pretty=format:'%s' ${{ github.sha }})
echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_OUTPUT
# Extract changelog from git tag annotation or generate from commits
if git tag -l v$VERSION -n --format='%(contents)' | grep -q .; then
CHANGELOG=$(git tag -l v$VERSION -n --format='%(contents)')
else
# Generate changelog from commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [[ -n "$LAST_TAG" ]]; then
CHANGELOG=$(git log $LAST_TAG..HEAD --pretty=format:"- %s (%h, %an)")
else
CHANGELOG=$(git log --pretty=format:"- %s (%h, %an)" -10)
fi
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
if: steps.trigger.outputs.auto_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.extract_info.outputs.VERSION }}
name: Release v${{ steps.extract_info.outputs.VERSION }}
body: |
## Version ${{ steps.extract_info.outputs.VERSION }}
${{ steps.extract_info.outputs.CHANGELOG }}
---
### 安装方式
```bash
pip install genome-mcp
```
### 快速开始
```bash
genome-mcp --help
```
### 功能特性
- 🔍 智能查询解析:支持自然语言和结构化查询
- 📊 批量数据获取:优化的批量查询,减少API调用
- 🎯 语义搜索:理解查询意图的智能搜索
- 🚀 多传输模式:支持STDIO、HTTP、SSE传输
- ⚡ 异步处理:高性能异步架构
- 📚 完整文档:详细的API文档和使用示例
### 配置示例
**Claude Desktop:**
```json
{
"mcpServers": {
"genome-mcp": {
"command": "uvx",
"args": ["genome-mcp"]
}
}
}
```
draft: false
prerelease: false
files: |
dist/*
- name: Publish to PyPI
if: steps.trigger.outputs.auto_release == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
echo "🚀 发布到PyPI..."
pip install twine
twine upload dist/*
- name: Summary
run: |
echo "✅ 版本管理流程完成!"
echo "📋 版本: ${{ steps.extract_info.outputs.VERSION }}"
echo "🔄 触发方式: ${{ steps.trigger.outputs.source }}"
echo "🚀 发布状态: ${{ steps.trigger.outputs.auto_release == 'true' && '已发布' || '仅版本管理' }}"