-
Notifications
You must be signed in to change notification settings - Fork 992
476 lines (414 loc) · 18.9 KB
/
release.yml
File metadata and controls
476 lines (414 loc) · 18.9 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# Copyright 2025 The ChaosBlade Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 1.8.0)'
required: true
type: string
draft:
description: 'Create as draft release'
required: false
type: boolean
default: false
env:
GO_VERSION: '1.25'
JAVA_VERSION: '11'
REGISTRY: 'ghcr.io'
IMAGE_NAME: 'chaosblade-io/chaosblade'
permissions:
contents: write
packages: write
jobs:
# 多平台构建任务 - 在对应原生平台编译
build-multi-platform:
name: Build - ${{ matrix.os }}-${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- os: linux
arch: amd64
target: linux_amd64
runner: ubuntu-latest
- os: linux
arch: arm64
target: linux_arm64
runner: ubuntu-24.04-arm
use_docker: true
- os: darwin
arch: amd64
target: darwin_amd64
runner: macos-latest
- os: darwin
arch: arm64
target: darwin_arm64
runner: macos-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
package-path: ${{ steps.package.outputs.package-path }}
package-name: ${{ steps.package.outputs.package-name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
continue-on-error: true
- name: Get version information
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
TAG="v$VERSION"
else
TAG="${{ github.ref_name }}"
VERSION="${TAG#v}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "Version: $VERSION, Tag: $TAG"
- name: Set environment variables
run: |
echo "BLADE_VERSION=${{ steps.version.outputs.version }}" >> $GITHUB_ENV
echo "BUILD_TARGET=${{ matrix.target }}" >> $GITHUB_ENV
# 不设置 GOOS 和 GOARCH,让 Go 使用当前运行环境的原生架构
echo "Using native platform: $(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m)"
# 设置 Maven 选项以支持 Lombok 与 Java 的兼容性
echo "MAVEN_OPTS=--add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED" >> $GITHUB_ENV
- name: Set up Docker Buildx (for ARM64)
if: matrix.use_docker == true
uses: docker/setup-buildx-action@v3
- name: Install dependencies
run: |
if [[ "${{ matrix.os }}" == "linux" ]]; then
sudo apt-get update
sudo apt-get install -y musl-tools upx-ucl
elif [[ "${{ matrix.os }}" == "darwin" ]]; then
if ! command -v upx &> /dev/null; then
brew install upx
else
echo "UPX already installed"
fi
fi
- name: Build all components
run: |
echo "Building ChaosBlade for ${{ matrix.target }} with all modules..."
echo "Current platform: $(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m)"
echo "Target platform: ${{ matrix.target }}"
echo "Building for target platform: ${{ matrix.target }}"
make ${{ matrix.target }} MODULES=all
echo "Build completed successfully for ${{ matrix.target }}"
- name: Verify build output
run: |
echo "Verifying build output for ${{ matrix.target }}..."
if [[ -d "target/chaosblade-${{ steps.version.outputs.version }}-${{ matrix.target }}" ]]; then
echo "✅ Build directory exists"
echo "Directory contents:"
ls -la "target/chaosblade-${{ steps.version.outputs.version }}-${{ matrix.target }}/"
# 检查关键文件
if [[ -f "target/chaosblade-${{ steps.version.outputs.version }}-${{ matrix.target }}/blade" ]]; then
echo "✅ blade binary exists"
file "target/chaosblade-${{ steps.version.outputs.version }}-${{ matrix.target }}/blade"
else
echo "❌ blade binary not found"
exit 1
fi
else
echo "❌ Build directory not found"
exit 1
fi
- name: Generate package
id: package
run: |
PACKAGE_NAME="chaosblade-${{ steps.version.outputs.version }}-${{ matrix.target }}.tar.gz"
PACKAGE_PATH="target/$PACKAGE_NAME"
# 检查 tar.gz 文件是否已生成
if [[ -f "$PACKAGE_PATH" ]]; then
echo "✅ Package already exists: $PACKAGE_PATH"
else
echo "❌ Package not found: $PACKAGE_PATH"
echo "Available files in target/:"
ls -la target/
exit 1
fi
echo "package-name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "package-path=$PACKAGE_PATH" >> $GITHUB_OUTPUT
# 显示包信息
echo "Package information:"
ls -lh "$PACKAGE_PATH"
file "$PACKAGE_PATH"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: chaosblade-${{ steps.version.outputs.version }}-${{ matrix.target }}
path: ${{ steps.package.outputs.package-path }}
retention-days: 30
# Docker 镜像构建任务
build-images:
name: Build Docker Images
runs-on: ubuntu-latest
needs: [ build-multi-platform ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_PASSWORD }}
- name: Debug permissions
run: |
echo "GitHub Actor: ${{ github.actor }}"
echo "Repository: ${{ github.repository }}"
echo "Registry: ${{ env.REGISTRY }}"
echo "Image Name: ${{ env.IMAGE_NAME }}"
echo "Version: ${{ needs.build-multi-platform.outputs.version }}"
echo "Full image name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-tool:${{ needs.build-multi-platform.outputs.version }}"
- name: Download Linux AMD64 artifacts
uses: actions/download-artifact@v4
with:
name: chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_amd64
path: artifacts/linux_amd64
- name: Download Linux ARM64 artifacts
uses: actions/download-artifact@v4
with:
name: chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_arm64
path: artifacts/linux_arm64
- name: Prepare artifacts for image build
run: |
# 创建目标目录结构
mkdir -p target/chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_amd64
mkdir -p target/chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_arm64
# 解压 Linux AMD64 包
tar -xzf artifacts/linux_amd64/*.tar.gz -C target/
# 解压 Linux ARM64 包
tar -xzf artifacts/linux_arm64/*.tar.gz -C target/
# 显示目录结构
echo "Linux AMD64 contents:"
ls -la target/chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_amd64/
echo "Linux ARM64 contents:"
ls -la target/chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_arm64/
# 显示版本信息和标签策略
echo "Version: ${{ needs.build-multi-platform.outputs.version }}"
if [[ "${{ needs.build-multi-platform.outputs.version }}" == *"dev"* ]]; then
echo "🔧 Development version detected - will NOT tag as 'latest'"
else
echo "🚀 Release version detected - will tag as 'latest'"
fi
- name: Build and push Linux AMD64 image
uses: docker/build-push-action@v5
with:
context: .
file: build/image/blade/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-tool:${{ needs.build-multi-platform.outputs.version }}
${{ !contains(needs.build-multi-platform.outputs.version, 'dev') && format('{0}/{1}-tool:latest', env.REGISTRY, env.IMAGE_NAME) || '' }}
build-args: |
BLADE_VERSION=${{ needs.build-multi-platform.outputs.version }}
GOOS=linux
GOARCH=amd64
platforms: linux/amd64
- name: Build and push Linux ARM64 image
uses: docker/build-push-action@v5
with:
context: .
file: build/image/blade_arm/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-tool-arm64:${{ needs.build-multi-platform.outputs.version }}
${{ !contains(needs.build-multi-platform.outputs.version, 'dev') && format('{0}/{1}-tool-arm64:latest', env.REGISTRY, env.IMAGE_NAME) || '' }}
build-args: |
BLADE_VERSION=${{ needs.build-multi-platform.outputs.version }}
GOOS=linux
GOARCH=arm64
platforms: linux/arm64
# 创建 GitHub Release
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [ build-multi-platform, build-images ]
if: github.event_name == 'push' || github.event.inputs.version
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Prepare release assets
run: |
# 创建发布目录
mkdir -p release-assets
# 复制所有平台的包
for platform in linux_amd64 linux_arm64 darwin_amd64 darwin_arm64; do
artifact_dir="artifacts/chaosblade-${{ needs.build-multi-platform.outputs.version }}-$platform"
if [[ -d "$artifact_dir" ]]; then
cp "$artifact_dir"/*.tar.gz "release-assets/"
echo "✅ Copied $platform package"
else
echo "❌ Missing $platform package"
fi
done
# 显示发布资产
echo "Release assets:"
ls -la release-assets/
# 生成校验和
cd release-assets
sha256sum *.tar.gz > checksums.txt
echo "Generated checksums:"
cat checksums.txt
- name: Setup OSSUTIL environment
uses: yizhoumo/setup-ossutil@v1.1.3
env:
BINARY_TAG: ${{ needs.build-multi-platform.outputs.version }}
with:
endpoint: ${{ secrets.OSS_ENDPOINT }}
access-key-id: ${{ secrets.OSS_ACCESS_KEY_ID }}
access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
ossutil-version: '1.7.14'
- name: Upload packages to OSS
env:
BINARY_TAG: ${{ needs.build-multi-platform.outputs.version }}
run: |
echo "Uploading ChaosBlade packages to OSS..."
# 上传所有平台的包
for platform in linux_amd64 linux_arm64 darwin_amd64 darwin_arm64; do
package_file="release-assets/chaosblade-${BINARY_TAG}-${platform}.tar.gz"
if [[ -f "$package_file" ]]; then
echo "Uploading $platform package..."
ossutil cp -f "$package_file" "oss://chaosblade/agent/github/${BINARY_TAG}/chaosblade-${BINARY_TAG}-${platform}.tar.gz"
echo "✅ $platform package uploaded successfully"
else
echo "❌ $platform package not found: $package_file"
fi
done
# 上传校验和文件
if [[ -f "release-assets/checksums.txt" ]]; then
echo "Uploading checksums file..."
ossutil cp -f "release-assets/checksums.txt" "oss://chaosblade/agent/github/${BINARY_TAG}/checksums.txt"
echo "✅ Checksums file uploaded successfully"
else
echo "❌ Checksums file not found"
fi
echo "All packages uploaded to OSS successfully"
- name: Generate release notes
run: |
cat > release-assets/RELEASE_NOTES.md << 'EOF'
### 📦 Downloads
Choose the appropriate package for your platform:
**Full Package (All Components):**
- **Linux AMD64**: `chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_amd64.tar.gz` - For 64-bit Linux systems
- **Linux ARM64**: `chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_arm64.tar.gz` - For ARM64 Linux systems
- **Darwin AMD64**: `chaosblade-${{ needs.build-multi-platform.outputs.version }}-darwin_amd64.tar.gz` - For Intel-based macOS
- **Darwin ARM64**: `chaosblade-${{ needs.build-multi-platform.outputs.version }}-darwin_arm64.tar.gz` - For Apple Silicon macOS
**Docker Images:**
- **Linux AMD64**:
`ghcr.io/chaosblade-io/chaosblade-tool:${{ needs.build-multi-platform.outputs.version }}`
`ghcr.io/chaosblade-io/chaosblade-operator:${{ needs.build-multi-platform.outputs.version }}`
- **Linux ARM64**:
`ghcr.io/chaosblade-io/chaosblade-tool-arm64:${{ needs.build-multi-platform.outputs.version }}`
`ghcr.io/chaosblade-io/chaosblade-operator-arm64:${{ needs.build-multi-platform.outputs.version }}`
### 🌐 OSS Download Links
Alternative download links from Alibaba Cloud OSS:
**Full Package (All Components):**
- [chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_amd64.tar.gz](https://chaosblade.oss-cn-hangzhou.aliyuncs.com/agent/github/${{ needs.build-multi-platform.outputs.version }}/chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_amd64.tar.gz)
- [chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_arm64.tar.gz](https://chaosblade.oss-cn-hangzhou.aliyuncs.com/agent/github/${{ needs.build-multi-platform.outputs.version }}/chaosblade-${{ needs.build-multi-platform.outputs.version }}-linux_arm64.tar.gz)
- [chaosblade-${{ needs.build-multi-platform.outputs.version }}-darwin_amd64.tar.gz](https://chaosblade.oss-cn-hangzhou.aliyuncs.com/agent/github/${{ needs.build-multi-platform.outputs.version }}/chaosblade-${{ needs.build-multi-platform.outputs.version }}-darwin_amd64.tar.gz)
- [chaosblade-${{ needs.build-multi-platform.outputs.version }}-darwin_arm64.tar.gz](https://chaosblade.oss-cn-hangzhou.aliyuncs.com/agent/github/${{ needs.build-multi-platform.outputs.version }}/chaosblade-${{ needs.build-multi-platform.outputs.version }}-darwin_arm64.tar.gz)
- [checksums.txt](https://chaosblade.oss-cn-hangzhou.aliyuncs.com/agent/github/${{ needs.build-multi-platform.outputs.version }}/checksums.txt) - SHA256 checksums
### 🔧 Installation
**From Package:**
```bash
# Extract and install
tar -xzf chaosblade-${{ needs.build-multi-platform.outputs.version }}-[platform].tar.gz
cd chaosblade-${{ needs.build-multi-platform.outputs.version }}-[platform]
# Verify installation
blade version
```
### For Kubernetes
#### Install
```
helm repo add chaosblade-io https://chaosblade-io.github.io/charts
helm install chaosblade chaosblade-io/chaosblade-operator --namespace chaosblade
```
Default image repository is `ghcr.io/chaosblade-io/chaosblade-tool` and `ghcr.io/chaosblade-io/chaosblade-operator`, you can append `--set blade.repository` or `--set operator.repository` flag to change the image repository. For examples:
```
helm install chaosblade-operator chaosblade-io/chaosblade-operator --namespace chaosblade --set blade.repository=chaosbladeio/chaosblade-tool,operator.repository=chaosbladeio/chaosblade-operator
```
#### Uninstall
```
helm uninstall chaosblade-operator --namespace chaosblade
```
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: v${{ needs.build-multi-platform.outputs.version }}
draft: ${{ github.event.inputs.draft == 'true' }}
body_path: release-assets/RELEASE_NOTES.md
prerelease: false
generate_release_notes: true
files: |
release-assets/*.tar.gz
release-assets/checksums.txt
tag_name: ${{ needs.build-multi-platform.outputs.tag }}
token: ${{ secrets.GITHUB_TOKEN }}
# 清理任务
cleanup:
name: Cleanup
runs-on: ubuntu-latest
needs: [ build-multi-platform, build-images, create-release ]
if: always()
steps:
- name: Clean up artifacts
run: |
echo "Cleaning up build artifacts..."
# 这里可以添加清理逻辑,比如删除临时文件等
echo "Cleanup completed"