forked from db-one/OpenWrt-AutoBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
414 lines (342 loc) · 15.8 KB
/
OpenWrt-Actions.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#
#
# 感谢p3terx大神的一键编译脚本
#
# Copyright (C) 2019 P3TERX <https://p3terx.com>
# <https://github.com/P3TERX/Actions-OpenWrt.git>
#
name: 编译OpenWrt固件
on:
workflow_dispatch:
inputs:
CACHE_BUILD:
description: '缓存加速'
required: false
default: 'true'
type: boolean
SSH_ACTION:
description: 'SSH远程配置固件'
required: false
default: 'false'
type: boolean
# 定时触发编译(1,2,5,6,8,10,12,15,16,18,20,22,25,26,28,30早3点)
schedule:
- cron: 0 17 1,4,5,7,9,11,14,15,17,19,21,24,25,27,29,31 * *
# 点赞☆Star触发编译
# watch:
# types: [started]
env:
TZ: Asia/Shanghai
GIT_USER_TOKEN: ${{ secrets.GIT_USER_TOKEN }}
WECHAT_WORK_URL: ${{ secrets.WECHAT_WORK_URL }}
WECHAT_WORK_TOKEN: ${{ secrets.WECHAT_WORK_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
GITHUB_RELEASE: https://github.com/wangweitung/OpenWrt-AutoBuild-db-one/releases
jobs:
build:
runs-on: ubuntu-latest
if: github.event.repository.owner.id == github.event.sender.id || ! github.event.sender.id
name: 编译 ${{matrix.target}}
strategy:
fail-fast: false
matrix:
target: [Lean_x86_64,Lean_x86_64_Long] #[Lean_x86_64,Lean_x86_64_Long]
steps:
- name: 检查文件
uses: actions/checkout@v4
- name: 检测脚本设置
run: |
source "${GITHUB_WORKSPACE}/build/${{matrix.target}}/settings.ini"
echo "REPO_URL=${REPO_URL}" >> $GITHUB_ENV
echo "REPO_BRANCH=${REPO_BRANCH}" >> $GITHUB_ENV
echo "CONFIG_FILE=${CONFIG_FILE}" >> $GITHUB_ENV
echo "FIRMWARE_MESSAGE=${FIRMWARE_MESSAGE}" >> $GITHUB_ENV
echo "CUSTOM_SH=${CUSTOM_SH}" >> $GITHUB_ENV
echo "CACHE_BUILD=${CACHE_BUILD}" >> $GITHUB_ENV
echo "SSH_ACTIONS=${SSH_ACTIONS}" >> $GITHUB_ENV
echo "UPLOAD_FIRMWARE=${UPLOAD_FIRMWARE}" >> $GITHUB_ENV
echo "UPLOAD_QCOW2=${UPLOAD_QCOW2}" >> $GITHUB_ENV
echo "UPLOAD_VHDX=${UPLOAD_VHDX}" >> $GITHUB_ENV
echo "UPLOAD_VMDK=${UPLOAD_VMDK}" >> $GITHUB_ENV
echo "UPLOAD_IPK=${UPLOAD_IPK}" >> $GITHUB_ENV
echo "UPLOAD_CONFIG=${UPLOAD_CONFIG}" >> $GITHUB_ENV
echo "UPLOAD_RELEASE=${UPLOAD_RELEASE}" >> $GITHUB_ENV
echo "WECHAT_WORK_PUSH=${WECHAT_WORK_PUSH}" >> $GITHUB_ENV
echo "TELEGRAM_BOT=${TELEGRAM_BOT}" >> $GITHUB_ENV
#添加变量
echo "HOME=${GITHUB_WORKSPACE}/openwrt" >> $GITHUB_ENV
echo "WORKPATH=${GITHUB_WORKSPACE}/openwrt/build/${{matrix.target}}" >> $GITHUB_ENV
- name: 初始化系统环境
env:
DEBIAN_FRONTEND: noninteractive
run: |
docker rmi `docker images -q`
sudo -E rm -rf /usr/share/dotnet /etc/mysql /etc/php /etc/apt/sources.list.d /usr/local/lib/android
sudo -E apt-mark hold grub-efi-amd64-signed
sudo -E apt update
sudo -E apt -y purge azure-cli* docker* ghc* zulu* llvm* firefox google* dotnet* powershell* openjdk* mysql* php* mongodb* dotnet* snap*
sudo -E apt -y full-upgrade
sudo -E apt -y install ack antlr3 aria2 asciidoc autoconf automake autopoint binutils bison build-essential bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libreadline-dev libssl-dev libtool lrzsz mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python3 python3-pip libpython3-dev qemu-utils rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
sudo -E systemctl daemon-reload
sudo -E apt -y autoremove --purge
sudo -E apt clean
- name: 编译前准备
run: |
sudo -E apt-get -y install xsltproc zip grep python3-pip python3-ply libc6-dev libncurses5 libtinfo-dev libtinfo5 ncurses-doc python2.7 git-core wget curl rsync
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
sudo timedatectl set-timezone "$TZ"
echo
echo " 系统空间 类型 总数 已用 可用 使用率"
df -hT $PWD
- name: 释放Ubuntu磁盘空间
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: true
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true
- name: 下载${{matrix.target}}源码
working-directory: /workdir
run: |
df -hT $PWD
git clone -b $REPO_BRANCH --single-branch $REPO_URL openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
- name: 缓存加速
uses: stupidloud/cachewrtbuild@main
if: env.CACHE_BUILD == 'true' || (github.event.inputs.CACHE_BUILD == 'true')
with:
ccache: 'true'
prefix: ${{ github.workspace }}/openwrt
- name: 更新时区、编译时间
id: date
run: |
sudo timedatectl set-timezone "$TZ"
echo "FILE_TIME=$(date +"%m-%d %H.%M")" >> $GITHUB_ENV
echo "FILE_TIME1=$(date "+%Y年%m月%d日-%H点%M分")" >> $GITHUB_ENV
echo "FILE_TIME2=$(date "+%Y%m%d-%H%M")" >> $GITHUB_ENV
echo "编译开始时间..."
START_TIME=`date +'%Y-%m-%d %H:%M:%S'`
echo "START_SECONDS=$(date --date="$START_TIME" +%s)" >> $GITHUB_ENV
- name: 加载源,定制文件并生成自定义配置
run: |
# 复制配置文件到源码目录
cp -Rf `find ./ -maxdepth 1 -type d ! -path './openwrt' ! -path './'` openwrt
cd openwrt
echo "执行脚本"
if [ -f "${WORKPATH}/$CUSTOM_SH" ]; then
(
chmod +x ${WORKPATH}/$CUSTOM_SH
/bin/bash "${WORKPATH}/$CUSTOM_SH"
)
fi
echo "复制脚本文件..."
if [ -n "$(ls -A "${GITHUB_WORKSPACE}/openwrt/build/scripts/files" 2>/dev/null)" ]; then
if [ -d "files" ];then
cp -rf ${GITHUB_WORKSPACE}/openwrt/build/scripts/files/* files
chmod -R 755 ${HOME}/files
else
cp -rf ${GITHUB_WORKSPACE}/openwrt/build/scripts/files/ files
chmod -R 755 ${HOME}/files
fi
fi
echo "复制配置文件..."
if [ -n "$(ls -A "${WORKPATH}/files" 2>/dev/null)" ]; then
if [ -d "files" ];then
cp -rf ${WORKPATH}/files/* files
chmod -R 755 ${WORKPATH}/files
else
cp -rf ${WORKPATH}/files/ files
chmod -R 755 ${WORKPATH}/files
fi
fi
echo "复制源码文件..."
if [ -n "$(ls -A "${WORKPATH}/sources" 2>/dev/null)" ]; then
cp -Rf ${WORKPATH}/sources/* ./
fi
echo "写入配置文件..."
mv ${WORKPATH}/$CONFIG_FILE .config
make defconfig
- name: SSH远程连接服务器
uses: db-one/debugger-action@main
if: env.SSH_ACTIONS == 'true' || (github.event.inputs.SSH_ACTION == 'true')
env:
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
- name: 输出编译信息
run: |
cd openwrt
echo
echo " 系统空间 类型 总数 已用 可用 使用率"
df -hT $PWD
echo
echo "=========================================="
echo
echo " CPU物理数量:$(cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l)"
echo " CPU核心及版本信息:$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \n"
echo
echo "=========================================="
echo
ZZZ="package/lean/default-settings/files/zzz-default-settings"
echo "DISTRIB_REVISION=$(cat $ZZZ|grep DISTRIB_REVISION= | sed 's/^.\{24\}//g' | sed 's/.\{26\}$//')" >> $GITHUB_ENV
echo "KERNEL_PATCHVER=$(cat target/linux/x86/Makefile|grep KERNEL_PATCHVER | sed 's/^.\{17\}//g')" >> $GITHUB_ENV
echo " 当前编译版本:$(cat $ZZZ|grep DISTRIB_REVISION= | sed 's/^.\{24\}//g' | sed 's/.\{26\}$//')"
echo " 内核版本:$(cat target/linux/x86/Makefile|grep KERNEL_PATCHVER | sed 's/^.\{17\}//g')"
echo " 编译时间:${{ env.FILE_TIME1 }}"
echo
echo "=========================================="
grep -i CONFIG_PACKAGE_luci-app .config | grep -v \# > Plug-in
grep -i CONFIG_PACKAGE_luci-theme .config | grep -v \# >> Plug-in
sed -i '/INCLUDE/d' Plug-in > /dev/null 2>&1
sed -i 's/CONFIG_PACKAGE_/、/g' Plug-in
sed -i '/Transparent_Proxy/d' Plug-in > /dev/null 2>&1 #排除 luci-app-passwall_Transparent_Proxy
sed -i '/qbittorrent-simple_dynamic/d' Plug-in > /dev/null 2>&1 #排除 luci-app-qbittorrent-simple_dynamic
sed -i 's/=y/\ /g' Plug-in
awk '$0=NR$0' Plug-in > Plug-2
awk '{print " " $0}' Plug-2 > Plug-in
echo
echo
echo " 已选插件列表"
cat Plug-in
rm -rf {Plug-in,Plug-2}
echo
echo "=========================================="
echo
echo
echo "输出完整插件信息..."
echo
echo
cat .config
- name: 下载编译所需文件
run: |
cd openwrt && make download -j16
- name: 开始编译固件
id: compile
run: |
cd openwrt
make -j$(nproc) || make -j1 V=s
- name: 检查空间使用情况
run: |
echo "======================="
echo "Space usage:"
echo "======================="
df -hT
echo "======================="
du -h --max-depth=1 openwrt/ --exclude=build_dir --exclude=bin
du -h --max-depth=1 openwrt/build_dir
du -h --max-depth=1 openwrt/bin
- name: 整理固件文件
id: organizer
run: |
mkdir -p ./artifact/firmware
mkdir -p ./artifact/pvekvm
mkdir -p ./artifact/hyperv
mkdir -p ./artifact/vmware
mkdir -p ./artifact/package
mkdir -p ./artifact/buildinfo
cp -rf openwrt/.config ./artifact/buildinfo/${{matrix.target}}.config
rm -rf $(find openwrt/bin/targets/ -type d -name "packages")
cp -rf $(find openwrt/bin/packages/ -type f -name "*.ipk") ./artifact/package/
cp -rf $(find openwrt/bin/targets/ -type f -name "*.buildinfo" -o -name "*.manifest") ./artifact/buildinfo/
cp -rf $(find openwrt/bin/targets/ -type f -name "*combined*img*") ./artifact/firmware/
cp -rf $(find openwrt/bin/targets/ -type f -name "*combined*qcow2*") ./artifact/pvekvm/ || true
cp -rf $(find openwrt/bin/targets/ -type f -name "*combined*vhdx*") ./artifact/hyperv/ || true
cp -rf $(find openwrt/bin/targets/ -type f -name "*combined*vmdk*") ./artifact/vmware/ || true
echo "编译完成时间..."
START_SECONDS=${{ env.START_SECONDS }}
END_TIME=`date +'%Y-%m-%d %H:%M:%S'`
END_SECONDS=$(date --date="$END_TIME" +%s)
SECONDS=$((END_SECONDS-START_SECONDS))
HOUR=$(( $SECONDS/3600 )) && MIN=$(( ($SECONDS-${HOUR}*3600)/60 )) && SEC=$(( $SECONDS-${HOUR}*3600-${MIN}*60 ))
echo "BUILD_TIME=${HOUR}时${MIN}分${SEC}秒" >> $GITHUB_ENV
- name: 上传固件文件
if: steps.compile.outcome == 'success' && env.UPLOAD_FIRMWARE == 'true'
uses: actions/upload-artifact@main
with:
name: OpenWrt_firmware_${{matrix.target}}_${{ env.FILE_TIME }}
path: ./artifact/firmware/
- name: 上传PVE/KVM镜像文件
if: steps.compile.outcome == 'success' && env.UPLOAD_QCOW2 == 'true'
uses: actions/upload-artifact@main
with:
name: OpenWrt_pvekvm_${{matrix.target}}_${{ env.FILE_TIME }}
path: ./artifact/pvekvm/
- name: 上传Hyper-V镜像文件
if: steps.compile.outcome == 'success' && env.UPLOAD_VHDX == 'true'
uses: actions/upload-artifact@main
with:
name: OpenWrt_hyperv_${{matrix.target}}_${{ env.FILE_TIME }}
path: ./artifact/hyperv/
- name: 上传VMware镜像文件
if: steps.compile.outcome == 'success' && env.UPLOAD_VMDK == 'true'
uses: actions/upload-artifact@main
with:
name: OpenWrt_vmware_${{matrix.target}}_${{ env.FILE_TIME }}
path: ./artifact/vmware/
- name: 上传插件包文件
if: steps.compile.outcome == 'success' && env.UPLOAD_IPK == 'true'
uses: actions/upload-artifact@main
with:
name: OpenWrt_package_${{matrix.target}}_${{ env.FILE_TIME }}
path: ./artifact/package/
- name: 上传固件信息
if: steps.compile.outcome == 'success' && env.UPLOAD_CONFIG == 'true'
uses: actions/upload-artifact@main
with:
name: OpenWrt_buildinfo_${{matrix.target}}_${{ env.FILE_TIME }}
path: ./artifact/buildinfo/
- name: 自动发布固件到 Releases
uses: ncipollo/release-action@main
if: steps.compile.outcome == 'success' && env.UPLOAD_RELEASE == 'true'
with:
name: ${{ env.FILE_TIME1 }} 「 ${{ env.FIRMWARE_MESSAGE }} 」
tag: ${{ env.FILE_TIME2 }}-${{matrix.target}}-${{ env.DISTRIB_REVISION }}
token: ${{ secrets.GIT_USER_TOKEN }}
body: |
★ 源码 : ${{ env.REPO_URL }}
★ 分支 : ${{ env.REPO_BRANCH }}
★ 感谢源码作者无私分享!
🛠 编译版本:${{ env.DISTRIB_REVISION }}
🖥 内核版本:${{ env.KERNEL_PATCHVER }}
🎈 编译时间:${{ env.FILE_TIME1 }}
⏰ 编译用时:${{ env.BUILD_TIME }}
🎉 [ ${{ env.FIRMWARE_MESSAGE }} ]固件下载
━━━━━━━━━━━━━━━━━━━━
=========================================
artifacts: ./artifact/firmware/*
- name: 删除运行记录
uses: Mattraks/delete-workflow-runs@v2
with:
retain_days: 30 #保留最后多少记录不删除
keep_minimum_runs: 0
- name: 删除自动发布的旧固件
uses: shidahuilang/delete-older-releases@main
if: steps.compile.outcome == 'success' && env.UPLOAD_RELEASE == 'true'
with:
keep_latest: 20 #保留多少个releases不删除
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GIT_USER_TOKEN }}
- name: 编译成功信息通知-企业微信
if: steps.compile.outcome == 'success' && env.WECHAT_WORK_PUSH == 'true'
run: |
curl "http://${{ secrets.WECHAT_WORK_URL }}/push?token=${{ secrets.WECHAT_WORK_TOKEN }}&message=您的${{ env.FIRMWARE_MESSAGE }}固件成功编译完成了!%0a%0a🎈编译时间:${{ env.FILE_TIME1 }}%0a%0a🛠编译版本:${{ env.DISTRIB_REVISION }}%0a%0a🖥内核版本:${{ env.KERNEL_PATCHVER }}%0a%0a⏰编译用时:${{ env.BUILD_TIME }}%0a%0a🎉发布地址:${{ env.GITHUB_RELEASE }}%0a%0a🌴固件已经编译完成🎈!!!" || true
- name: 编译成功信息通知-Telegram
if: steps.compile.outcome == 'success' && env.TELEGRAM_BOT == 'true'
run: |
curl "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" -d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}&text=
您的${{ env.FIRMWARE_MESSAGE }}固件成功编译完成了!
🛠 编译版本:${{ env.DISTRIB_REVISION }}
🖥 内核版本:${{ env.KERNEL_PATCHVER }}
🎈 编译时间:${{ env.FILE_TIME1 }}
⏰ 编译用时:${{ env.BUILD_TIME }}
🎉 发布地址:${{ env.GITHUB_RELEASE }}
🌴 固件已经编译完成 🎈!!!
" >/dev/null 2>&1 && echo "ok..."