|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: "Version to release (e.g., v1.0.0)" |
| 11 | + required: true |
| 12 | + default: "v1.0.0" |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Set up Go |
| 25 | + uses: actions/setup-go@v5 |
| 26 | + with: |
| 27 | + go-version: "latest" |
| 28 | + cache: true |
| 29 | + |
| 30 | + - name: Cache Go modules |
| 31 | + uses: actions/cache@v4 |
| 32 | + with: |
| 33 | + path: ~/go/pkg/mod |
| 34 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 35 | + restore-keys: | |
| 36 | + ${{ runner.os }}-go- |
| 37 | +
|
| 38 | + - name: Download dependencies |
| 39 | + run: go mod download |
| 40 | + |
| 41 | + - name: Verify dependencies |
| 42 | + run: go mod verify |
| 43 | + |
| 44 | + - name: Run tests |
| 45 | + run: go test -v ./... |
| 46 | + |
| 47 | + - name: Install UPX |
| 48 | + run: | |
| 49 | + sudo apt-get update |
| 50 | + sudo apt-get install -y upx |
| 51 | +
|
| 52 | + - name: Get version |
| 53 | + id: version |
| 54 | + run: | |
| 55 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 56 | + echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT |
| 57 | + else |
| 58 | + echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 59 | + fi |
| 60 | +
|
| 61 | + - name: Build for multiple platforms |
| 62 | + run: | |
| 63 | + # 创建发布目录 |
| 64 | + mkdir -p release |
| 65 | +
|
| 66 | + # 构建 Mac 版本 |
| 67 | + echo "构建 Mac 版本..." |
| 68 | + GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -trimpath -o release/cert-deploy-mac main.go |
| 69 | + GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -trimpath -o release/cert-deploy-mac-arm64 main.go |
| 70 | +
|
| 71 | + # 构建 Linux 版本 |
| 72 | + echo "构建 Linux 版本..." |
| 73 | + GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -trimpath -o release/cert-deploy-linux main.go |
| 74 | + GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -trimpath -o release/cert-deploy-linux-arm64 main.go |
| 75 | +
|
| 76 | + # 构建 Windows 版本 |
| 77 | + echo "构建 Windows 版本..." |
| 78 | + GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -trimpath -o release/cert-deploy-windows.exe main.go |
| 79 | + GOOS=windows GOARCH=arm64 go build -ldflags="-s -w" -trimpath -o release/cert-deploy-windows-arm64.exe main.go |
| 80 | +
|
| 81 | + - name: Show build info |
| 82 | + run: | |
| 83 | + echo "=== 构建信息 ===" |
| 84 | + echo "版本: ${{ steps.version.outputs.VERSION }}" |
| 85 | + echo "Go 版本: $(go version)" |
| 86 | + echo "UPX 版本: $(upx --version)" |
| 87 | + echo "构建文件:" |
| 88 | + ls -lh release/cert-deploy-* |
| 89 | +
|
| 90 | + - name: Compress with UPX |
| 91 | + run: | |
| 92 | + echo "开始 UPX 压缩..." |
| 93 | + upx --best release/cert-deploy-* |
| 94 | + echo "压缩完成" |
| 95 | + echo "压缩后文件大小:" |
| 96 | + ls -lh release/cert-deploy-* |
| 97 | +
|
| 98 | + - name: Create release packages |
| 99 | + run: | |
| 100 | + # 创建各平台的发布包 |
| 101 | + cd release |
| 102 | +
|
| 103 | + # Mac 包 |
| 104 | + tar -czf cert-deploy-mac-${{ steps.version.outputs.VERSION }}.tar.gz cert-deploy-mac cert-deploy-mac-arm64 |
| 105 | + echo "Mac 包大小: $(du -h cert-deploy-mac-${{ steps.version.outputs.VERSION }}.tar.gz)" |
| 106 | +
|
| 107 | + # Linux 包 |
| 108 | + tar -czf cert-deploy-linux-${{ steps.version.outputs.VERSION }}.tar.gz cert-deploy-linux cert-deploy-linux-arm64 |
| 109 | + echo "Linux 包大小: $(du -h cert-deploy-linux-${{ steps.version.outputs.VERSION }}.tar.gz)" |
| 110 | +
|
| 111 | + # Windows 包 |
| 112 | + zip -r cert-deploy-windows-${{ steps.version.outputs.VERSION }}.zip cert-deploy-windows*.exe |
| 113 | + echo "Windows 包大小: $(du -h cert-deploy-windows-${{ steps.version.outputs.VERSION }}.zip)" |
| 114 | +
|
| 115 | + # 创建通用包 |
| 116 | + tar -czf cert-deploy-${{ steps.version.outputs.VERSION }}.tar.gz cert-deploy-* |
| 117 | + echo "通用包大小: $(du -h cert-deploy-${{ steps.version.outputs.VERSION }}.tar.gz)" |
| 118 | +
|
| 119 | + # 复制配置文件 |
| 120 | + cp ../config.yaml . |
| 121 | + cp ../README.md . |
| 122 | +
|
| 123 | + - name: Generate checksums |
| 124 | + run: | |
| 125 | + cd release |
| 126 | + sha256sum cert-deploy-* > checksums.txt |
| 127 | + echo "生成校验和文件" |
| 128 | +
|
| 129 | + - name: Upload release artifacts |
| 130 | + uses: actions/upload-artifact@v4 |
| 131 | + with: |
| 132 | + name: release-files |
| 133 | + path: release/ |
| 134 | + retention-days: 30 |
| 135 | + |
| 136 | + - name: Create GitHub Release |
| 137 | + uses: softprops/action-gh-release@v2 |
| 138 | + if: github.event_name == 'push' |
| 139 | + with: |
| 140 | + files: | |
| 141 | + release/cert-deploy-mac-${{ steps.version.outputs.VERSION }}.tar.gz |
| 142 | + release/cert-deploy-linux-${{ steps.version.outputs.VERSION }}.tar.gz |
| 143 | + release/cert-deploy-windows-${{ steps.version.outputs.VERSION }}.zip |
| 144 | + release/cert-deploy-${{ steps.version.outputs.VERSION }}.tar.gz |
| 145 | + release/checksums.txt |
| 146 | + body: | |
| 147 | + ## 证书部署工具 ${{ steps.version.outputs.VERSION }} |
| 148 | +
|
| 149 | + ### 下载说明 |
| 150 | +
|
| 151 | + - **Mac**: `cert-deploy-mac-${{ steps.version.outputs.VERSION }}.tar.gz` |
| 152 | + - **Linux**: `cert-deploy-linux-${{ steps.version.outputs.VERSION }}.tar.gz` |
| 153 | + - **Windows**: `cert-deploy-windows-${{ steps.version.outputs.VERSION }}.zip` |
| 154 | + - **通用包**: `cert-deploy-${{ steps.version.outputs.VERSION }}.tar.gz` |
| 155 | +
|
| 156 | + ### 安装使用 |
| 157 | +
|
| 158 | + 1. 下载对应平台的压缩包 |
| 159 | + 2. 解压到目标目录 |
| 160 | + 3. 配置 `config.yaml` 文件 |
| 161 | + 4. 运行 `./cert-deploy daemon` 启动服务 |
| 162 | +
|
| 163 | + ### 校验文件 |
| 164 | +
|
| 165 | + 请使用 `checksums.txt` 文件验证下载的完整性。 |
| 166 | + draft: false |
| 167 | + prerelease: false |
| 168 | + |
| 169 | + - name: Create Manual Release |
| 170 | + uses: softprops/action-gh-release@v2 |
| 171 | + if: github.event_name == 'workflow_dispatch' |
| 172 | + with: |
| 173 | + tag_name: ${{ steps.version.outputs.VERSION }} |
| 174 | + name: Release ${{ steps.version.outputs.VERSION }} |
| 175 | + files: | |
| 176 | + release/cert-deploy-mac-${{ steps.version.outputs.VERSION }}.tar.gz |
| 177 | + release/cert-deploy-linux-${{ steps.version.outputs.VERSION }}.tar.gz |
| 178 | + release/cert-deploy-windows-${{ steps.version.outputs.VERSION }}.zip |
| 179 | + release/cert-deploy-${{ steps.version.outputs.VERSION }}.tar.gz |
| 180 | + release/checksums.txt |
| 181 | + body: | |
| 182 | + ## 证书部署工具 ${{ steps.version.outputs.VERSION }} |
| 183 | +
|
| 184 | + ### 下载说明 |
| 185 | +
|
| 186 | + - **Mac**: `cert-deploy-mac-${{ steps.version.outputs.VERSION }}.tar.gz` |
| 187 | + - **Linux**: `cert-deploy-linux-${{ steps.version.outputs.VERSION }}.tar.gz` |
| 188 | + - **Windows**: `cert-deploy-windows-${{ steps.version.outputs.VERSION }}.zip` |
| 189 | + - **通用包**: `cert-deploy-${{ steps.version.outputs.VERSION }}.tar.gz` |
| 190 | +
|
| 191 | + ### 安装使用 |
| 192 | +
|
| 193 | + 1. 下载对应平台的压缩包 |
| 194 | + 2. 解压到目标目录 |
| 195 | + 3. 配置 `config.yaml` 文件 |
| 196 | + 4. 运行 `./cert-deploy daemon` 启动服务 |
| 197 | +
|
| 198 | + ### 校验文件 |
| 199 | +
|
| 200 | + 请使用 `checksums.txt` 文件验证下载的完整性。 |
| 201 | + draft: false |
| 202 | + prerelease: false |
0 commit comments