Release #21
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*' | |
| 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/[email protected] | |
| 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" |