Skip to content

Commit 8329fac

Browse files
CopilotspiritLHLS
andcommitted
Fix workflow to commit binaries to repository and improve error handling
Co-authored-by: spiritLHLS <103393591+spiritLHLS@users.noreply.github.com>
1 parent 44ed7a3 commit 8329fac

1 file changed

Lines changed: 76 additions & 10 deletions

File tree

.github/workflows/build.yml

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,14 @@ jobs:
327327
fi
328328
329329
echo "Building STREAM with CC=$CC and CFLAGS=$CFLAGS"
330+
echo "Target: ${{ matrix.target }}"
330331
331332
# 编译 STREAM C 版本
332333
echo "=== Building STREAM C version ==="
333334
334335
# 对于某些特殊架构,可能需要特殊处理
335336
BUILD_SUCCESS=false
337+
BUILD_ERROR=""
336338
337339
# macOS 特殊编译选项
338340
if [[ "${{ runner.os }}" == "macOS" && "${{ matrix.use_openmp }}" == "true" ]]; then
@@ -352,14 +354,22 @@ jobs:
352354
{
353355
echo "Even basic compilation failed, trying minimal flags..."
354356
$CC -O2 -static stream.c -o stream_c${{ matrix.ext }} && BUILD_SUCCESS=true || \
355-
$CC stream.c -o stream_c${{ matrix.ext }} && BUILD_SUCCESS=true
357+
$CC stream.c -o stream_c${{ matrix.ext }} && BUILD_SUCCESS=true || \
358+
{
359+
BUILD_ERROR="All compilation attempts failed for ${{ matrix.target }}"
360+
echo "ERROR: $BUILD_ERROR"
361+
}
356362
}
357363
}
358364
fi
359365
360366
if [[ "$BUILD_SUCCESS" != "true" ]]; then
361-
echo "ERROR: Failed to build C version for ${{ matrix.target }}"
362-
exit 1
367+
# 记录失败但不退出,让其他架构继续构建
368+
echo "FAILED: ${{ matrix.target }} - $BUILD_ERROR"
369+
echo "${{ matrix.target }}: FAILED - $BUILD_ERROR" > ../build-failure.log
370+
# 创建一个空的标记文件,表示此架构构建失败
371+
echo "Build failed: $BUILD_ERROR" > "../bin/FAILED-${{ matrix.target }}.txt"
372+
exit 0 # 不要因为单个架构失败而终止整个构建
363373
fi
364374
365375
# 尝试编译 Fortran 版本 (如果有 Fortran 编译器)
@@ -445,7 +455,7 @@ jobs:
445455
fi
446456
fi
447457
448-
continue-on-error: true
458+
continue-on-error: false # 改为 false,让失败的构建显示为失败但不阻止其他构建
449459

450460
- name: Upload binary artifact
451461
uses: actions/upload-artifact@v4
@@ -464,6 +474,7 @@ jobs:
464474
uses: actions/checkout@v4
465475
with:
466476
token: ${{ secrets.GITHUB_TOKEN }}
477+
fetch-depth: 0 # 获取完整历史以便于提交
467478

468479
- name: Checkout STREAM source
469480
uses: actions/checkout@v4
@@ -484,6 +495,9 @@ jobs:
484495
# 从所有构建工件中复制文件到 bin 目录
485496
find artifacts/ -type f -name "stream-*" -exec cp {} bin/ \;
486497
498+
# 复制失败标记文件(如果有的话)
499+
find artifacts/ -type f -name "FAILED-*.txt" -exec cp {} bin/ \; 2>/dev/null || true
500+
487501
# 给所有二进制文件添加执行权限
488502
chmod +x bin/stream-* 2>/dev/null || true
489503
@@ -638,24 +652,76 @@ jobs:
638652
echo "" >> bin/ARCHITECTURES.md
639653
640654
for arch in amd64 386 arm64 arm riscv64 ppc64le ppc64 s390x mips mipsle mips64 mips64le; do
641-
count=$(ls bin/stream-linux-${arch}* 2>/dev/null | wc -l)
655+
count=$(ls bin/stream-linux-${arch}* 2>/dev/null | grep -v "FAILED" | wc -l)
656+
failed_file="bin/FAILED-linux-${arch}.txt"
642657
if [ $count -gt 0 ]; then
643658
echo "✅ linux-${arch}: $count binaries" >> bin/ARCHITECTURES.md
644-
ls bin/stream-linux-${arch}* 2>/dev/null | sed 's/^bin\// - /' >> bin/ARCHITECTURES.md
659+
ls bin/stream-linux-${arch}* 2>/dev/null | grep -v "FAILED" | sed 's/^bin\// - /' >> bin/ARCHITECTURES.md
660+
elif [ -f "$failed_file" ]; then
661+
echo "❌ linux-${arch}: build failed - $(cat "$failed_file")" >> bin/ARCHITECTURES.md
645662
else
646-
echo "linux-${arch}: build failed" >> bin/ARCHITECTURES.md
663+
echo "⚠️ linux-${arch}: no artifacts found (build may have been skipped)" >> bin/ARCHITECTURES.md
647664
fi
648665
echo "" >> bin/ARCHITECTURES.md
649666
done
650667
651668
# 统计其他平台
652-
darwin_count=$(ls bin/stream-darwin-* 2>/dev/null | wc -l)
653-
windows_count=$(ls bin/stream-windows-* 2>/dev/null | wc -l)
669+
darwin_count=$(ls bin/stream-darwin-* 2>/dev/null | grep -v "FAILED" | wc -l)
670+
windows_count=$(ls bin/stream-windows-* 2>/dev/null | grep -v "FAILED" | wc -l)
654671
655672
echo "Other platforms:" >> bin/ARCHITECTURES.md
656673
echo "✅ macOS: $darwin_count binaries" >> bin/ARCHITECTURES.md
657674
echo "✅ Windows: $windows_count binaries" >> bin/ARCHITECTURES.md
658675
echo "" >> bin/ARCHITECTURES.md
659676
660-
total_binaries=$(ls bin/stream-* 2>/dev/null | grep -v -E '\.(md|txt)' | wc -l)
677+
total_binaries=$(ls bin/stream-* 2>/dev/null | grep -v -E '\.(md|txt)' | grep -v "FAILED" | wc -l)
678+
failed_builds=$(ls bin/FAILED-*.txt 2>/dev/null | wc -l)
661679
echo "**Total: $total_binaries STREAM binaries built**" >> bin/ARCHITECTURES.md
680+
if [ $failed_builds -gt 0 ]; then
681+
echo "**Failed: $failed_builds build failures**" >> bin/ARCHITECTURES.md
682+
fi
683+
684+
- name: Configure Git for automated commits
685+
run: |
686+
git config --local user.email "action@github.com"
687+
git config --local user.name "GitHub Action"
688+
689+
- name: Commit and push binaries to repository
690+
run: |
691+
# 计算统计数据
692+
total_binaries=$(ls bin/stream-* 2>/dev/null | grep -v -E '\.(md|txt)' | grep -v "FAILED" | wc -l)
693+
linux_count=$(ls bin/stream-linux-* 2>/dev/null | grep -v "FAILED" | wc -l)
694+
darwin_count=$(ls bin/stream-darwin-* 2>/dev/null | grep -v "FAILED" | wc -l)
695+
windows_count=$(ls bin/stream-windows-* 2>/dev/null | grep -v "FAILED" | wc -l)
696+
697+
# 检查是否有变化
698+
if [[ $(git status --porcelain bin/) ]]; then
699+
echo "Changes detected in bin/ directory, committing..."
700+
701+
# 添加所有 bin/ 目录下的文件
702+
git add bin/
703+
704+
# 创建提交信息
705+
COMMIT_MSG="🚀 Auto-build: Update STREAM binaries from workflow run ${{ github.run_number }}
706+
707+
Built ${total_binaries} binaries across multiple architectures:
708+
- Linux: ${linux_count} binaries
709+
- macOS: ${darwin_count} binaries
710+
- Windows: ${windows_count} binaries
711+
712+
Workflow: ${{ github.workflow }}
713+
Run ID: ${{ github.run_id }}
714+
Commit: ${{ github.sha }}
715+
Actor: ${{ github.actor }}"
716+
717+
# 提交更改
718+
git commit -m "$COMMIT_MSG"
719+
720+
# 推送到 main 分支
721+
echo "Pushing binaries to main branch..."
722+
git push origin HEAD:main
723+
724+
echo "✅ Successfully committed and pushed ${total_binaries} binaries to repository"
725+
else
726+
echo "No changes detected in bin/ directory, skipping commit"
727+
fi

0 commit comments

Comments
 (0)