forked from kiddin9/Kwrt
-
Notifications
You must be signed in to change notification settings - Fork 0
312 lines (279 loc) · 13.9 KB
/
Openwrt-AutoBuild.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
#=================================================
# https://github.com/P3TERX/Actions-OpenWrt
# Description: Build OpenWrt using GitHub Actions
# Lisence: MIT
# Author: P3TERX
# Blog: https://p3terx.com
#=================================================
name: Build OpenWrt
on:
repository_dispatch:
env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PPPOE_USERNAME: ${{ secrets.PPPOE_USERNAME }}
PPPOE_PASSWD: ${{ secrets.PPPOE_PASSWD }}
SCKEY: ${{ secrets.SCKEY }}
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
TZ: Asia/Shanghai
jobs:
build:
runs-on: Ubuntu-20.04
name: Build ${{matrix.target}}
strategy:
fail-fast: false
matrix:
target: ["${{ github.event.client_payload.target }}"]
steps:
- name: Checkout
uses: actions/checkout@main
- name: cancel running workflows
uses: styfle/cancel-workflow-action@main
if: contains(github.event.action, 'cw')
with:
workflow_id: 4439867
access_token: ${{ github.token }}
- name: Load Settings.ini
run: |
source "${GITHUB_WORKSPACE}/devices/common/settings.ini"
if [ -f "devices/${{matrix.target}}/settings.ini" ]; then
source "${GITHUB_WORKSPACE}/devices/${{matrix.target}}/settings.ini"
fi
echo "REPO_URL=${REPO_URL}" >> $GITHUB_ENV
echo "REPO_BRANCH=${REPO_BRANCH}" >> $GITHUB_ENV
echo "CONFIG_FILE=${CONFIG_FILE}" >> $GITHUB_ENV
echo "DIY_SH=${DIY_SH}" >> $GITHUB_ENV
echo "FREE_UP_DISK=${FREE_UP_DISK}" >> $GITHUB_ENV
echo "UPLOAD_BIN_DIR_FOR_ARTIFACT=${UPLOAD_BIN_DIR_FOR_ARTIFACT}" >> $GITHUB_ENV
echo "UPLOAD_FIRMWARE_FOR_ARTIFACT=${UPLOAD_FIRMWARE_FOR_ARTIFACT}" >> $GITHUB_ENV
echo "UPLOAD_FIRMWARE_FOR_RELEASE=${UPLOAD_FIRMWARE_FOR_RELEASE}" >> $GITHUB_ENV
echo "UPLOAD_FIRMWARE_TO_COWTRANSFER=${UPLOAD_FIRMWARE_TO_COWTRANSFER}" >> $GITHUB_ENV
echo "UPLOAD_FIRMWARE_TO_WETRANSFER=${UPLOAD_FIRMWARE_TO_WETRANSFER}" >> $GITHUB_ENV
- name: Trigger Packages Update
run: |
gitdate=$(curl -s "https://api.github.com/repos/garypang13/openwrt-packages/actions/runs" | jq -r '.workflow_runs[0].updated_at')
gitdate=$(date -d "$gitdate" +%s)
now=$(date -d "$(date '+%Y-%m-%d %H:%M:%S')" +%s)
if [[ $(expr $gitdate + 300) < $now ]]; then
gitdate=$(curl -s "https://api.github.com/repos/garypang13/openwrt-packages/actions/runs" | jq -r '.workflow_runs[0].created_at')
gitdate=$(date -d "$gitdate" +%s)
now=$(date -d "$(date '+%Y-%m-%d %H:%M:%S')" +%s)
if [[ $(expr $gitdate + 300) < $now ]]; then
curl -X POST https://api.github.com/repos/garypang13/openwrt-packages/dispatches \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token ${{ secrets.REPO_TOKEN }}" \
--data '{"event_type": "update"}'
fi
sleep 10
fi
- name: Initialization environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
( sudo -E apt-get -qq purge azure-cli ghc* zulu* hhvm llvm* firefox powershell openjdk* dotnet* google* mysql* php* android*
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 build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs gcc-multilib g++-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler ccache xsltproc rename antlr3 gperf wget curl swig rsync upx
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean ) &
sudo timedatectl set-timezone "$TZ"
- name: Get current date
id: date
run: |
echo "date=$(date +'%m/%d_%Y_%H/%M')" >> $GITHUB_ENV
echo "date2=$(date +'%m/%d %Y')" >> $GITHUB_ENV
echo "date3=$(date +'%m.%d')" >> $GITHUB_ENV
echo "date4=$(date +'%m.%d.%Y')" >> $GITHUB_ENV
- name: Clone source code
run: |
git clone --depth 1 $REPO_URL -b $REPO_BRANCH openwrt
cd openwrt
if [[ ${{matrix.target}} =~ (redmi-ac2100|phicomm-k2p|newifi-d2|k2p-32m-usb|XY-C5|xiaomi-r3p) ]]; then
wget -cO sdk.tar.xz https://downloads.openwrt.org/releases/21.02-SNAPSHOT/targets/ramips/mt7621/openwrt-sdk-21.02-SNAPSHOT-ramips-mt7621_gcc-8.4.0_musl.Linux-x86_64.tar.xz
elif [[ ${{matrix.target}} == "x86_64" ]]; then
wget -cO sdk.tar.xz https://downloads.openwrt.org/releases/21.02-SNAPSHOT/targets/x86/64/openwrt-sdk-21.02-SNAPSHOT-x86-64_gcc-8.4.0_musl.Linux-x86_64.tar.xz
elif [[ ${{matrix.target}} =~ (nanopi-r2s|nanopi-r4s) ]]; then
wget -cO sdk.tar.xz https://downloads.openwrt.org/releases/21.02-SNAPSHOT/targets/rockchip/armv8/openwrt-sdk-21.02-SNAPSHOT-rockchip-armv8_gcc-8.4.0_musl.Linux-x86_64.tar.xz
fi
- name: Free up disk space
if: env.FREE_UP_DISK == 'true'
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo mkdir -p -m 777 /mnt/openwrt/dl /mnt/openwrt/staging_dir /mnt/openwrt/build_dir/hostpkg openwrt/build_dir
ln -sf /mnt/openwrt/dl openwrt/dl
ln -sf /mnt/openwrt/staging_dir openwrt/staging_dir
ln -sf /mnt/openwrt/build_dir/hostpkg openwrt/build_dir/hostpkg
- name: Load && Update feeds
run: |
cp -rf devices/common/. openwrt/
cp -rf devices/${{matrix.target}}/. openwrt/
cd openwrt
./scripts/feeds update -a
- name: Load custom configuration
run: |
cp -rf devices openwrt/
cd openwrt
chmod +x devices/common/$DIY_SH
/bin/bash "devices/common/$DIY_SH"
cp -Rf ./diy/* ./
if [ -f "devices/${{matrix.target}}/$DIY_SH" ]; then
chmod +x devices/${{matrix.target}}/$DIY_SH
/bin/bash "devices/${{matrix.target}}/$DIY_SH"
fi
cp -f devices/common/default-settings package/*/*/default-settings/files/uci.defaults
if [ -f "devices/${{matrix.target}}/default-settings" ]; then
echo >> package/*/*/default-settings/files/uci.defaults
cat devices/${{matrix.target}}/default-settings >> package/*/*/default-settings/files/uci.defaults
fi
cp -f devices/common/$CONFIG_FILE .config
if [ -f "devices/${{matrix.target}}/$CONFIG_FILE" ]; then
echo >> .config
cat devices/${{matrix.target}}/$CONFIG_FILE >> .config
fi
- name: Apply patches
run: |
cd openwrt
find "devices/common/patches" -type f ! -path 'devices/common/patches/china_mirrors.patch' -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 -E --forward --no-backup-if-mismatch"
if [ -n "$(ls -A "devices/${{matrix.target}}/patches" 2>/dev/null)" ]; then
find "devices/${{matrix.target}}/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p1 -E --forward --no-backup-if-mismatch"
fi
- name: Default PPPOE Setting
if: env.PPPOE_USERNAME && env.PPPOE_PASSWD
run: |
sed -i '$i uci set network.wan.username=${{ env.PPPOE_USERNAME }}' openwrt/package/*/*/default-settings/files/uci.defaults
sed -i '$i uci set network.wan.password=${{ env.PPPOE_PASSWD }}' openwrt/package/*/*/default-settings/files/uci.defaults
sed -i '$i uci commit network' openwrt/package/*/*/default-settings/files/uci.defaults
- name: SSH connection to Actions
uses: garypang13/debugger-action@master
if: contains(github.event.action, 'ssh')
- name: Download package
id: package
run: |
cd openwrt
make defconfig
make download -j$(($(nproc)+1)) &
- name: Compile the firmware
id: compile
run: |
cd openwrt
echo -e "$(($(nproc)+1)) thread compile"
make -j$(($(nproc)+1)) || make -j1 V=s
echo "::set-output name=status::success"
- name: Check space usage
run: df -hT
- name: Upload bin directory
uses: actions/upload-artifact@main
if: env.UPLOAD_BIN_DIR_FOR_ARTIFACT == 'true'
with:
name: OpenWrt_bin_${{matrix.target}}
path: openwrt/bin
- name: Organize files
id: organize
run: |
mkdir firmware && find openwrt/bin/targets/*/*/ -maxdepth 1 \
-name "*combined*" \
-or -name "*sysupgrade*" \
-or -name "*armvirt-64-default-rootfs*" \
-or -name "sha256sums" \
| xargs -i mv -f {} ./firmware/
cp openwrt/.config ./firmware/${{matrix.target}}.config
cd firmware
echo ${{ env.date4 }} > version.txt
mv sha256sums ${{matrix.target}}_sha256sums
rename -v "s/^openwrt/${{ env.date3 }}-openwrt/" *
rename -v "s/xiaomi_redmi-router/redmi/" *bin
rename -v "s/(d-team_|xiaoyu_)//" *bin
rename -v "s/friendlyarm_//" *gz
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
Emoji=("🎉" "🤞" "✨" "🎁" "🎈" "🎄" "🎨" "💋" "🍓" "🍕" "🍉" "💐" "🌴" "🚀" "🛸" "🗽" "⛅" "🌈" "🔥" "⛄" "🐶" "🏅" "🦄" "🐤")
RANDOM=$$$(date +%s)
rand=$[$RANDOM % ${#Emoji[@]}]
echo "EMOJI=${Emoji[$rand]}" >> $GITHUB_ENV
if [ ${{matrix.target}} == "phicomm-k2p" ]; then
echo "NOTICE=刷机时breed里的闪存布局请选择斐讯而非默认的公版" >> $GITHUB_ENV
elif [ ${{matrix.target}} == "x86_64" ]; then
echo "NOTICE=请分配不少于800M的存储容量" >> $GITHUB_ENV
fi
- name: Deploy files to server
uses: easingthemes/ssh-deploy@master
continue-on-error: true
if: env.SSH_PRIVATE_KEY && ! contains(github.event.action, 'noser')
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-avzr --exclude="
SOURCE: firmware/
REMOTE_HOST: op.supes.top
REMOTE_USER: root
TARGET: "/www/wwwroot/op.supes.top/firmware/${{matrix.target}}/"
- name: Upload firmware to cowtransfer
if: env.UPLOAD_FIRMWARE_TO_COWTRANSFER == 'true'
continue-on-error: true
run: |
curl -fsSL git.io/file-transfer | sh
cowurl=$(./transfer cow --block 2621440 -s --no-progress ${FIRMWARE})
cowurl=$(echo $cowurl | grep -o -E "https[^ ]*")
echo "COWURL=$cowurl" >> $GITHUB_ENV
echo "Download Link: ${{ env.EMOJI }} $cowurl ${{ env.EMOJI }} 🚀"
- name: Upload firmware to WeTransfer
if: env.UPLOAD_FIRMWARE_TO_WETRANSFER == 'true' && ! contains(github.event.action, 'noup')
continue-on-error: true
run: |
curl -fsSL git.io/file-transfer | sh
wetrans=$(./transfer wet -s -p 16 --no-progress ${FIRMWARE})
wetrans=$(echo $wetrans | grep -o -E "https[^ ]*")
echo "WETRANS=$wetrans" >> $GITHUB_ENV
echo "Download Link: ${{ env.EMOJI }} $wetrans ${{ env.EMOJI }} 🚀"
- name: Create release
id: create_release
if: env.REPO_TOKEN && env.UPLOAD_FIRMWARE_FOR_RELEASE == 'true'
continue-on-error: true
run: |
echo -e "墙内加速下载 🚀:\n" >> release.txt
echo -e "[腾讯云] (https://op.supes.top/firmware/${{matrix.target}}/ ☁)\n" >> release.txt
[ ${{ env.WETRANS }} ] && echo -e "[WeTransfer] (${{ env.WETRANS }} 🗽)\n" >> release.txt
[ ${{ env.COWURL }} ] && echo -e "[奶牛上传] (${{ env.COWURL }} 🐮)\n" >> release.txt
[ ${{ env.NOTICE }} ] && echo -e "${{ env.NOTICE }}" >> release.txt || true
- name: Upload firmware for release
uses: softprops/action-gh-release@v1
continue-on-error: true
if: env.REPO_TOKEN && env.UPLOAD_FIRMWARE_FOR_RELEASE == 'true'
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
with:
files: "${{ env.FIRMWARE }}/*"
name: ${{ env.date2 }} ${{matrix.target}} ${{ env.EMOJI }}
tag_name: ${{ env.date }}_${{matrix.target}}
body_path: release.txt
- name: Upload firmware for artifact
uses: actions/upload-artifact@main
continue-on-error: true
if: env.UPLOAD_FIRMWARE_FOR_ARTIFACT == 'true'
with:
name: ${{ env.date3 }} ${{matrix.target}}
path: ${{ env.FIRMWARE }}
- name: WeChat notification
continue-on-error: true
if: env.SCKEY
run: |
[ steps.compile.outputs.status == 'success' ] && curl https://sc.ftqq.com/${{ secrets.SCKEY }}.send?text=🎉OpenWrt_${{ env.date3 }}_${{matrix.target}}编译完成😋|| curl https://sc.ftqq.com/${{ secrets.SCKEY }}.send?text=❌OpenWrt_${{ env.date3 }}_${{matrix.target}}编译失败😂
- name: Telegram notification
if: env.TELEGRAM_TOKEN && ! contains(github.event.action, 'notg')
continue-on-error: true
run: |
# [ steps.compile.outputs.status == 'success' ] && curl -k --data chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" --data "text=🎉 OpenWrt ${{ env.date3 }} ${{matrix.target}} 编译成功 😋 https://op.supes.top/firmware/${{matrix.target}}/ ${{ env.COWURL }} ${{ env.WETRANS }} 🚀" "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage" || curl -k --data chat_id="${{ secrets.TELEGRAM_TO }}" --data "text=❌ OpenWrt ${{ env.date3 }} ${{matrix.target}} 编译失败 😂" "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage"
- name: Delete workflow runs
uses: GitRML/delete-workflow-runs@main
with:
retain_days: 10
keep_minimum_runs: 0
- name: Remove old Releases
uses: dev-drprasad/delete-older-releases@master
continue-on-error: true
if: env.UPLOAD_FIRMWARE_FOR_RELEASE == 'true' && !cancelled()
with:
keep_latest: 15
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}