From 2674e469b83c2fb470c498a521b79860586519ea Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Thu, 17 Jul 2025 23:00:28 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=B5=8B=E8=AF=95=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-build.yml | 121 ++++++------------------------- 1 file changed, 22 insertions(+), 99 deletions(-) diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 5bb62d4..fea5f7c 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -54,7 +54,7 @@ jobs: - name: 🐹 设置 Go 环境 uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.20' cache: true - name: 📦 下载依赖 @@ -115,78 +115,27 @@ jobs: dist/ retention-days: 7 - - name: 🧪 测试生成的二进制文件 - id: binary_test + - name: 📊 统计构建产物 + id: build_stats run: | - echo "## 🧪 测试二进制文件" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY + if [ -d "dist" ]; then + total_files=$(find dist/ -type f | wc -l) + executable_files=$(find dist/ -type f -executable | wc -l) + config_files=$(find dist/ -name "*.json" -o -name "*.yaml" -o -name "*.yml" -o -name "*.txt" | wc -l) - binary_count=0 - tested_count=0 - passed_count=0 - failed_count=0 - - echo "| 文件名 | 架构 | 大小 | 压缩 | 运行测试 |" >> $GITHUB_STEP_SUMMARY - echo "|--------|------|------|------|----------|" >> $GITHUB_STEP_SUMMARY - - for binary in dist/*/*; do - if [[ -f "$binary" && -x "$binary" ]]; then - binary_count=$((binary_count + 1)) - filename=$(basename "$binary") - - # 获取文件信息 - file_info=$(file "$binary") - size=$(ls -lh "$binary" | awk '{print $5}') - - # 检测架构 - if [[ "$file_info" == *"x86-64"* ]]; then - arch="amd64" - elif [[ "$file_info" == *"ARM"* ]]; then - arch="arm64" - elif [[ "$file_info" == *"386"* ]]; then - arch="386" - else - arch="unknown" - fi - - # 检测是否压缩 - if [[ "$file_info" == *"UPX"* ]]; then - compressed="✅ UPX" - else - compressed="❌ 未压缩" - fi - - # 运行测试(仅对Linux AMD64版本) - if [[ "$binary" == *"linux"* && "$arch" == "amd64" ]]; then - tested_count=$((tested_count + 1)) - if timeout 10s "$binary" --help > /dev/null 2>&1; then - test_result="✅ 通过" - passed_count=$((passed_count + 1)) - else - test_result="❌ 失败" - failed_count=$((failed_count + 1)) - fi - else - test_result="➖ 跳过" - fi - - echo "| $filename | $arch | $size | $compressed | $test_result |" >> $GITHUB_STEP_SUMMARY - fi - done - - echo "" >> $GITHUB_STEP_SUMMARY - echo "**测试统计**: 总计 $binary_count 个文件,测试 $tested_count 个,通过 $passed_count 个,失败 $failed_count 个" >> $GITHUB_STEP_SUMMARY - - # 输出统计信息供后续步骤使用 - echo "binary_count=$binary_count" >> $GITHUB_OUTPUT - echo "tested_count=$tested_count" >> $GITHUB_OUTPUT - echo "passed_count=$passed_count" >> $GITHUB_OUTPUT - echo "failed_count=$failed_count" >> $GITHUB_OUTPUT + echo "total_files=$total_files" >> $GITHUB_OUTPUT + echo "executable_files=$executable_files" >> $GITHUB_OUTPUT + echo "config_files=$config_files" >> $GITHUB_OUTPUT + else + echo "total_files=0" >> $GITHUB_OUTPUT + echo "executable_files=0" >> $GITHUB_OUTPUT + echo "config_files=0" >> $GITHUB_OUTPUT + fi - - name: 📊 生成详细测试报告 + - name: 📊 生成构建报告 if: always() run: | - echo "# 🎯 测试构建详细报告" >> $GITHUB_STEP_SUMMARY + echo "# 🎯 测试构建报告" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY # 基本信息表格 @@ -232,40 +181,15 @@ jobs: echo "## 📦 构建产物统计" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - # 平台支持统计 - echo "### 🎯 平台支持统计" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - - linux_count=$(find dist/ -name "*linux*" -type f | wc -l) - windows_count=$(find dist/ -name "*windows*" -type f | wc -l) - darwin_count=$(find dist/ -name "*darwin*" -type f | wc -l) - amd64_count=$(find dist/ -name "*amd64*" -type f | wc -l) - arm64_count=$(find dist/ -name "*arm64*" -type f | wc -l) - i386_count=$(find dist/ -name "*386*" -type f | wc -l) - - echo "| 平台/架构 | 数量 |" >> $GITHUB_STEP_SUMMARY - echo "|-----------|------|" >> $GITHUB_STEP_SUMMARY - echo "| 🐧 **Linux** | $linux_count |" >> $GITHUB_STEP_SUMMARY - echo "| 🪟 **Windows** | $windows_count |" >> $GITHUB_STEP_SUMMARY - echo "| 🍎 **macOS** | $darwin_count |" >> $GITHUB_STEP_SUMMARY - echo "| 💻 **AMD64** | $amd64_count |" >> $GITHUB_STEP_SUMMARY - echo "| 📱 **ARM64** | $arm64_count |" >> $GITHUB_STEP_SUMMARY - echo "| 🔧 **386** | $i386_count |" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - - # 简化的文件类型统计 + # 文件类型统计 echo "### 📊 文件类型统计" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - total_files=$(find dist/ -type f | wc -l) - executable_files=$(find dist/ -type f -executable | wc -l) - config_files=$(find dist/ -name "*.json" -o -name "*.yaml" -o -name "*.yml" -o -name "*.txt" | wc -l) - echo "| 文件类型 | 数量 |" >> $GITHUB_STEP_SUMMARY echo "|----------|------|" >> $GITHUB_STEP_SUMMARY - echo "| 📁 **总文件数** | $total_files |" >> $GITHUB_STEP_SUMMARY - echo "| 🔧 **可执行文件** | $executable_files |" >> $GITHUB_STEP_SUMMARY - echo "| 📄 **配置文件** | $config_files |" >> $GITHUB_STEP_SUMMARY + echo "| 📁 **总文件数** | ${{ steps.build_stats.outputs.total_files }} |" >> $GITHUB_STEP_SUMMARY + echo "| 🔧 **可执行文件** | ${{ steps.build_stats.outputs.executable_files }} |" >> $GITHUB_STEP_SUMMARY + echo "| 📄 **配置文件** | ${{ steps.build_stats.outputs.config_files }} |" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY # 总产物大小 @@ -287,8 +211,7 @@ jobs: echo "🎉 **构建状态**: ❌ 失败" >> $GITHUB_STEP_SUMMARY fi - echo "📊 **二进制文件**: ${{ steps.binary_test.outputs.binary_count }} 个" >> $GITHUB_STEP_SUMMARY - echo "🧪 **测试通过**: ${{ steps.binary_test.outputs.passed_count }}/${{ steps.binary_test.outputs.tested_count }}" >> $GITHUB_STEP_SUMMARY + echo "📊 **可执行文件**: ${{ steps.build_stats.outputs.executable_files }} 个" >> $GITHUB_STEP_SUMMARY echo "⏱️ **构建耗时**: ${{ steps.build_end.outputs.duration_readable }}" >> $GITHUB_STEP_SUMMARY echo "📦 **产物大小**: $(du -sh dist/ 2>/dev/null | cut -f1 || echo "未知")" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY