-
Notifications
You must be signed in to change notification settings - Fork 2
162 lines (151 loc) · 5.88 KB
/
test.yml
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
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
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: ${{ matrix.image }}
arch: ${{ matrix.arch }}
steps:
- uses: actions/checkout@v4
- name: Setup Fresh Environment
run: |
echo "设置新环境..."
sudo apt-get update -y
sudo sh -c 'export noninteractive=true && 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: Install Missing Packages
run: |
sudo apt-get update -y
sudo apt-get install -y network-manager ifupdown isc-dhcp-client
- name: Configure Git
run: |
git config --global user.name "daily-test"
git config --global user.email "test@spiritlhl.top"
- name: Test Image
id: test
run: |
echo "测试镜像: ${{ matrix.image }}"
if sudo bash test.sh "${{ matrix.image }}"; then
echo "测试通过: ${{ matrix.image }}"
echo "success=true" | tee -a "$GITHUB_OUTPUT"
else
echo "测试失败: ${{ matrix.image }}"
echo "success=false" | tee -a "$GITHUB_OUTPUT"
fi
echo "image=${{ matrix.image }}" | tee -a "$GITHUB_OUTPUT"
echo "arch=${{ matrix.arch }}" | tee -a "$GITHUB_OUTPUT"
- name: Reset Network Configuration
run: |
sudo systemctl restart network-manager || sudo ifdown eth0 && sudo ifup eth0 || sudo dhclient -r && sudo dhclient
curl ip.sb
- name: Collect Test Result
if: ${{ steps.test.outputs.success && steps.test.outputs.success == 'true' }}
run: |
echo "收集测试结果..."
echo "success=${{ steps.test.outputs.success }}" > result.txt
echo "image=${{ matrix.image }}" >> result.txt
echo "arch=${{ matrix.arch }}" >> result.txt
cat result.txt
- name: Upload Result Artifact
if: ${{ steps.test.outputs.success == 'true' }}
uses: actions/upload-artifact@v4
with:
name: result-${{ matrix.image }}
path: result.txt
results-updater:
needs: test-single-image
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download All Results
uses: actions/download-artifact@v4
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
- name: Commit and Push Updated Results
run: |
# 配置 Git 用户信息
git config --global user.name "your-bot-name"
git config --global user.email "your-bot-email@example.com"
# 确保处于 main 分支
git checkout main
# 添加文件
git add x86_64_fixed_images.txt arm64_fixed_images.txt
# 提交更改(如果有更改才会提交)
git commit -m "Update fixed images list"
# 推送到仓库
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
cleanup:
needs: results-updater
if: always()
runs-on: ubuntu-latest
steps:
- name: Cleanup
run: |
echo "所有测试完成。请查看 Actions 页面获取详细测试结果。"