Files
xiaohongshu-mcp/.github/workflows/release.yml
zy 3b8abfeafc refactor: 优化发布流程 - PR 合并时触发,自动清理旧版本
主要改进:
- 改为 PR 合并到 main 时触发(不是每次 push)
- 自动删除超过 10 个的旧 Release,保持发布历史整洁
- 移除 prerelease 标记,所有自动构建都是正式 Release
- 恢复使用 v 前缀的版本号格式
- 清理了现有的 Draft 状态 Release

工作流程:
1. PR 合并到 main 分支时自动构建并发布
2. 自动清理,只保留最近 10 个 Release
3. 手动触发 tag-release.yml 发布语义化版本

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-18 23:19:00 +08:00

119 lines
3.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Build and Release
on:
pull_request:
types: [closed]
branches: [ main ]
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
# 只在 PR 被合并时运行,或手动触发
if: (github.event.pull_request.merged == true) || (github.event_name == 'workflow_dispatch')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Generate release name
id: version
run: |
TIMESTAMP=$(date +%Y.%m.%d.%H%M)
COMMIT_SHA=$(git rev-parse --short HEAD)
VERSION="v${TIMESTAMP}-${COMMIT_SHA}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Generated version: ${VERSION}"
- name: Build for multiple platforms
run: |
# 主程序构建
# macOS ARM64 (Apple Silicon)
GOOS=darwin GOARCH=arm64 go build -o xiaohongshu-mcp-darwin-arm64 .
GOOS=darwin GOARCH=arm64 go build -o xiaohongshu-login-darwin-arm64 ./cmd/login
# macOS Intel
GOOS=darwin GOARCH=amd64 go build -o xiaohongshu-mcp-darwin-amd64 .
GOOS=darwin GOARCH=amd64 go build -o xiaohongshu-login-darwin-amd64 ./cmd/login
# Windows x64
GOOS=windows GOARCH=amd64 go build -o xiaohongshu-mcp-windows-amd64.exe .
GOOS=windows GOARCH=amd64 go build -o xiaohongshu-login-windows-amd64.exe ./cmd/login
# Linux x64
GOOS=linux GOARCH=amd64 go build -o xiaohongshu-mcp-linux-amd64 .
GOOS=linux GOARCH=amd64 go build -o xiaohongshu-login-linux-amd64 ./cmd/login
- name: Clean up old releases
run: |
# 获取所有自动构建的 releases (v开头的时间戳格式)
RELEASES=$(gh release list --limit 100 | grep -E '^v[0-9]{4}\.[0-9]{2}\.[0-9]{2}\.[0-9]{4}-' | awk '{print $3}' | tail -n +11)
# 删除超过 10 个的旧 releases 和对应的 tags
for release in $RELEASES; do
echo "Deleting old release: $release"
gh release delete "$release" --yes --cleanup-tag
done
env:
GH_TOKEN: ${{ github.token }}
continue-on-error: true
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
draft: false
prerelease: false
body: |
## 🔧 自动构建版本
**注意:这是自动构建的预发布版本,用于测试。正式版本请等待手动发布。**
### 📦 下载说明
**主程序MCP 服务):**
- **macOS Apple Silicon**: `xiaohongshu-mcp-darwin-arm64`
- **macOS Intel**: `xiaohongshu-mcp-darwin-amd64`
- **Windows x64**: `xiaohongshu-mcp-windows-amd64.exe`
- **Linux x64**: `xiaohongshu-mcp-linux-amd64`
**登录工具:**
- **macOS Apple Silicon**: `xiaohongshu-login-darwin-arm64`
- **macOS Intel**: `xiaohongshu-login-darwin-amd64`
- **Windows x64**: `xiaohongshu-login-windows-amd64.exe`
- **Linux x64**: `xiaohongshu-login-linux-amd64`
### 🔧 使用方法
```bash
# 1. 首先运行登录工具
./xiaohongshu-login-darwin-arm64
# 2. 然后启动 MCP 服务
./xiaohongshu-mcp-darwin-arm64
```
### 📊 构建信息
- **Commit**: ${{ github.sha }}
- **Branch**: main
- **Build Time**: ${{ steps.version.outputs.version }}
files: |
xiaohongshu-mcp-darwin-arm64
xiaohongshu-mcp-darwin-amd64
xiaohongshu-mcp-windows-amd64.exe
xiaohongshu-mcp-linux-amd64
xiaohongshu-login-darwin-arm64
xiaohongshu-login-darwin-amd64
xiaohongshu-login-windows-amd64.exe
xiaohongshu-login-linux-amd64