-
Notifications
You must be signed in to change notification settings - Fork 2
139 lines (114 loc) · 4.57 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
name: Test Incus Images
on:
schedule:
- cron: '0 4 2-30/2 * *'
workflow_dispatch:
jobs:
prepare-matrix:
runs-on: ubuntu-latest
outputs:
test-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: 4
matrix: ${{fromJson(needs.prepare-matrix.outputs.test-matrix)}}
runs-on: ${{ matrix.runner }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Setup Fresh Environment
run: |
echo "设置新环境..."
sudo apt 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: 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
if sudo bash test.sh "${{ matrix.image }}"; then
echo "success=true" >> $GITHUB_OUTPUT
echo "测试通过: ${{ matrix.image }}"
else
echo "success=false" >> $GITHUB_OUTPUT
echo "测试失败: ${{ matrix.image }}"
fi
# 还原 DNS 配置
sudo mv /etc/resolv.conf.backup /etc/resolv.conf || true
results-updater:
needs: test-single-image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update Results Based on Test Status
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
# 清空或创建固定镜像列表
> x86_64_fixed_images.txt
> arm64_fixed_images.txt
# 检查每个测试任务的状态
images=$(echo '${{ toJSON(needs.test-single-image.result) }}' | jq -r 'to_entries[] | select(.value=="success") | .key')
for i in $images; do
image=$(echo '${{ toJSON(needs.prepare-matrix.outputs.test-matrix) }}' | jq -r ".include[$i].image")
arch=$(echo '${{ toJSON(needs.prepare-matrix.outputs.test-matrix) }}' | jq -r ".include[$i].arch")
if [ "$arch" = "amd64" ]; then
echo "$image" >> x86_64_fixed_images.txt
else
echo "$image" >> arm64_fixed_images.txt
fi
done
# 去重并排序
sort -u x86_64_fixed_images.txt -o x86_64_fixed_images.txt
sort -u arm64_fixed_images.txt -o arm64_fixed_images.txt
- name: Push Results
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ -f x86_64_fixed_images.txt && -f arm64_fixed_images.txt ]]; then
echo "推送测试结果..."
git pull origin main
git add x86_64_fixed_images.txt arm64_fixed_images.txt
git commit -m "更新镜像测试结果"
git push
fi
continue-on-error: true
cleanup:
needs: results-updater
if: always()
runs-on: ubuntu-latest
steps:
- name: Check Test Results
run: |
echo "所有测试完成"
echo "查看 Actions 页面获取详细测试结果"