Test Incus Images #430
This file contains 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: Test Incus Images | ||
on: | ||
schedule: | ||
- cron: '0 4 2-30/2 * *' | ||
workflow_dispatch: | ||
jobs: | ||
prepare-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- id: set-matrix | ||
run: | | ||
# 下载两个平台的镜像列表 | ||
curl -o x86_64_all_images.txt https://raw.githubusercontent.com/oneclickvirt/incus_images/main/x86_64_all_images.txt | ||
curl -o arm64_all_images.txt https://raw.githubusercontent.com/oneclickvirt/incus_images/main/arm64_all_images.txt | ||
echo "构建测试矩阵..." | ||
matrix_json="{\"include\":[" | ||
while IFS= read -r image; do | ||
if [[ -n "$image" ]]; then | ||
matrix_json+="{\"image\":\"$image\",\"arch\":\"amd64\",\"runner\":\"ubuntu-latest\"}," | ||
fi | ||
done < x86_64_all_images.txt | ||
while IFS= read -r image; do | ||
if [[ -n "$image" ]]; then | ||
matrix_json+="{\"image\":\"$image\",\"arch\":\"arm64\",\"runner\":\"ubuntu-24.04-arm\"}," | ||
fi | ||
done < arm64_all_images.txt | ||
# 去掉最后一个逗号 | ||
matrix_json=${matrix_json%,} | ||
matrix_json+="]}" | ||
echo "matrix=$matrix_json" >> "$GITHUB_OUTPUT" | ||
test-single-image: | ||
needs: prepare-matrix | ||
name: test-${{ matrix.image }} | ||
strategy: | ||
fail-fast: false | ||
max-parallel: 12 | ||
matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }} | ||
runs-on: ${{ matrix.runner }} | ||
timeout-minutes: 8 | ||
outputs: | ||
success: ${{ steps.test.outputs.success }} | ||
image: ${{ steps.test.outputs.image }} | ||
arch: ${{ steps.test.outputs.arch }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Fresh Environment | ||
run: | | ||
echo "设置新环境..." | ||
sudo apt-get update -y | ||
sudo sh -c 'export DEBIAN_FRONTEND=noninteractive && curl -L https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/incus_install.sh -o incus_install.sh && chmod +x incus_install.sh && bash incus_install.sh' | ||
- name: Configure Git | ||
run: | | ||
git config --global user.name "daily-test" | ||
git config --global user.email "test@spiritlhl.top" | ||
- name: Test Image | ||
id: test | ||
continue-on-error: true | ||
run: | | ||
echo "测试镜像: ${{ matrix.image }}" | ||
# 备份 DNS 配置 | ||
sudo cp /etc/resolv.conf /etc/resolv.conf.backup || true | ||
if sudo bash test.sh "${{ matrix.image }}"; then | ||
echo "测试通过: ${{ matrix.image }}" | ||
echo "success=true" >> "$GITHUB_OUTPUT" | ||
echo "image=${{ matrix.image }}" >> "$GITHUB_OUTPUT" | ||
echo "arch=${{ matrix.arch }}" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "测试失败: ${{ matrix.image }}" | ||
echo "success=false" >> "$GITHUB_OUTPUT" | ||
echo "image=${{ matrix.image }}" >> "$GITHUB_OUTPUT" | ||
echo "arch=${{ matrix.arch }}" >> "$GITHUB_OUTPUT" | ||
exit 1 | ||
fi | ||
# 还原 DNS 配置 | ||
sudo mv /etc/resolv.conf.backup /etc/resolv.conf || true | ||
collect-single-image: | ||
needs: [prepare-matrix, test-single-image] | ||
name: collect-${{ matrix.image }} | ||
# 关键修复:使用job id而不是动态构造的字符串 | ||
if: ${{ needs.test-single-image.outputs[format('test-{0}', matrix.image)].result == 'success' }} | ||
Check failure on line 93 in .github/workflows/test.yml GitHub Actions / Test Incus ImagesInvalid workflow file
|
||
strategy: | ||
matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Collect Test Result | ||
run: | | ||
# 使用job id获取结果 | ||
JOB_ID="test-${{ matrix.image }}" | ||
echo "收集任务结果,job id: $JOB_ID" | ||
# 读取上游任务的输出 | ||
SUCCESS="${{ needs.test-single-image.outputs[format('test-{0}', matrix.image)].success }}" | ||
IMAGE="${{ needs.test-single-image.outputs[format('test-{0}', matrix.image)].image }}" | ||
ARCH="${{ needs.test-single-image.outputs[format('test-{0}', matrix.image)].arch }}" | ||
echo "结果: success=$SUCCESS, image=$IMAGE, arch=$ARCH" | ||
# 将结果写入文件 | ||
echo "success=$SUCCESS" > result.txt | ||
echo "image=$IMAGE" >> result.txt | ||
echo "arch=$ARCH" >> result.txt | ||
- name: Upload Result Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: result-${{ matrix.image }} | ||
path: result.txt | ||
results-updater: | ||
needs: collect-single-image | ||
if: always() | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Download All Results | ||
uses: actions/download-artifact@v3 | ||
with: | ||
path: ./results | ||
- name: Aggregate Test Results | ||
run: | | ||
# 初始化结果文件 | ||
> x86_64_fixed_images.txt | ||
> arm64_fixed_images.txt | ||
echo "聚合各分支测试结果..." | ||
for result_file in $(find ./results -type f -name "result.txt"); do | ||
echo "处理文件: $result_file" | ||
# 读取文件内容,得到 success、image、arch 变量 | ||
source "$result_file" | ||
echo "success=$success, image=$image, arch=$arch" | ||
if [ "$success" = "true" ]; then | ||
if [ "$arch" = "amd64" ]; then | ||
echo "$image" >> x86_64_fixed_images.txt | ||
elif [ "$arch" = "arm64" ]; then | ||
echo "$image" >> arm64_fixed_images.txt | ||
fi | ||
fi | ||
done | ||
echo "排序去重..." | ||
sort -u x86_64_fixed_images.txt -o x86_64_fixed_images.txt | ||
sort -u arm64_fixed_images.txt -o arm64_fixed_images.txt | ||
echo "最终结果:" | ||
echo "成功的 x86_64 镜像:" | ||
cat x86_64_fixed_images.txt | ||
echo "成功的 arm64 镜像:" | ||
cat arm64_fixed_images.txt | ||
cleanup: | ||
needs: results-updater | ||
if: always() | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Cleanup | ||
run: | | ||
echo "所有测试完成。请查看 Actions 页面获取详细测试结果。" |