Skip to content

Commit 16829e9

Browse files
committed
ci: optimize code
Signed-off-by: David Mandy <smallprogramzhusir@gmail.com>
1 parent 2b82501 commit 16829e9

4 files changed

Lines changed: 62 additions & 43 deletions

File tree

.github/workflows/Build_Multi_Platform(V6).yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,6 @@ jobs:
430430
[ -e ${{ matrix.value.CONFIGS }}/${{ matrix.platform }}.config ] && cp -r ${{ matrix.value.CONFIGS }}/${{ matrix.platform }}.config openwrt/.config
431431
cd openwrt
432432
make defconfig
433-
if [[ "${{ matrix.source_code_platform }}" == "openwrt" ]]; then
434-
chmod +x $GITHUB_WORKSPACE/diy_script/openwrt_diy/diy-part4.sh
435-
source $GITHUB_WORKSPACE/diy_script/openwrt_diy/diy-part4.sh
436-
install_rustdesk_server
437-
fi
438433
439434
440435
- name: Git Restore Mtime (True SSoT) And DL Restore Time
@@ -661,6 +656,12 @@ jobs:
661656
run: |
662657
cd openwrt
663658
df -h
659+
660+
if [[ "${{ matrix.source_code_platform }}" == "openwrt" ]]; then
661+
chmod +x $GITHUB_WORKSPACE/${{ matrix.value.DIY_P4_SH }} || true
662+
source $GITHUB_WORKSPACE/${{ matrix.value.DIY_P4_SH }}
663+
install_rustdesk_server
664+
fi
664665
665666
666667
if [[ ${{ fromJSON(github.run_attempt) }} == 3 ]]; then

.github/workflows/Cache_Multi_Platform(V6).yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,6 @@ jobs:
245245
[ -e ${{ matrix.value.CONFIGS }}/${{ matrix.platform }}.config ] && cp -r ${{ matrix.value.CONFIGS }}/${{ matrix.platform }}.config openwrt/.config
246246
cd openwrt
247247
make defconfig
248-
if [[ "${{ matrix.source_code_platform }}" == "openwrt" ]]; then
249-
chmod +x $GITHUB_WORKSPACE/diy_script/openwrt_diy/diy-part4.sh
250-
source $GITHUB_WORKSPACE/diy_script/openwrt_diy/diy-part4.sh
251-
install_rustdesk_server
252-
fi
253248
254249
- name: Git Restore Mtime (True SSoT) And DL Restore Time
255250
if: steps.matrix_status.outputs.status != 'success'

compile_script/platforms.sh

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,45 @@
22

33
source_code_platforms=(openwrt immortalwrt lede)
44

5-
6-
7-
openwrt_value='{"REPO_URL": "https://github.com/openwrt/openwrt.git","REPO_BRANCH": "openwrt-25.12","CONFIGS": "config/openwrt_config","DIY_P1_SH": "diy_script/openwrt_diy/diy-part1.sh","DIY_P2_SH": "diy_script/openwrt_diy/diy-part2.sh","DIY_P3_SH": "diy_script/openwrt_diy/diy-part3.sh","OS": "ubuntu-latest"}'
8-
9-
immortalwrt_value='{"REPO_URL": "https://github.com/immortalwrt/immortalwrt.git","REPO_BRANCH": "openwrt-25.12","CONFIGS": "config/immortalwrt_config","DIY_P1_SH": "diy_script/immortalwrt_diy/diy-part1.sh","DIY_P2_SH": "diy_script/immortalwrt_diy/diy-part2.sh","DIY_P3_SH": "diy_script/immortalwrt_diy/diy-part3.sh","OS": "ubuntu-latest"}'
10-
11-
lede_value='{"REPO_URL": "https://github.com/coolsnowwolf/lede","REPO_BRANCH": "master","CONFIGS": "config/leanlede_config","DIY_P1_SH": "diy_script/lean_diy/diy-part1.sh","DIY_P2_SH": "diy_script/lean_diy/diy-part2.sh","DIY_P3_SH": "diy_script/lean_diy/diy-part3.sh","OS": "ubuntu-latest"}'
12-
5+
openwrt_value='{
6+
"REPO_URL": "https://github.com/openwrt/openwrt.git",
7+
"REPO_BRANCH": "openwrt-25.12",
8+
"CONFIGS": "config/openwrt_config",
9+
"DIY_P1_SH": "diy_script/openwrt_diy/diy-part1.sh",
10+
"DIY_P2_SH": "diy_script/openwrt_diy/diy-part2.sh",
11+
"DIY_P3_SH": "diy_script/openwrt_diy/diy-part3.sh",
12+
"DIY_P4_SH": "diy_script/openwrt_diy/diy-part4.sh",
13+
"OS": "ubuntu-latest"
14+
}'
15+
16+
immortalwrt_value='{
17+
"REPO_URL": "https://github.com/immortalwrt/immortalwrt.git",
18+
"REPO_BRANCH": "openwrt-25.12",
19+
"CONFIGS": "config/immortalwrt_config",
20+
"DIY_P1_SH": "diy_script/immortalwrt_diy/diy-part1.sh",
21+
"DIY_P2_SH": "diy_script/immortalwrt_diy/diy-part2.sh",
22+
"DIY_P3_SH": "diy_script/immortalwrt_diy/diy-part3.sh",
23+
"OS": "ubuntu-latest"
24+
}'
25+
26+
lede_value='{
27+
"REPO_URL": "https://github.com/coolsnowwolf/lede",
28+
"REPO_BRANCH": "master",
29+
"CONFIGS": "config/leanlede_config",
30+
"DIY_P1_SH": "diy_script/lean_diy/diy-part1.sh",
31+
"DIY_P2_SH": "diy_script/lean_diy/diy-part2.sh",
32+
"DIY_P3_SH": "diy_script/lean_diy/diy-part3.sh",
33+
"OS": "ubuntu-latest"
34+
}'
1335

1436
openwrt_platforms=(X86 R2S R3S R4S R4SE R5C R5S R6C R6S)
15-
1637
immortalwrt_platforms=(X86 R2S R3S R4S R4SE R5C R5S R6C R6S R66S R68S)
17-
1838
lede_platforms=(X86 R2S R3S R4S R4SE R5C R5S R6C R6S H28K H29K H66K H68K H69K R66S R68S)
1939

20-
21-
copy_backgroundfiles_platforms=(X86 R5S R5C R4S R4SE R2S R2C H66K H68K H69K R66S R68S R_PI_3b R_PI_4b)
22-
2340
matrix_json="["
2441
source_matrix_json="["
2542

2643
for source_platform in "${source_code_platforms[@]}"; do
27-
28-
2944
platforms_var="${source_platform}_platforms[@]"
3045
platforms=("${!platforms_var}")
3146
value_var="${source_platform}_value"
@@ -38,11 +53,20 @@ for source_platform in "${source_code_platforms[@]}"; do
3853
done
3954
done
4055

56+
# 去除末尾的逗号并闭合数组
4157
matrix_json="${matrix_json%,}]"
4258
source_matrix_json="${source_matrix_json%,}]"
4359

60+
# 【关键修复】使用 jq -c 将多行 JSON 压缩为紧凑的单行,确保能安全写入 GITHUB_OUTPUT
61+
COMPRESSED_MATRIX=$(echo "$matrix_json" | jq -c .)
62+
COMPRESSED_SOURCE=$(echo "$source_matrix_json" | jq -c .)
63+
64+
# 打印到控制台方便日志排错 (用 jq 格式化输出)
65+
echo "=== Matrix JSON ==="
66+
echo "$COMPRESSED_MATRIX" | jq .
67+
echo "=== Source Matrix JSON ==="
68+
echo "$COMPRESSED_SOURCE" | jq .
4469

45-
echo $matrix_json
46-
echo $source_matrix_json
47-
echo "matrix=$matrix_json" >> $GITHUB_OUTPUT
48-
echo "source_matrix_json=$source_matrix_json" >> $GITHUB_OUTPUT
70+
# 安全写入到 GITHUB_OUTPUT
71+
echo "matrix=$COMPRESSED_MATRIX" >> $GITHUB_OUTPUT
72+
echo "source_matrix_json=$COMPRESSED_SOURCE" >> $GITHUB_OUTPUT

diy_script/openwrt_diy/diy-part4.sh

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# 该脚本会在make defconfig之后执行
2+
# 该脚本会在make编译之前执行
33

44
# =================================================================
55
# 函数: install_rustdesk_server
@@ -12,7 +12,7 @@ install_rustdesk_server() {
1212
# 1. 检查是否存在 .config 文件
1313
if [ ! -f "./.config" ]; then
1414
echo "错误:未找到 .config 文件,请确保在 OpenWrt 源码根目录且已执行 make defconfig!"
15-
return 1
15+
exit 1
1616
fi
1717

1818
# 2. 设置临时目录与目标目录
@@ -24,13 +24,12 @@ install_rustdesk_server() {
2424
mkdir -p "${TMP_DIR}"
2525

2626
# 3. 核心精髓:直接从 .config 提取最底层的架构名称
27-
# 结果会是 x86_64, aarch64, arm, i386, mips 等
2827
local OPENWRT_ARCH
2928
OPENWRT_ARCH=$(grep "^CONFIG_ARCH=" ./.config | cut -d '"' -f 2)
3029

3130
if [ -z "$OPENWRT_ARCH" ]; then
3231
echo "错误:无法从 .config 中读取 CONFIG_ARCH 变量!"
33-
return 1
32+
exit 1
3433
fi
3534
echo "检测到当前 OpenWrt 核心架构为: $OPENWRT_ARCH"
3635

@@ -50,7 +49,7 @@ install_rustdesk_server() {
5049
ARCH_KEYWORD="linux-i386.zip"
5150
;;
5251
*)
53-
# 如果你编译了 MT7621 (mipsel) 或 AR9331 (mips),RustDesk 是没包的
52+
# 架构不支持时,安全跳过,不中断编译,使用 return 0
5453
echo "警告:RustDesk Server 官方暂不支持该架构 ($OPENWRT_ARCH)!"
5554
echo "跳过 RustDesk Server 的集成,不中断编译流程。"
5655
return 0
@@ -69,15 +68,15 @@ install_rustdesk_server() {
6968

7069
if [ -z "$TARGET_URL" ]; then
7170
echo "错误:未找到架构 [$ARCH_KEYWORD] 的下载链接,请检查网络或 GitHub API 限制!"
72-
return 1
71+
exit 1
7372
fi
7473
echo "匹配到下载链接: $TARGET_URL"
7574

76-
# 7. 下载并解压到临时目录
77-
wget -qO "${TMP_DIR}/rustdesk-server.zip" "$TARGET_URL"
78-
unzip -q "${TMP_DIR}/rustdesk-server.zip" -d "${TMP_DIR}"
75+
# 7. 下载并解压到临时目录 (加入容错,防止静默崩溃)
76+
wget -qO "${TMP_DIR}/rustdesk-server.zip" "$TARGET_URL" || { echo "错误:下载 RustDesk 失败!"; exit 1; }
77+
unzip -q "${TMP_DIR}/rustdesk-server.zip" -d "${TMP_DIR}" || { echo "错误:解压 RustDesk 失败!"; exit 1; }
7978

80-
# 8. 彻底动态化:使用 find 查找文件,官方怎么乱给内部文件夹起名都不会报错
79+
# 8. 彻底动态化:使用 find 查找文件
8180
local HBBS_PATH
8281
local HBBR_PATH
8382
HBBS_PATH=$(find "${TMP_DIR}" -type f -name "hbbs" | head -n 1)
@@ -86,16 +85,16 @@ install_rustdesk_server() {
8685
if [ -z "$HBBS_PATH" ] || [ -z "$HBBR_PATH" ]; then
8786
echo "错误:在解压目录中未能找到 hbbs 或 hbbr 文件!"
8887
ls -laR "${TMP_DIR}" # 打印目录结构方便排错
89-
return 1
88+
exit 1
9089
fi
9190

9291
echo "成功提取文件:"
9392
echo " -> $HBBS_PATH"
9493
echo " -> $HBBR_PATH"
9594

96-
# 9. 拷贝并赋权
97-
cp -f "$HBBS_PATH" "${FILES_DIR}/usr/bin/"
98-
cp -f "$HBBR_PATH" "${FILES_DIR}/usr/bin/"
95+
# 9. 拷贝并赋权 (加入容错)
96+
cp -f "$HBBS_PATH" "${FILES_DIR}/usr/bin/" || { echo "错误:拷贝 hbbs 失败!"; exit 1; }
97+
cp -f "$HBBR_PATH" "${FILES_DIR}/usr/bin/" || { echo "错误:拷贝 hbbr 失败!"; exit 1; }
9998

10099
chmod +x "${FILES_DIR}/usr/bin/hbbs"
101100
chmod +x "${FILES_DIR}/usr/bin/hbbr"

0 commit comments

Comments
 (0)