forked from stupidloud/nanopi-openwrt
-
Notifications
You must be signed in to change notification settings - Fork 0
323 lines (294 loc) · 15.6 KB
/
lo-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
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
name: build
on:
repository_dispatch:
workflow_dispatch:
inputs:
device:
description: 'select device to build'
default: 'r6s'
required: false
branch:
description: 'seleclt openwrt branch'
default: 'master'
required: false
jobs:
build_packages:
name: Build ${{ github.event.client_payload.device || github.event.inputs.device }} packages
runs-on: ubuntu-latest
env:
DEVICE: ${{ github.event.client_payload.device || github.event.inputs.device }}
BRANCH: ${{ github.event.client_payload.branch || github.event.inputs.branch }}
TG: ${{ secrets.TELEGRAM_BOT_TOKEN }}
if: github.repository_owner=='stupidloud'
steps:
- name: Space cleanup
env:
DEBIAN_FRONTEND: noninteractive
run: |
nohup sh -c '
sudo sysctl vm.swappiness=0
sudo apt update;
sudo apt -qq -y --no-install-recommends install pv jq \
ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache clang cmake cpio curl device-tree-compiler ecj fastjar flex gawk gettext gcc-multilib \
g++-multilib git gnutls-dev gperf haveged help2man intltool lib32gcc-s1 libc6-dev-i386 libelf-dev \
libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5 \
libncursesw5-dev libpython3-dev libreadline-dev libssl-dev libtool lld llvm lrzsz mkisofs \
nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pip python3-ply \
python3-docutils python3-pyelftools qemu-utils re2c rsync scons squashfs-tools subversion swig \
texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
' &
sudo rm -rf /usr/share/dotnet /usr/local/lib/android/sdk /opt/hostedtoolcache
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Checkout
run: |
cd
curl -sL https://raw.githubusercontent.com/stupidloud/nanopi-openwrt/zstd-bin/zstd | sudo tee /usr/bin/zstd > /dev/null
sudo chown $USER:$(id -gn) /mnt
for i in {1..20}
do
curl -sL --fail https://github.com/stupidloud/sshactions/releases/download/cache/lede.$DEVICE.img.zst.0$i || break
done | zstdmt -d -o /mnt/lede.img || (truncate -s 30g /mnt/lede.img && mkfs.btrfs -M /mnt/lede.img)
LOOP_DEVICE=$(losetup -f) && echo "LOOP_DEVICE=$LOOP_DEVICE" >> $GITHUB_ENV
sudo losetup -P --direct-io $LOOP_DEVICE /mnt/lede.img
mkdir lede && sudo mount -o nossd,compress=zstd $LOOP_DEVICE lede
if [ -d 'lede/.git' ]; then
cd lede && rm -f zerospace && git config --local user.email "[email protected]" && git config --local user.name "GitHub Action"
git fetch && git reset --hard origin/$BRANCH && git clean -df
else
sudo chown $USER:$(id -gn) lede && git clone -b $BRANCH --single-branch https://github.com/coolsnowwolf/lede lede
fi
- name: Update feeds and packages
run: |
cd ~/lede
rm -rf ./tmp && rm -rf ./feeds && rm -rf ./pacakges/feeds
if [ -d 'feeds' ]; then
pushd feeds/packages; git restore .; popd
pushd feeds/luci; git restore .; popd
pushd feeds/routing; git restore .; popd
pushd feeds/telephony; git restore .; popd
fi
./scripts/feeds update -a
./scripts/feeds install -a
. $GITHUB_WORKSPACE/scripts/merge_packages.sh
. $GITHUB_WORKSPACE/scripts/patches.sh
cd
git clone --depth=1 --single-branch https://github.com/openwrt/luci
pushd luci
ls -d */ | xargs -ri diff -q {} ../lede/feeds/luci/{} | grep Only | grep lede | grep -E applications\|themes | awk '{print $4}' | xargs -ri echo CONFIG_PACKAGE_{}=m > ~/lede/more_luci.txt
popd
- name: Custom configure file
run: |
cd ~/lede && rm -rf tmp/
cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | sed 's/\(CONFIG_PACKAGE_luci-app-[^A-Z]*=\)y/\1m/' > .config
find package/ -type d -name luci-app-* | rev | cut -d'/' -f1 | rev | xargs -ri echo CONFIG_PACKAGE_{}=m >> .config
cat $GITHUB_WORKSPACE/extra_packages.seed >> .config
cat more_luci.txt >> .config
[ -f .config_fix ] && cat .config_fix >> .config
make defconfig && sed -i -E 's/# (CONFIG_.*_COMPRESS_UPX) is not set/\1=y/' .config && make defconfig
cat .config
- name: Debug via tmate
uses: stupidloud/ssh2actions@main
if: ${{ github.event.client_payload.debug == 'true' }}
with:
mode: ssh
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
SSH_PASSWORD: ${{secrets.SSH_PASSWORD}}
SSH_PUBKEY: ${{secrets.SSH_PUBKEY}}
TUNNEL_KEY: ${{secrets.TUNNEL_KEY}}
TUNNEL_HOST: ${{secrets.TUNNEL_HOST}}
- name: Clean build cache
if: ${{ github.event.client_payload.package_clean == 'true' || github.event.inputs.device != '' }}
run: |
cd ~/lede
df -h .
make clean || true
df -h .
- name: Build and deploy packages
timeout-minutes: 1440
run: |
ulimit -SHn 65000
cd ~/lede
while true; do make download -j && break || true; done
make -j$[`nproc`+1] IGNORE_ERRORS=1 tools/compile toolchain/compile buildinfo target/compile package/compile package/install target/install
if [ ! -e ~/lede/bin/targets/*/*/*imagebuilder*xz ]; then make IGNORE_ERRORS=1 V=sc; fi
mv `ls ~/lede/bin/targets/*/*/*imagebuilder*xz` ~/ib-$DEVICE.tar.xz
echo "======================="
echo "Space usage:"
echo "======================="
df -h
echo "======================="
du -h --max-depth=1 ./ --exclude=build_dir --exclude=bin
du -h --max-depth=1 ./build_dir
du -h --max-depth=1 ./bin
- name: Prepare artifact
run: |
cd
mkdir -p ./artifact/buildinfo
cd lede
cp -rf $(find ./bin/targets/ -type f -name "*.buildinfo" -o -name "*.manifest") ../artifact/buildinfo/
cp -rf .config ../artifact/buildinfo/
echo "strDate=$(TZ=UTC-8 date +%Y-%m-%d)" >> $GITHUB_ENV
echo "strDevice=$(echo $DEVICE | awk '{print toupper($0)}')" >> $GITHUB_ENV
cd ..
mv artifact $GITHUB_WORKSPACE
- name: Clean build cache
if: ${{ github.event.client_payload.package_clean == 'true' }}
run: |
cd ~/lede
df -h .
make clean
rm -rf bin tmp
df -h .
- name: Deliver buildinfo
uses: actions/upload-artifact@v2
with:
name: OpenWrt_buildinfo
path: ./artifact/buildinfo/
- name: Save cache state
if: env.TG
run: |
cd
sleep 60
sudo mount -o remount,compress=no,nodatacow,nodatasum lede
cd lede/; pv /dev/zero > zerospace || true; sync; rm -f zerospace; cd -
sleep 60
sudo umount lede
sudo losetup -d $LOOP_DEVICE
export AUTH="Authorization: token ${{ secrets.SEC_TOKEN }}"
export cache_path='github.com/repositories/233224580/releases'
export cache_repo_id='39020554'
#zstdmt -c --adapt --long lede.img | parallel --wc --block 1.99G --pipe \
#'curl -s --data-binary @- -H "$AUTH" -H "Content-Type: application/octet-stream" https://uploads.$cache_path/$cache_repo_id/assets?name=lede.'$DEVICE'.img.zst.0{#} > /dev/null'
zstdmt -c --long /mnt/lede.img | split --numeric=1 -b 2000m - lede.$DEVICE.img.zst.
#for f in *img.zst*
#do
# while true; do curl --data-binary @$f -H "$AUTH" -H 'Content-Type: application/octet-stream' "https://uploads.$cache_path/$cache_repo_id/assets?name=$f" && break || true; done
#done
while true; do
ret=$(curl -sH "$AUTH" "https://api.$cache_path/tags/cache")
echo $ret | jq -r '.assets[] | select(.name | contains ("'$DEVICE'.img")).id' | \
xargs -ri curl -X DELETE -H "$AUTH" "https://api.$cache_path/assets/{}"
echo $ret | jq -r '.assets[] | select(.name == "ib-'$DEVICE'.tar.xz").id' | \
xargs -ri curl -X DELETE -H "$AUTH" "https://api.$cache_path/assets/{}"
ls *img.zst* ib-$DEVICE.tar.xz | parallel --wc 'while true; do curl -T {} -H "$AUTH" -H "Content-Type: application/octet-stream" "https://uploads.$cache_path/$cache_repo_id/assets?name={}" && break || true; done'
set +e
for i in {1..20}; do curl -sL --fail https://github.com/stupidloud/sshactions/releases/download/cache/lede.$DEVICE.img.zst.0$i || break; done | zstdmt -d -o /dev/null
if [ $? -eq 0 ]; then break; fi
done
set -e
- name: Send tg notification
if: env.TG
run: |
curl -k --data chat_id="${{secrets.TELEGRAM_CHAT_ID}}" --data "text=The ${{env.DEVICE}} build ran completed at ${{job.status}}." "https://api.telegram.org/bot${{secrets.TELEGRAM_BOT_TOKEN}}/sendMessage"
- name: Debug via tmate
uses: stupidloud/ssh2actions@main
if: ${{ failure() && env.TG }}
with:
mode: ssh
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
SSH_PASSWORD: ${{secrets.SSH_PASSWORD}}
SSH_PUBKEY: ${{secrets.SSH_PUBKEY}}
TUNNEL_KEY: ${{secrets.TUNNEL_KEY}}
TUNNEL_HOST: ${{secrets.TUNNEL_HOST}}
generate_slim_firmware:
needs: build_packages
name: Generate ${{ github.event.client_payload.device || github.event.inputs.device }} slim firmware
runs-on: ubuntu-latest
env:
DEVICE: ${{ github.event.client_payload.device || github.event.inputs.device }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Generate firmware
run: |
sudo apt update && sudo apt install qemu-utils
sudo sysctl vm.swappiness=0
ulimit -SHn 65000
curl -L https://github.com/stupidloud/sshactions/releases/download/cache/ib-$DEVICE.tar.xz | tar -Jxvf -
mv *imagebuilder* ib && cd ib
. $GITHUB_WORKSPACE/scripts/merge_files.sh
mkdir -p files/local_feed && sudo mount --bind packages files/local_feed
sed -i 's/luci-app-[^ ]*//g' include/target.mk $(find target/ -name Makefile)
sed -i 's/$(OPKG) install $(BUILD_PACKAGES)/$(OPKG) install --force-overwrite $(BUILD_PACKAGES)/' Makefile
ls packages/*.ipk | xargs -n1 basename > package.files
PACKAGES=$(cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE | grep '=y' | grep -v CONFIG_PACKAGE_luci-app | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -ri grep -o {} package.files | sort -u | xargs echo)
PACKAGES="$PACKAGES `grep -o luci-i18n-opkg-zh-cn package.files || true`"
make image PACKAGES="$PACKAGES $LUCI $LP luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn" FILES="files"
mkdir -p $GITHUB_WORKSPACE/release
mv $(ls -1 ./bin/targets/*/*/*img.gz | head -1) $GITHUB_WORKSPACE/release/$DEVICE-slim.img.gz
cd $GITHUB_WORKSPACE/release/ && md5sum $DEVICE-slim.img.gz > $DEVICE-slim.img.gz.md5
gzip -dc $DEVICE-slim.img.gz | md5sum | sed "s/-/$DEVICE-slim.img/" > $DEVICE-slim.img.md5
echo "strDate=$(TZ=UTC-8 date +%Y-%m-%d)" >> $GITHUB_ENV
echo "strDevice=$(echo $DEVICE | awk '{print toupper($0)}')" >> $GITHUB_ENV
- name: Upload release asset
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./release/*
tag: ${{env.strDate}}
file_glob: true
overwrite: true
release_name: ${{env.strDate}} 自动发布
generate_firmware:
needs: build_packages
if: always()
name: Generate ${{ github.event.client_payload.device || github.event.inputs.device }} firmware
runs-on: ubuntu-latest
env:
DEVICE: ${{ github.event.client_payload.device || github.event.inputs.device }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Generate firmware
run: |
sudo apt update && sudo apt install qemu-utils
sudo sysctl vm.swappiness=0
ulimit -SHn 65000
curl -L https://github.com/stupidloud/sshactions/releases/download/cache/ib-$DEVICE.tar.xz | tar -Jxvf -
set -x
mv *imagebuilder* ib && cd ib
. $GITHUB_WORKSPACE/scripts/merge_files.sh
sed -i '/local/d;s/#//' files/etc/opkg/distfeeds.conf
sed -i 's/luci-app-[^ ]*//g' include/target.mk $(find target/ -name Makefile)
sed -i 's/$(OPKG) install $(BUILD_PACKAGES)/$(OPKG) install --force-overwrite $(BUILD_PACKAGES)/' Makefile
ls packages/*.ipk | xargs -n1 basename > package.files
PACKAGES=$(cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE | grep '=y' | grep -v CONFIG_PACKAGE_luci-app | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -ri grep -o {} package.files | sort -u | xargs echo)
PACKAGES="$PACKAGES `grep -o luci-i18n-opkg-zh-cn package.files || true`"
LUCI=$(cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE_luci-app | grep '=y' | grep -v docker | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -ri grep -o {} package.files | sort -u | xargs echo)
LP=$(echo $LUCI | sed 's/-app-/-i18n-/g;s/ /\n/g' | xargs -ri grep -o {}-zh-cn package.files | xargs echo)
make image PACKAGES="$PACKAGES $LUCI $LP luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn" FILES="files"
mkdir -p $GITHUB_WORKSPACE/release
mv $(ls -1 ./bin/targets/*/*/*img.gz | head -1) $GITHUB_WORKSPACE/release/$DEVICE.img.gz
cd $GITHUB_WORKSPACE/release/ && md5sum $DEVICE.img.gz > $DEVICE.img.gz.md5
gzip -dc $DEVICE.img.gz | md5sum | sed "s/-/$DEVICE.img/" > $DEVICE.img.md5
echo "strDate=$(TZ=UTC-8 date +%Y-%m-%d)" >> $GITHUB_ENV
echo "strDevice=$(echo $DEVICE | awk '{print toupper($0)}')" >> $GITHUB_ENV
if [[ ${{ github.event.client_payload.device || github.event.inputs.device }} == *"r1s"* ]]; then
exit 0
fi
cd $GITHUB_WORKSPACE/ib
rm -rf bin/
LUCI=$(cat $GITHUB_WORKSPACE/$DEVICE.config.seed $GITHUB_WORKSPACE/common.seed | grep CONFIG_PACKAGE_luci-app | sed 's/CONFIG_PACKAGE_//;s/=y//' | xargs -ri grep -o {} package.files | sort -u | xargs echo)
LP=$(echo $LUCI | sed 's/-app-/-i18n-/g;s/ /\n/g' | xargs -ri grep -o {}-zh-cn package.files | xargs echo | xargs echo)
make image PACKAGES="$PACKAGES $LUCI $LP luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn" FILES="files"
mv $(ls -1 ./bin/targets/*/*/*img.gz | head -1) $GITHUB_WORKSPACE/release/$DEVICE-with-docker.img.gz
cd $GITHUB_WORKSPACE/release/ && md5sum $DEVICE-with-docker.img.gz > $DEVICE-with-docker.img.gz.md5
gzip -dc $DEVICE-with-docker.img.gz | md5sum | sed "s/-/$DEVICE-with-docker.img/" > $DEVICE-with-docker.img.md5
- name: Upload release asset
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./release/*
tag: ${{env.strDate}}
file_glob: true
overwrite: true
release_name: ${{env.strDate}} 自动发布