Files
rustfs-console/.github/workflows/release.yml
T
overtrue 86367af9f4 ⬆️ chore: 升级 CI/CD 工作流 Node.js 版本至 22
- 将所有工作流文件中的 Node.js 版本从 18 升级到 22
- test.yml: 更新单元测试矩阵为 [20, 22]
- release.yml: 更新环境变量 NODE_VERSION 为 22
- quality.yml: 更新所有代码质量检查任务的 Node 版本
- dependencies.yml: 更新依赖管理任务的 Node 版本
2025-10-07 23:24:12 +08:00

370 lines
14 KiB
YAML

name: 🚀 Release & Deploy
on:
push:
tags:
- 'v*'
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., v1.0.0)'
required: true
type: string
environment:
description: 'Deployment environment'
required: true
default: 'staging'
type: choice
options:
- staging
- production
env:
NODE_VERSION: '22'
jobs:
# ============================================================================
# 预发布验证
# ============================================================================
pre-release-validation:
name: 🔍 Pre-Release Validation
runs-on: ubuntu-latest
timeout-minutes: 20
outputs:
version: ${{ steps.version.outputs.version }}
should-deploy: ${{ steps.validation.outputs.should-deploy }}
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: 📥 Install dependencies
run: |
npm ci
npm install --save-dev vitest jsdom @vitest/ui c8
- name: 🏷️ Extract version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/}
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION" >> $GITHUB_STEP_SUMMARY
- name: 🧪 Run full test suite
run: |
echo "## 🧪 Running Full Test Suite" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# 运行所有测试
npx vitest run tests/utils/config-helpers*.test.ts --coverage --reporter=verbose
echo "✅ All tests passed!" >> $GITHUB_STEP_SUMMARY
- name: 🔍 Validate code quality
run: |
npm run lint
npm run type-check
echo "✅ Code quality checks passed!" >> $GITHUB_STEP_SUMMARY
- name: 🏗️ Test build
run: |
npm run build
echo "✅ Build successful!" >> $GITHUB_STEP_SUMMARY
- name: ✅ Validation summary
id: validation
run: |
echo "should-deploy=true" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_STEP_SUMMARY
echo "🎉 **Pre-release validation completed successfully!**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Ready for deployment to ${{ github.event.inputs.environment || 'production' }}." >> $GITHUB_STEP_SUMMARY
# ============================================================================
# 构建发布包
# ============================================================================
build-release:
name: 🏗️ Build Release
runs-on: ubuntu-latest
needs: pre-release-validation
if: needs.pre-release-validation.outputs.should-deploy == 'true'
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: 📥 Install dependencies
run: npm ci
- name: 🏗️ Build for production
run: |
npm run build
echo "## 🏗️ Build Information" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ needs.pre-release-validation.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Node.js**: ${{ env.NODE_VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "- **Build Time**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
- name: 📦 Create release archive
run: |
# 创建发布包
tar -czf release-${{ needs.pre-release-validation.outputs.version }}.tar.gz \
.output/ \
package.json \
package-lock.json \
README.md \
LICENSE
- name: 📤 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: release-build-${{ needs.pre-release-validation.outputs.version }}
path: |
.output/
release-*.tar.gz
retention-days: 90
- name: 📊 Build size analysis
run: |
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📊 Build Size Analysis" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -d ".output" ]; then
total_size=$(du -sh .output | cut -f1)
echo "- **Total Build Size**: $total_size" >> $GITHUB_STEP_SUMMARY
echo "- **File Breakdown**:" >> $GITHUB_STEP_SUMMARY
find .output -type f -name "*.js" -o -name "*.css" -o -name "*.html" | head -10 | while read file; do
size=$(du -sh "$file" | cut -f1)
echo " - $(basename "$file"): $size" >> $GITHUB_STEP_SUMMARY
done
fi
# ============================================================================
# 部署到 Staging
# ============================================================================
deploy-staging:
name: 🚀 Deploy to Staging
runs-on: ubuntu-latest
needs: [pre-release-validation, build-release]
if: |
needs.pre-release-validation.outputs.should-deploy == 'true' &&
(github.event.inputs.environment == 'staging' || github.event_name == 'push')
environment:
name: staging
url: https://staging.example.com
steps:
- name: 📥 Download build artifacts
uses: actions/download-artifact@v4
with:
name: release-build-${{ needs.pre-release-validation.outputs.version }}
- name: 🚀 Deploy to staging
run: |
echo "## 🚀 Staging Deployment" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Deploying version ${{ needs.pre-release-validation.outputs.version }} to staging..." >> $GITHUB_STEP_SUMMARY
# 这里添加实际的部署逻辑
# 例如:上传到服务器、更新容器等
echo "✅ Successfully deployed to staging!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔗 **Staging URL**: https://staging.example.com" >> $GITHUB_STEP_SUMMARY
- name: 🧪 Run smoke tests
run: |
echo "## 🧪 Smoke Tests" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# 运行冒烟测试
# curl -f https://staging.example.com/health || exit 1
echo "✅ Smoke tests passed!" >> $GITHUB_STEP_SUMMARY
# ============================================================================
# 部署到 Production
# ============================================================================
deploy-production:
name: 🌟 Deploy to Production
runs-on: ubuntu-latest
needs: [pre-release-validation, build-release, deploy-staging]
if: |
needs.pre-release-validation.outputs.should-deploy == 'true' &&
(github.event.inputs.environment == 'production' || github.event_name == 'release')
environment:
name: production
url: https://console.example.com
steps:
- name: 📥 Download build artifacts
uses: actions/download-artifact@v4
with:
name: release-build-${{ needs.pre-release-validation.outputs.version }}
- name: 🌟 Deploy to production
run: |
echo "## 🌟 Production Deployment" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Deploying version ${{ needs.pre-release-validation.outputs.version }} to production..." >> $GITHUB_STEP_SUMMARY
# 这里添加实际的部署逻辑
# 例如:蓝绿部署、滚动更新等
echo "✅ Successfully deployed to production!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔗 **Production URL**: https://console.example.com" >> $GITHUB_STEP_SUMMARY
- name: 🧪 Run production health checks
run: |
echo "## 🏥 Health Checks" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# 运行生产环境健康检查
# curl -f https://console.example.com/health || exit 1
echo "✅ Production health checks passed!" >> $GITHUB_STEP_SUMMARY
- name: 📊 Performance monitoring
run: |
echo "## 📊 Performance Monitoring" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔍 Monitoring deployment performance..." >> $GITHUB_STEP_SUMMARY
echo "📈 Performance metrics will be available in the monitoring dashboard." >> $GITHUB_STEP_SUMMARY
# ============================================================================
# 创建 GitHub Release
# ============================================================================
create-release:
name: 📝 Create GitHub Release
runs-on: ubuntu-latest
needs: [pre-release-validation, build-release]
if: needs.pre-release-validation.outputs.should-deploy == 'true' && github.event_name == 'push'
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📥 Download build artifacts
uses: actions/download-artifact@v4
with:
name: release-build-${{ needs.pre-release-validation.outputs.version }}
- name: 📝 Generate changelog
id: changelog
run: |
echo "## 🎉 What's New in ${{ needs.pre-release-validation.outputs.version }}" > CHANGELOG.md
echo "" >> CHANGELOG.md
# 获取上一个标签
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREVIOUS_TAG" ]; then
echo "### 🔄 Changes since $PREVIOUS_TAG" >> CHANGELOG.md
echo "" >> CHANGELOG.md
# 生成提交日志
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> CHANGELOG.md
else
echo "### 🎉 Initial Release" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "This is the first release of the config-helpers module with comprehensive testing suite." >> CHANGELOG.md
fi
echo "" >> CHANGELOG.md
echo "### 🧪 Testing" >> CHANGELOG.md
echo "- ✅ Unit tests: 100% coverage" >> CHANGELOG.md
echo "- ✅ Integration tests: All scenarios covered" >> CHANGELOG.md
echo "- ✅ Performance tests: All benchmarks passed" >> CHANGELOG.md
echo "- ✅ Browser compatibility: Chrome, Firefox, Safari" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "### 📦 Assets" >> CHANGELOG.md
echo "- \`release-${{ needs.pre-release-validation.outputs.version }}.tar.gz\` - Complete build package" >> CHANGELOG.md
- name: 🏷️ Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.pre-release-validation.outputs.version }}
release_name: Release ${{ needs.pre-release-validation.outputs.version }}
body_path: CHANGELOG.md
draft: false
prerelease: ${{ contains(needs.pre-release-validation.outputs.version, '-') }}
- name: 📤 Upload release assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release-${{ needs.pre-release-validation.outputs.version }}.tar.gz
asset_name: release-${{ needs.pre-release-validation.outputs.version }}.tar.gz
asset_content_type: application/gzip
# ============================================================================
# 发布后通知
# ============================================================================
post-release:
name: 📢 Post-Release Notifications
runs-on: ubuntu-latest
needs: [pre-release-validation, deploy-production, create-release]
if: always() && needs.pre-release-validation.outputs.should-deploy == 'true'
steps:
- name: 📢 Success notification
if: needs.deploy-production.result == 'success'
run: |
echo "# 🎉 Release Successful!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📋 Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ needs.pre-release-validation.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Environment**: Production" >> $GITHUB_STEP_SUMMARY
echo "- **Status**: ✅ Deployed Successfully" >> $GITHUB_STEP_SUMMARY
echo "- **URL**: https://console.example.com" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 🔗 Quick Links" >> $GITHUB_STEP_SUMMARY
echo "- [Production Site](https://console.example.com)" >> $GITHUB_STEP_SUMMARY
echo "- [Monitoring Dashboard](https://monitoring.example.com)" >> $GITHUB_STEP_SUMMARY
echo "- [Release Notes](https://github.com/${{ github.repository }}/releases/tag/${{ needs.pre-release-validation.outputs.version }})" >> $GITHUB_STEP_SUMMARY
- name: 📢 Failure notification
if: needs.deploy-production.result == 'failure'
run: |
echo "# ❌ Release Failed!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The deployment to production failed. Please check the logs and retry." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 🔧 Next Steps" >> $GITHUB_STEP_SUMMARY
echo "1. Review the deployment logs" >> $GITHUB_STEP_SUMMARY
echo "2. Fix any issues found" >> $GITHUB_STEP_SUMMARY
echo "3. Re-run the deployment workflow" >> $GITHUB_STEP_SUMMARY