添加修复脚本和说明文档 #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # 当推送以 v 开头的标签时触发(如 v1.0.0) | |
| workflow_dispatch: # 允许手动触发 | |
| inputs: | |
| version: | |
| description: '版本号 (例如: v1.0.0)' | |
| required: true | |
| type: string | |
| jobs: | |
| build: | |
| name: Build (${{ matrix.goos }}-${{ matrix.goarch }}) | |
| runs-on: ubuntu-latest | |
| continue-on-error: false | |
| strategy: | |
| fail-fast: false # 让各平台独立构建,一个失败不影响其他 | |
| matrix: | |
| include: | |
| - goos: linux | |
| goarch: amd64 | |
| ext: "" | |
| - goos: linux | |
| goarch: arm64 | |
| ext: "" | |
| - goos: darwin | |
| goarch: amd64 | |
| ext: "" | |
| - goos: darwin | |
| goarch: arm64 | |
| ext: "" | |
| - goos: windows | |
| goarch: amd64 | |
| ext: ".exe" | |
| - goos: windows | |
| goarch: arm64 | |
| ext: ".exe" | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Get version from tag | |
| id: tag | |
| shell: bash | |
| 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}" | |
| - name: Build binary | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| CGO_ENABLED: 0 | |
| run: | | |
| set -e # 遇到错误立即退出 | |
| echo "Building for ${{ matrix.goos }}/${{ matrix.goarch }}" | |
| OUTPUT_NAME="cloudbot${{ matrix.ext }}" | |
| FINAL_NAME="cloudbot-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}" | |
| echo "Output name: ${OUTPUT_NAME}" | |
| echo "Final name: ${FINAL_NAME}" | |
| # 构建 | |
| go build -v -ldflags="-s -w -X main.version=${{ steps.tag.outputs.version }}" \ | |
| -o "${OUTPUT_NAME}" \ | |
| ./cmd/cloudbot | |
| # 验证文件是否存在 | |
| if [ ! -f "${OUTPUT_NAME}" ]; then | |
| echo "Error: Build failed, output file not found" | |
| exit 1 | |
| fi | |
| # 创建发布目录 | |
| mkdir -p release | |
| # 移动文件 | |
| mv "${OUTPUT_NAME}" "release/${FINAL_NAME}" | |
| echo "Build successful: release/${FINAL_NAME}" | |
| ls -lh "release/${FINAL_NAME}" | |
| - name: Create checksum | |
| shell: bash | |
| run: | | |
| set -e | |
| cd release | |
| FILE="cloudbot-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}" | |
| if [ ! -f "${FILE}" ]; then | |
| echo "Error: File not found: ${FILE}" | |
| exit 1 | |
| fi | |
| echo "Creating checksum for: ${FILE}" | |
| if [ "${{ matrix.goos }}" == "windows" ]; then | |
| sha256sum "${FILE}" > "${FILE}.sha256" | |
| else | |
| shasum -a 256 "${FILE}" > "${FILE}.sha256" | |
| fi | |
| echo "Checksum created: ${FILE}.sha256" | |
| cat "${FILE}.sha256" | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: cloudbot-${{ matrix.goos }}-${{ matrix.goarch }} | |
| path: | | |
| release/cloudbot-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }} | |
| release/cloudbot-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}.sha256 | |
| retention-days: 30 | |
| if-no-files-found: error | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| if: always() # 即使部分构建失败也创建 release | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get version from tag | |
| id: tag | |
| shell: bash | |
| 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}" | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| pattern: cloudbot-* | |
| merge-multiple: true | |
| - name: Prepare release files | |
| run: | | |
| mkdir -p release | |
| # 将所有 artifacts 中的文件复制到 release 目录 | |
| find artifacts -type f -name "cloudbot-*" -exec cp {} release/ \; | |
| echo "Release files:" | |
| ls -lh release/ | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.tag.outputs.version }} | |
| name: Release ${{ steps.tag.outputs.version }} | |
| body: | | |
| ## Cloudbot ${{ steps.tag.outputs.version }} | |
| ### 安装方式 | |
| #### 使用 Homebrew (macOS/Linux) | |
| ```bash | |
| brew install lucksec/cloudbot/cloudbot | |
| ``` | |
| #### 手动安装 | |
| 1. 下载对应平台的二进制文件 | |
| 2. 解压并移动到 PATH 目录 | |
| 3. 添加执行权限(Linux/macOS) | |
| ### 支持的平台 | |
| - Linux (amd64, arm64) | |
| - macOS (amd64, arm64) | |
| - Windows (amd64, arm64) | |
| ### 校验文件 | |
| 每个二进制文件都包含对应的 `.sha256` 校验文件,可以使用以下命令验证: | |
| ```bash | |
| # Linux/macOS | |
| shasum -a 256 -c cloudbot-*.sha256 | |
| # Windows (PowerShell) | |
| Get-FileHash cloudbot-*.exe -Algorithm SHA256 | |
| ``` | |
| files: release/* | |
| draft: false | |
| prerelease: false | |
| fail_on_unmatched_files: false # 即使部分文件缺失也继续 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |