generated from P3TERX/Actions-OpenWrt
-
Notifications
You must be signed in to change notification settings - Fork 25
362 lines (325 loc) · 13.7 KB
/
[AIO]Build.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
#
# Copyright (c) 2019-2020 P3TERX <https://p3terx.com>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
# https://github.com/P3TERX/Actions-OpenWrt
# Description: Build OpenWrt using GitHub Actions
#
name: Build Image
run-name: Build Image [${{ inputs.config_tag }}, No.${{ inputs.device_choice }}, @${{ inputs.commit_sha }}]
on:
repository_dispatch:
workflow_dispatch:
inputs:
device_choice:
description: '选择型号(device-env.sh中的编号)'
required: false
default: 5
type: number
config_tag:
type: choice
required: true
description: '选择配置版本'
default: 'func'
options:
- clean
- basic
- func
- test
commit_sha:
description: '使用指定的commit(可选)'
required: false
default: 'latest'
use_cache:
description: '尝试使用缓存的tool和toolchain'
required: false
default: true
type: boolean
ssh:
description: '编译前进行SSH调试'
required: false
default: false
type: boolean
env:
# REPO_URL: https://github.com/openwrt/openwrt
# REPO_BRANCH: master
FEEDS_CONF: feeds.conf.default
CONFIG_FILE: .config
COMMIT_SHA: ${{ inputs.commit_sha }}
DIY_P1_SH: diy-part1.sh
# DIY_P2_SH: diy-part2/[OpenWrt]RE-SP-01B-part2.sh
UPLOAD_BIN_DIR: true
UPLOAD_FIRMWARE: true
UPLOAD_TRANSFER: false
UPLOAD_RELEASE: false
TZ: Asia/Shanghai
jobs:
init:
runs-on: ubuntu-22.04
outputs:
DEVICE_TAG: ${{steps.job_tag.outputs.DEVICE_TAG}}
steps:
- uses: actions/checkout@main
- name: Load environment variable
run: |
chmod +x $GITHUB_WORKSPACE/device-env.sh
$GITHUB_WORKSPACE/device-env.sh ${{ inputs.device_choice }}
- id: job_tag
run: |
# notifications
# echo "::set-output name=DEVICE_TAG::${DEVICE_TAG}"
echo "DEVICE_TAG=${DEVICE_TAG}" >> $GITHUB_OUTPUT
echo "::notice title=Task Summary::Compile using the ${{ inputs.config_tag }}.config of device No.${{ inputs.device_choice }}(${DEVICE_TAG})"
# 若指定了 commit 提个醒
if [ "$USE_COMMIT_SHA" == "latest" ]; then
LATEST_SHA=$(curl "https://api.github.com/repos/$REPO_USE/commits/$REPO_BRANCH" | grep sha | head -n1 | cut -d\" -f4)
echo "::notice title=Using commit::[latest] https://github.com/$REPO_USE/tree/$LATEST_SHA"
else
echo "::notice title=Using commit::[specific] https://github.com/$REPO_USE/tree/$USE_COMMIT_SHA"
fi
build:
runs-on: ubuntu-22.04
needs: init
name: ${{needs.init.outputs.DEVICE_TAG}}
steps:
- uses: actions/checkout@main
- name: Load Environment Variable
run: |
chmod +x $GITHUB_WORKSPACE/device-env.sh
$GITHUB_WORKSPACE/device-env.sh ${{ inputs.device_choice }}
- name: Initialize Environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
sudo -E apt-get -qq update
sudo -E apt-get -qq install $DEPENDS
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
# docker image prune -a -f
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
- name: Clone Source Code
working-directory: /workdir
run: |
df -hT | tee /workdir/df.before
git clone https://github.com/$REPO_USE -b $REPO_BRANCH openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
# 若指定了 commit
if [ "$USE_COMMIT_SHA" != "latest" ]; then
cd openwrt
git checkout "$USE_COMMIT_SHA"
cd ..
fi
- name: Cache
uses: klever1988/cachewrtbuild@main
if: ${{ inputs.use_cache }}
with:
ccache: 'false'
prefix: ${{ github.workspace }}/openwrt
- name: Load Custom Feeds
run: |
[ -e $FEEDS_CONF ] && mv $FEEDS_CONF openwrt/feeds.conf.default
chmod +x $DIY_P1_SH
cd openwrt
$GITHUB_WORKSPACE/$DIY_P1_SH
- name: Update Feeds
run: cd openwrt && ./scripts/feeds update -a
- name: Install Feeds
run: cd openwrt && ./scripts/feeds install -a
- name: Load Custom Configuration
run: |
[ -e files ] && echo '::notice title=Image Type:: 已启用files大法!' && mv -v files openwrt/files
[ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config
chmod +x "$DIY_P2_SH"
cd openwrt
# 使用脚本生成配置
"$GITHUB_WORKSPACE/$DIY_P2_SH" ${{ inputs.config_tag }}
echo ==============.config===============
[ -e .config ] && cat .config || (echo '.config NOT FOUND!' && exit 1)
echo ====================================
- name: Download Packages
id: download
run: |
cd openwrt
make defconfig
# 分析配置文件是否包含补丁
subset_check=$(comm -23 <(sed '/# -/d' .config.old | sort | uniq) <(sort .config | uniq) | tee .notfound)
if [[ -z $subset_check ]]; then
echo "自定义配置(${{ inputs.config_tag }})是 .conifg 的子集"
else
echo "自定义配置(${{ inputs.config_tag }})不是 .conifg 的子集!以下配置行未在 .config 中找到"
cat .notfound
echo "=====================EOF======================="
echo "::warning title=Config fault::Custom config is not a subset of .config, please check..."
fi
# 从DIY_P2_SH中截取型号信息
grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME
[ -s DEVICE_NAME ] && echo "::notice title=Target Name in .config:: $(cat DEVICE_NAME)" && echo "DEVICE_NAME=$(cat DEVICE_NAME)" >> $GITHUB_ENV
echo =============current .config DIFF default config=============
./scripts/diffconfig.sh
echo ===========================EoDIFF============================
# 下载包,如若出错生成警告
# 一轮八线程
make download -j8 | tee make_download.log
grep 'ERROR:' make_download.log | xargs -i echo "::warning:: [Download Trial 1]" {}
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
# 二轮单线程
grep 'ERROR:' -q -m1 make_download.log && make download -j1 V=s | tee make_download.log
grep 'ERROR:' make_download.log | xargs -i echo "::warning:: [Download Trial 2]" {}
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
- name: SSH Before Compile
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: false
if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh')
- name: Compile
id: compile
run: |
# 计时起点,启动打点计时器
start_time=$(date +%s)
( while true; do echo "...Timer.$[ $(date +%s)-${start_time} ]s" >&2 && sleep 20; done ) &
TIMER_PID=$!
# 启动编译任务
cd openwrt
echo -e "Initiate Compilation. Try $(($(nproc)+1)) thread first..."
make -j $(($(nproc)+1)) || make -j1 || make -j1 V=s.
echo "TimeStamp=$(date +"%Y%m%d-%H%M")" >> $GITHUB_ENV
# 复制配置文件到 bin/targets/[arch]/[subtarget]/ 目录,最终一并打包
SUBTARGET_FOLDER=$(realpath bin/targets/*/*)
cp -v .config ${SUBTARGET_FOLDER}/
# 计时终点,关闭打点计时器
kill -15 $TIMER_PID
end_time=$(date +%s)
cost_time=$[ ${end_time}-${start_time} ]
echo "==============================================="
echo -ne "Start Time:\t${start_time}\nEnd Time:\t${end_time}\nCost Time:\t${cost_time}\n" | tee ${SUBTARGET_FOLDER}/Timer.log
echo "==============================================="
- name: Check Space Usage
if: (!cancelled())
run: |
echo "=======================BEFORE========================"
cat /workdir/df.before
echo "========================AFTER========================"
df -hT
- name: Upload Bin Directory
uses: actions/upload-artifact@main
if: steps.compile.conclusion == 'success' && env.UPLOAD_BIN_DIR == 'true'
with:
name: OpenWrt_bin_${{ env.DEVICE_NAME }}_${{ env.TimeStamp }}
path: openwrt/bin
- name: Organize Files
id: organize
if: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
run: |
cd openwrt/bin/targets/*/*
rm -rf packages
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
- name: Upload Firmware Directory
uses: actions/upload-artifact@main
if: steps.organize.conclusion == 'success' && !cancelled()
with:
name: OpenWrt_firmware_${{ env.DEVICE_NAME }}_${{ env.TimeStamp }}
path: ${{ env.FIRMWARE }}
- name: Upload Using File-transfer
id: transfer
if: steps.organize.conclusion == 'success' && env.UPLOAD_TRANSFER == 'true' && !cancelled()
run: |
curl -fsSL git.io/file-transfer | sh
# 返回链接格式:【 Download Link: https://we.tl/t-fLXXXXXXzJ 】
touch release.txt
echo 'wetransfer(2GB)'
(
./transfer wet -s -p 4 --no-progress ${FIRMWARE} 2>&1 | tee transfer.wet.log
echo "::notice title=@wetransfer.com::$(cat transfer.wet.log | grep https)"
echo "🔗 [WeTransfer]($(cat transfer.wet.log | grep https | cut -f3 -d' '))" >> release.txt
)
echo 'Musetransfer(10GB)'
(
./transfer muse -s -p 4 --no-progress ${FIRMWARE} 2>&1 | tee transfer.muse.log
echo "::notice title=@musetransfer.com::$(cat transfer.muse.log | grep https)"
echo "🔗 [Musetransfer]($(cat transfer.muse.log | grep https | cut -f3 -d' '))" >> release.txt
)
echo 'GoFile(-)'
(
./transfer gof -s --no-progress ${FIRMWARE} 2>&1 | tee transfer.gof.log
echo "::notice title=@gofile.io::$(cat transfer.gof.log | grep https)"
echo "🔗 [GoFile]($(cat transfer.gof.log | grep https | cut -f3 -d' '))" >> release.txt
)
# echo 'DownloadGG(25GB, no single mode yet)'
# (
# ./transfer gg --no-progress ${FIRMWARE} 2>&1 | tee transfer.gg.log
# echo "::notice title=@download.gg::$(cat transfer.gg.log | grep https)"
# echo "🔗 [DownloadGG]($(cat transfer.gg.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'Wenshushu(2GB, meet captcha)'
# echo ref: https://github.com/Mikubill/transfer/issues/55
# (
# ./transfer wss -s -p 4 --no-progress ${FIRMWARE} 2>&1 | tee transfer.wss.log
# echo "::notice title=@wenshushu.cn::$(cat transfer.wss.log | grep https)"
# echo "🔗 [Wenshushu]($(cat transfer.wss.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'cowtransfer(need login)'
# (
# ./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE} 2>&1 | tee transfer.cow.log
# echo "::notice title=@cowtransfer.com::$(cat cowtransfer.log | grep https)"
# echo "🔗 [Cowtransfer]($(cat transfer.cow.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'LitterBox(1GB, no single mode)'
# (
# ./transfer lit --no-progress ${FIRMWARE} 2>&1 | tee transfer.lit.log
# echo "::notice title=@litterbox.catbox.moe::$(cat transfer.lit.log | grep https)"
# echo "🔗 [LitterBox]($(cat transfer.lit.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo '1Fichier(300GB, no single mode)'
# (
# ./transfer fic --no-progress ${FIRMWARE} 2>&1 | tee transfer.fic.log
# echo "::notice title=@1fichier.com::$(cat transfer.fic.log | grep https)"
# echo "🔗 [1Fichier]($(cat transfer.fic.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'Anonfile(10GB, no single mode)'
# (
# ./transfer anon --no-progress ${FIRMWARE} 2>&1 | tee transfer.anon.log
# echo "::notice title=@anonfile.com::$(cat transfer.anon.log | grep https)"
# echo "🔗 [Anonfile]($(cat transfer.anon.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'Transfer.sh(-, will be zip/tar)'
# (
# ./transfer trs -s --no-progress ${FIRMWARE} 2>&1 | tee transfer.trs.log
# echo "::notice title=@Transfer.sh::$(cat transfer.trs.log | grep https)"
# echo "🔗 [Transfer.sh]($(cat transfer.trs.log | grep https | cut -f3 -d' '))" >> release.txt
# )
wait
# for release
# echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H%M")"
echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT
- name: SSH After Compile
uses: mxschmitt/action-tmate@v3
if: ${{ failure() }}
- name: Upload Firmware to Release
uses: softprops/action-gh-release@v1
if: env.UPLOAD_RELEASE == 'true' && steps.transfer.conclusion == 'success' && !cancelled()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.transfer.outputs.release_tag }}
body_path: release.txt
files: ${{ env.FIRMWARE }}/*
- name: Delete Workflow Runs
uses: Mattraks/delete-workflow-runs@main
with:
retain_days: 30
keep_minimum_runs: 5
- name: Remove Old Releases
uses: dev-drprasad/delete-older-releases@v0.2.0
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
with:
keep_latest: 3
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}