-
Notifications
You must be signed in to change notification settings - Fork 0
326 lines (292 loc) · 12.5 KB
/
build-immortalwrt.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
#=================================================
# https://github.com/P3TERX/Actions-OpenWrt
# Description: Build OpenWrt using GitHub Actions
# Lisence: MIT
# Author: P3TERX
# Blog: https://p3terx.com
#=================================================
name: Build-ImmortalWrt
on:
# push:
# paths: [ immortalwrt_openwrt ]
# schedule: [ cron: 0 2 */7 * * ]
# watch:
# types: started
workflow_dispatch:
inputs:
repo:
description: '选择仓库:'
default: 'ImmortalWrt'
required: true
type: choice
options: [ immortalwrt, openwrt ]
branch:
description: '选择的分支:'
default: 'openwrt-21.02'
required: true
type: choice
options: [ openwrt-21.02, openwrt-23.05, openwrt-24.10, master, openwrt-18.06-k5.4, openwrt-18.06 ]
target:
description: '选择要生成的机型:'
default: 'r1-plus-lts'
required: true
type: choice
options: [ x86_64, r1-plus-lts, newifi-d2, asus_rt-n16, phicomm_k2p, armvirt-64-default, r4s, r2s, r2c ]
# version:
# description: '选择要生成版本:'
# default: 'plus'
# required: true
# type: choice
# options: [ pure, plus ]
ip:
description: '设置web登录IP:'
default: '192.168.2.1'
required: false
partsize:
description: '设置rootfs大小:'
default: '800'
required: false
free_disk:
description: '整理空间'
type: choice
default: 'no'
options: [ 'losetup', 'free-disk-space', 'plus', 'no' ]
required: false
depends:
description: '编译依赖选项'
type: choice
default: 'default'
options: [ default, ImmortalWrt ]
required: false
env:
TZ: Asia/Shanghai
REPO_FLODER: 'openwrt'
UPLOAD_RELEASE: true
UPLOAD_BIN_DIR: true
UPLOAD_PACKAGES: true
UPLOAD_SYSUPGRADE: true
UPLOAD_WETRANSFER: true
UPLOAD_COWTRANSFER: true
jobs:
immo-openwrt:
runs-on: ubuntu-20.04
if: github.event.repository.owner.id == github.event.sender.id || ! github.event.sender.id
name: ${{github.event.inputs.repo}}-${{github.event.inputs.branch}}-${{github.event.inputs.target}}
permissions:
contents: write
env:
IP: ${{github.event.inputs.ip}}
REPO: ${{github.event.inputs.repo}}
DEPENDS: ${{github.event.inputs.depends}}
# VERSION: ${{github.event.inputs.version}}
PARTSIZE: ${{github.event.inputs.partsize}}
REPO_BRANCH: ${{github.event.inputs.branch}}
FREE_DISK: ${{github.event.inputs.free_disk}}
TARGET_DEVICE: ${{github.event.inputs.target}}
# strategy:
# fail-fast: false
# matrix:
# target: ["${{github.event.inputs.target}}"]
steps:
- name: Checkout
uses: actions/[email protected]
- name: jlumbroso 整理磁盘
continue-on-error: true
uses: jlumbroso/free-disk-space@main
if: env.FREE_DISK == 'plus' || env.FREE_DISK == 'free-disk-space'
with:
dotnet: true
android: true
haskell: true
tool-cache: true
swap-storage: true
large-packages: true
- name: losetup 整理磁盘
continue-on-error: true
if: env.FREE_DISK == 'plus' || env.FREE_DISK == 'losetup'
run: |
[ -f /mnt/swapfile ] && sudo swapoff -a && sudo rm -f /mnt/swapfile
export ROOT_LOOP_BYTES=$((($(df --block-size=1024 --output=avail / | tail -1) - 1024*1024*7) * 1024))
sudo fallocate -l $ROOT_LOOP_BYTES /root.img
export ROOT_LOOP_DEVNAME=$(sudo losetup -Pf --show /root.img)
sudo pvcreate -f $ROOT_LOOP_DEVNAME
export MNT_LOOP_BYTES=$((($(df --block-size=1024 --output=avail /mnt | tail -1) - 1024*1024*1) * 1024))
sudo fallocate -l $MNT_LOOP_BYTES /mnt/mnt.img
export MNT_LOOP_DEVNAME=$(sudo losetup -Pf --show /mnt/mnt.img)
sudo pvcreate -f $MNT_LOOP_DEVNAME
sudo vgcreate Actions $ROOT_LOOP_DEVNAME $MNT_LOOP_DEVNAME
sudo lvcreate -n disk -l 100%FREE Actions
export LV_DEVNAME=$(sudo lvscan | awk -F "'" '{print $2}')
sudo mkfs.btrfs -L combinedisk $LV_DEVNAME
sudo mount -o compress=zstd $LV_DEVNAME $GITHUB_WORKSPACE
sudo chown -R runner:runner $GITHUB_WORKSPACE
mkdir -m 0777 -p $GITHUB_WORKSPACE/tmp
sudo cp -rp /tmp/* $GITHUB_WORKSPACE/tmp || true
sudo mount -B $GITHUB_WORKSPACE/tmp /tmp
- name: 系统信息
run: |
echo "--------------------------CPU信息--------------------------"
echo "CPU物理数量:$(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)"
echo -e "CPU核心信息:$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \n"
echo "--------------------------内存信息--------------------------"
echo "已安装内存详细信息:"
echo -e "$(sudo lshw -short -C memory | grep GiB) \n"
echo "--------------------------磁盘使用情况-----------------------"
echo "硬盘数量:$(ls /dev/sd* | grep -v [1-9] | wc -l)" && df -hT
Emoji=("🎉" "🤞" "✨" "🎁" "🎈" "🎄" "🎨" "💋" "🍓" "🍕" "🍉" "💐" "🌴" "🚀" "🗽" "⛅" "🌈" "🔥" "⛄" "🐶" "🏅" "🦄" "🐤")
RANDOM=$$$(date +%s); rand=$[$RANDOM % ${#Emoji[@]}]
echo "EMOJI=${Emoji[$rand]}" >>$GITHUB_ENV
- name: 安装编译依赖
continue-on-error: true
env:
DEBIAN_FRONTEND: noninteractive
run: |
if [[ $DEPENDS == 'ImmortalWrt' ]]; then
wget -qO- is.gd/build_environment | sudo bash
else
( sudo -E apt-get -qq update
sudo -E apt-get -qq install ack antlr3 aria2 asciidoc autoconf automake autopoint binutils \
bison build-essential bzip2 ccache clang cmake cpio curl device-tree-compiler fastjar flex \
g++ gawk gcc-multilib gettext 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 \
libpython3-dev libreadline-dev libssl-dev libtool lrzsz mkisofs msmtp nano ninja-build p7zip \
p7zip-full patch pkgconf python2.7 python3 python3-distutils python3-pyelftools python3-pip \
python3-ply python3-docutils python3-pyelftools quilt re2c rename rsync scons squashfs-tools \
subversion swig texinfo uglifyjs unzip upx-ucl vim wget xmlto xxd zip zlib1g-dev
sudo -E apt-get -qq purge android* azure-cli dotnet* firefox ghc* google* hhvm llvm* mysql* \
openjdk* php* powershell zulu*
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean ) &
fi
sudo -E timedatectl set-timezone "Asia/Shanghai"
- name: 部署
continue-on-error: true
# run: wget -qO- git.io/J6IXO | bash
run: wget -qO- is.gd/immortalwrt_openwrt | bash
- name: Cache
uses: stupidloud/cachewrtbuild@main
continue-on-error: true
if: env.CACHE_ACTIONS == 'true'
with:
ccache: 'true'
clean: ${{env.CLEAN}}
mixkey: ${{env.CACHE_NAME}}
prefix: ${{github.workspace}}/${{env.REPO_FLODER}}
- name: tools
continue-on-error: true
if: env.CACHE_ACTIONS == 'true' && !cancelled()
id: tools
run: cd $REPO_FLODER && (make -j$(nproc) toolchain/compile || make -j1 V=s toolchain/compile)
- name: 保存 Cache
id: fetch_cache
if: (env.FETCH_CACHE == 'true' || steps.tools.conclusion == 'success') && !cancelled()
run: wget -qO- git.io/lean_openwrt | bash
- name: Cache 上传到 Release
continue-on-error: true
if: steps.fetch_cache.conclusion == 'success' || env.OUTPUT_RELEASE == 'true' && !cancelled()
uses: softprops/[email protected]
with:
files: output/*
token: ${{secrets.GITHUB_TOKEN}}
body: ${{env.REPO}}-Cache
tag_name: ${{env.REPO}}-Cache
name: ${{env.EMOJI}} ${{env.REPO}}-Cache ${{env.EMOJI}}
- name: 下载软件包
run: |
cd $REPO_FLODER
# make package/download -j16
n=0; while true; do make package/download -j && break || (n=$((n+1)); [ $n -eq 3 ] && break); done
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
- name: 固件编译
timeout-minutes: 1440
continue-on-error: true
id: compile
run: cd $REPO_FLODER && make -j$(nproc) || make -j1 V=s
- name: 上传 Bin
uses: actions/[email protected]
if: steps.organize.conclusion == 'success' && env.UPLOAD_BIN_DIR == 'true' && !cancelled()
with:
path: ${{env.REPO_FLODER}}/bin
name: OpenWrt-${{env.TARGET_DEVICE}}-bin
- name: 筛选固件
id: organize
if: steps.compile.conclusion == 'success' && !cancelled()
run: |
echo "======================="
echo "磁盘使用情况:"
echo "======================="
df -hT
cd $REPO_FLODER
echo "======================="
du -h --max-depth=1 ./bin
du -h --max-depth=1 ./build_dir
du -h --max-depth=1 ./staging_dir
du -h --max-depth=1 ./ --exclude=bin --exclude=build_dir --exclude=staging_dir --exclude=bin
ls bin/targets/*/*/
sf=${CACHE_NAME%%-*}-${REPO_BRANCH#*-}-$(TZ=UTC-8 date +%m-%d)
ARCH=`awk -F'"' '/ARCH_PACKAGES/{print $2}' .config`
[[ $FIRMWARE_TYPE ]] && cp -v $(find bin/targets/ -type f -name "*${FIRMWARE_TYPE}*") ../firmware && echo "upload_firmware=true" >>$GITHUB_ENV || true
tar -zcPf ../firmware/$sf-$ARCH-packages.tar.gz bin/packages/ && echo "upload_packages=true" >>$GITHUB_ENV || true
cd ../firmware && md5sum * >$sf-$TARGET_DEVICE-md5-config.txt || true
sed '/^$/d' ../$REPO_FLODER/.config >>$sf-$TARGET_DEVICE-md5-config.txt || true
echo "FIRMWARE=$PWD" >>$GITHUB_ENV
echo "STRDATE=$(TZ=UTC-8 date +%Y-%m-%d)" >>$GITHUB_ENV
- name: 上传 Packages
uses: actions/[email protected]
if: env.upload_packages == 'true' && env.UPLOAD_PACKAGES == 'true' && !cancelled()
with:
path: firmware/*packages.tar.gz
name: OpenWrt-${{env.TARGET_DEVICE}}-package
- name: 上传 Firmware
uses: actions/[email protected]
if: env.upload_firmware == 'true' && env.UPLOAD_SYSUPGRADE == 'true' && !cancelled()
with:
path: firmware/*${{env.FIRMWARE_TYPE}}*
name: OpenWrt-${{env.TARGET_DEVICE}}-firmware
- name: 上传到奶牛快传
id: cowtransfer
if: env.upload_firmware == 'true' && env.UPLOAD_COWTRANSFER == 'true' && !cancelled()
run: |
curl -fsSL git.io/file-transfer | sh ./transfer cow --block 2621440 -s -p 64 --no-progress $FIRMWARE 2>&1 | tee cowtransfer.log
echo "::warning file=↓↓奶牛快传下载地址↓↓::$(grep https cowtransfer.log)"
- name: 上传到 WeTransfer
id: wetransfer
if: env.upload_firmware == 'true' && env.UPLOAD_WETRANSFER == 'true' && !cancelled()
run: |
wget -qO- git.io/file-transfer | sh ./transfer wet -s -p 16 --no-progress $FIRMWARE 2>&1 | tee wetransfer.log
echo "::warning file=↓↓wetransfer下载地址↓↓::$(grep https wetransfer.log)"
pwd
- name: Firmware 上传到 Release
if: env.upload_firmware == 'true' && env.UPLOAD_RELEASE == 'true' && !cancelled()
uses: softprops/[email protected]
with:
files: firmware/*
token: ${{secrets.GITHUB_TOKEN}}
body: ${{env.REPO}}-firmware
tag_name: ${{env.STRDATE}}-${{env.REPO}}
name: ${{env.EMOJI}} ${{env.STRDATE}} ${{env.REPO}}-firmware ${{env.EMOJI}}
- name: Save cache state
continue-on-error: true
if: env.SAVE_CACHE == 'true' && !cancelled()
run: |
echo "上传到github"
export cache_repo_id='654643315'
export cache_path='github.com/repos/hong0980/OpenWrt-Cache/releases'
ls output | parallel --wc '
while true; do
curl -T {} \
-H "Content-Type: application/octet-stream" \
-H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \
"https://uploads.${cache_path}/${cache_repo_id}/assets?name={}" && break || true
done'
- name: Delete Releases
if: (!cancelled())
uses: dev-drprasad/[email protected]
with:
keep_latest: 15
delete_tags: true
delete_tag_pattern: ^.*immortalwrt$
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}