-
Notifications
You must be signed in to change notification settings - Fork 0
216 lines (178 loc) · 6.24 KB
/
Copy pathrelease.yml
File metadata and controls
216 lines (178 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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 }}