|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: '版本号 (如: 0.7.1, 1.0.0-beta.1)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + prerelease: |
| 11 | + description: '是否为预发布版本' |
| 12 | + required: false |
| 13 | + type: boolean |
| 14 | + default: false |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + create-release: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v5 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Validate version format |
| 30 | + run: | |
| 31 | + VERSION="${{ github.event.inputs.version }}" |
| 32 | + if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$'; then |
| 33 | + echo "❌ 错误: 无效的版本格式。请使用语义化版本 (如 1.2.3)" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + echo "✅ 版本格式验证通过: $VERSION" |
| 37 | +
|
| 38 | + - name: Check if tag exists |
| 39 | + run: | |
| 40 | + VERSION="${{ github.event.inputs.version }}" |
| 41 | + if git rev-parse "v$VERSION" >/dev/null 2>&1; then |
| 42 | + echo "❌ 错误: 标签 v$VERSION 已存在" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + echo "✅ 标签检查通过" |
| 46 | +
|
| 47 | + - name: Setup Git |
| 48 | + run: | |
| 49 | + git config user.name "github-actions[bot]" |
| 50 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 51 | +
|
| 52 | + - name: Update version file |
| 53 | + run: | |
| 54 | + VERSION="${{ github.event.inputs.version }}" |
| 55 | + VERSION_FILE="internal/version.go" |
| 56 | + |
| 57 | + echo "📝 更新版本文件: $VERSION_FILE" |
| 58 | + sed -i "s/const RuntimeVersion = \".*\"/const RuntimeVersion = \"$VERSION\"/" "$VERSION_FILE" |
| 59 | + |
| 60 | + # 验证更新 |
| 61 | + NEW_VERSION=$(grep 'const RuntimeVersion' "$VERSION_FILE" | sed 's/.*"\(.*\)".*/\1/') |
| 62 | + if [ "$NEW_VERSION" != "$VERSION" ]; then |
| 63 | + echo "❌ 错误: 版本更新失败" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + echo "✅ 版本已更新为: $VERSION" |
| 67 | +
|
| 68 | + - name: Commit and push version bump |
| 69 | + run: | |
| 70 | + VERSION="${{ github.event.inputs.version }}" |
| 71 | + git add internal/version.go |
| 72 | + git commit -m "chore: bump version to $VERSION" |
| 73 | + git push origin main |
| 74 | +
|
| 75 | + - name: Create and push tag |
| 76 | + run: | |
| 77 | + VERSION="${{ github.event.inputs.version }}" |
| 78 | + git tag -a "v$VERSION" -m "Release v$VERSION" |
| 79 | + git push origin "v$VERSION" |
| 80 | + echo "✅ 已创建并推送标签: v$VERSION" |
| 81 | +
|
| 82 | + - name: Wait for tag to be available |
| 83 | + run: | |
| 84 | + echo "⏳ 等待 tag 同步到 GitHub..." |
| 85 | + sleep 5 |
| 86 | + echo "✅ Tag 应该已经可用,GoReleaser 即将开始工作" |
| 87 | +
|
| 88 | + - name: Summary |
| 89 | + run: | |
| 90 | + VERSION="${{ github.event.inputs.version }}" |
| 91 | + echo "### 🎉 版本发布已启动!" >> $GITHUB_STEP_SUMMARY |
| 92 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 93 | + echo "**版本:** v$VERSION" >> $GITHUB_STEP_SUMMARY |
| 94 | + echo "**标签:** v$VERSION" >> $GITHUB_STEP_SUMMARY |
| 95 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 96 | + echo "## 📋 后续自动流程" >> $GITHUB_STEP_SUMMARY |
| 97 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 98 | + echo "1. ✅ 版本文件已更新 (\`internal/version.go\`)" >> $GITHUB_STEP_SUMMARY |
| 99 | + echo "2. ✅ Git 标签已创建并推送 (\`v$VERSION\`)" >> $GITHUB_STEP_SUMMARY |
| 100 | + echo "3. 🔄 [GoReleaser workflow](https://github.com/${{ github.repository }}/actions/workflows/go-releaser.yml) 正在构建..." >> $GITHUB_STEP_SUMMARY |
| 101 | + echo " - 构建所有平台的二进制文件" >> $GITHUB_STEP_SUMMARY |
| 102 | + echo " - 生成 checksums 和签名" >> $GITHUB_STEP_SUMMARY |
| 103 | + echo " - 创建 draft release 和 changelog" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo " - 上传所有构建产物" >> $GITHUB_STEP_SUMMARY |
| 105 | + echo "4. 🔄 [Inno Setup workflow](https://github.com/${{ github.repository }}/actions/workflows/compile-inno-setup.yml) 将编译 Windows 安装包..." >> $GITHUB_STEP_SUMMARY |
| 106 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 107 | + echo "## ⏭️ 下一步操作" >> $GITHUB_STEP_SUMMARY |
| 108 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 109 | + echo "1. 等待 GoReleaser 和 Inno Setup workflows 完成(约 10-15 分钟)" >> $GITHUB_STEP_SUMMARY |
| 110 | + echo "2. 访问 [Releases 页面](https://github.com/${{ github.repository }}/releases)" >> $GITHUB_STEP_SUMMARY |
| 111 | + echo "3. 找到 \`v$VERSION\` 的 draft release" >> $GITHUB_STEP_SUMMARY |
| 112 | + echo "4. 检查 changelog 和所有附件是否完整" >> $GITHUB_STEP_SUMMARY |
| 113 | + echo "5. 点击 **Publish release** 正式发布" >> $GITHUB_STEP_SUMMARY |
| 114 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 115 | + echo "---" >> $GITHUB_STEP_SUMMARY |
| 116 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 117 | + echo "💡 **提示:** GoReleaser 会自动创建 draft release,你只需要最后点击发布按钮即可!" >> $GITHUB_STEP_SUMMARY |
| 118 | +
|
| 119 | + notify: |
| 120 | + needs: create-release |
| 121 | + runs-on: ubuntu-latest |
| 122 | + steps: |
| 123 | + - name: Summary |
| 124 | + run: | |
| 125 | + echo "### 🎉 发版流程已启动!" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 127 | + echo "**版本:** v${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 128 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 129 | + echo "**后续步骤:**" >> $GITHUB_STEP_SUMMARY |
| 130 | + echo "1. ✅ 版本号已更新" >> $GITHUB_STEP_SUMMARY |
| 131 | + echo "2. ✅ Git 标签已创建" >> $GITHUB_STEP_SUMMARY |
| 132 | + echo "3. 🔄 GoReleaser 正在构建资源..." >> $GITHUB_STEP_SUMMARY |
| 133 | + echo "4. 🔄 Inno Setup 将编译 Windows 安装包..." >> $GITHUB_STEP_SUMMARY |
| 134 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 135 | + echo "**注意:** 请等待所有 workflow 完成后,在 [Releases](https://github.com/${{ github.repository }}/releases) 页面发布版本。" >> $GITHUB_STEP_SUMMARY |
0 commit comments