Skip to content

Commit f6556a6

Browse files
committed
ci: 添加多平台构建和自动发布工作流
添加 GitHub Actions 工作流,用于在推送至 main 分支或创建版本标签时自动构建和发布二进制文件。工作流支持跨平台构建(Windows、Linux、macOS、FreeBSD)并自动创建 GitHub Release,包含所有平台的编译产物和说明文档。
1 parent 81b2b58 commit f6556a6

1 file changed

Lines changed: 237 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
build:
12+
name: Build for ${{ matrix.os }} (${{ matrix.arch }})
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
include:
17+
# Windows
18+
- os: windows-latest
19+
arch: amd64
20+
goos: windows
21+
goarch: amd64
22+
suffix: .exe
23+
- os: windows-latest
24+
arch: 386
25+
goos: windows
26+
goarch: 386
27+
suffix: .exe
28+
29+
# Linux
30+
- os: ubuntu-latest
31+
arch: amd64
32+
goos: linux
33+
goarch: amd64
34+
suffix: ''
35+
- os: ubuntu-latest
36+
arch: 386
37+
goos: linux
38+
goarch: 386
39+
suffix: ''
40+
- os: ubuntu-latest
41+
arch: arm64
42+
goos: linux
43+
goarch: arm64
44+
suffix: ''
45+
46+
# macOS
47+
- os: macos-latest
48+
arch: amd64
49+
goos: darwin
50+
goarch: amd64
51+
suffix: ''
52+
- os: macos-latest
53+
arch: arm64
54+
goos: darwin
55+
goarch: arm64
56+
suffix: ''
57+
58+
# FreeBSD
59+
- os: ubuntu-latest
60+
arch: amd64
61+
goos: freebsd
62+
goarch: amd64
63+
suffix: ''
64+
- os: ubuntu-latest
65+
arch: 386
66+
goos: freebsd
67+
goarch: 386
68+
suffix: ''
69+
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v4
73+
with:
74+
fetch-depth: 0
75+
76+
- name: Set up Go
77+
uses: actions/setup-go@v5
78+
with:
79+
go-version: '1.25'
80+
cache: true
81+
82+
- name: Get version from tag
83+
id: get_version
84+
run: |
85+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
86+
VERSION="${GITHUB_REF#refs/tags/}"
87+
else
88+
VERSION="dev-$(git rev-parse --short HEAD)"
89+
fi
90+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
91+
echo "version=$VERSION" >> $GITHUB_ENV
92+
93+
- name: Build
94+
run: |
95+
# 设置构建参数
96+
OUTPUT_NAME="qdbexploit${{ matrix.suffix }}"
97+
BUILD_FLAGS="-ldflags='-X main.version=${{ env.version }} -s -w'"
98+
99+
# 创建输出目录
100+
mkdir -p dist
101+
102+
# 执行构建
103+
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build $BUILD_FLAGS -o "dist/${OUTPUT_NAME}" .
104+
105+
# 为 Unix 系统添加可执行权限
106+
if [[ "${{ matrix.goos }}" != "windows" ]]; then
107+
chmod +x "dist/${OUTPUT_NAME}"
108+
fi
109+
110+
# 显示构建信息
111+
echo "Built: dist/${OUTPUT_NAME}"
112+
echo "Platform: ${{ matrix.goos }}/${{ matrix.goarch }}"
113+
file "dist/${OUTPUT_NAME}" || true
114+
115+
- name: Upload artifact
116+
uses: actions/upload-artifact@v4
117+
with:
118+
name: qdbexploit-${{ matrix.goos }}-${{ matrix.goarch }}
119+
path: dist/
120+
retention-days: 7
121+
122+
release:
123+
name: Create Release
124+
needs: build
125+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
126+
runs-on: ubuntu-latest
127+
permissions:
128+
contents: write
129+
130+
steps:
131+
- name: Download all artifacts
132+
uses: actions/download-artifact@v4
133+
with:
134+
path: artifacts
135+
136+
- name: List downloaded artifacts
137+
run: |
138+
find artifacts -type f -name "qdbexploit*" | sort
139+
140+
- name: Create release archive
141+
run: |
142+
# 创建临时目录
143+
mkdir -p release
144+
145+
# 复制所有构建产物
146+
find artifacts -type f -name "qdbexploit*" -exec cp {} release/ \;
147+
148+
# 创建 README 文件
149+
cat > release/README.md << 'EOF'
150+
# QuestDB Exploit 发布文件
151+
152+
此目录包含 QuestDB Exploit 工具的多平台可执行文件。
153+
154+
## 文件说明
155+
156+
- `qdbexploit` - Linux/macOS/FreeBSD 可执行文件
157+
- `qdbexploit.exe` - Windows 可执行文件
158+
159+
## 平台支持
160+
161+
| 文件名 | 操作系统 | 架构 |
162+
|--------|----------|------|
163+
| qdbexploit | Linux | amd64, 386, arm64 |
164+
| qdbexploit | macOS | amd64, arm64 |
165+
| qdbexploit | FreeBSD | amd64, 386 |
166+
| qdbexploit.exe | Windows | amd64, 386 |
167+
168+
## 使用说明
169+
170+
1. 下载对应平台的文件
171+
2. 添加可执行权限(Unix 系统):
172+
```bash
173+
chmod +x qdbexploit
174+
```
175+
3. 运行工具:
176+
```bash
177+
./qdbexploit -h
178+
```
179+
180+
## 版本信息
181+
182+
构建时间: $(date)
183+
提交哈希: ${{ github.sha }}
184+
EOF
185+
186+
# 创建压缩包
187+
tar -czf qdbexploit-binaries.tar.gz -C release .
188+
zip -r qdbexploit-binaries.zip release/
189+
190+
# 显示文件列表
191+
echo "=== 发布文件列表 ==="
192+
ls -la *.tar.gz *.zip
193+
echo ""
194+
echo "=== 压缩包内容 ==="
195+
tar -tzf qdbexploit-binaries.tar.gz | head -20
196+
197+
- name: Create GitHub Release
198+
uses: softprops/action-gh-release@v1
199+
with:
200+
name: Release ${{ github.sha }}
201+
body: |
202+
# QuestDB Exploit 自动构建发布
203+
204+
## 构建信息
205+
- **提交**: ${{ github.sha }}
206+
- **触发分支**: ${{ github.ref }}
207+
- **构建时间**: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
208+
209+
## 包含的平台
210+
- **Windows**: amd64, 386
211+
- **Linux**: amd64, 386, arm64
212+
- **macOS**: amd64, arm64
213+
- **FreeBSD**: amd64, 386
214+
215+
## 使用说明
216+
1. 下载对应的压缩包
217+
2. 解压文件
218+
3. 运行对应的可执行文件
219+
220+
### Unix 系统(Linux/macOS/FreeBSD)
221+
```bash
222+
chmod +x qdbexploit
223+
./qdbexploit -h
224+
```
225+
226+
### Windows 系统
227+
```cmd
228+
qdbexploit.exe -h
229+
```
230+
231+
## 文件说明
232+
压缩包中包含所有平台的二进制文件,请根据您的操作系统选择对应的文件。
233+
files: |
234+
qdbexploit-binaries.tar.gz
235+
qdbexploit-binaries.zip
236+
draft: false
237+
prerelease: false

0 commit comments

Comments
 (0)