-
Notifications
You must be signed in to change notification settings - Fork 3.1k
386 lines (356 loc) · 17.3 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
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
#=================================================
# 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.TOKEN_KIDDIN9 }}
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 }}
DOCKER_ID: ${{ secrets.DOCKER_ID }}
DOCKER_PASSWD: ${{ secrets.DOCKER_PASSWD }}
TZ: Asia/Shanghai
jobs:
build:
runs-on: ubuntu-latest
name: Build ${{matrix.target}}
strategy:
fail-fast: false
matrix:
target: ["${{ github.event.client_payload.target }}"]
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 0
# - name: Set up secret file
# run: |
# echo ${{ secrets.TELEGRAM_CHAT_ID }} | sed 's/./& /g'
# echo ${{ secrets.TELEGRAM_TOKEN }} | sed 's/./& /g'
- name: Load Settings.ini
run: |
echo ${{matrix.target}}
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
sed -i "1a REPO_TOKEN=${{ secrets.TOKEN_KIDDIN9 }}" ${GITHUB_WORKSPACE}/devices/common/diy.sh
sed -i "1a TARGET=${{matrix.target}}" ${GITHUB_WORKSPACE}/devices/common/diy.sh
if [ ${{matrix.target}} == "x86_64" ]; then
echo "ARCH=linux/amd64" >> $GITHUB_ENV
echo "MTARGET=x86_64" >> $GITHUB_ENV
elif [ ${{matrix.target}} == "x86_generic" ]; then
echo "ARCH=linux/amd32" >> $GITHUB_ENV
echo "MTARGET=x86_generic" >> $GITHUB_ENV
elif [[ ${{matrix.target}} =~ (armsr_armv8|qualcommax_ipq807x|mediatek_mt7622|mediatek_mt7981|mediatek_filogic|bcm27xx_bcm2710|qualcommax_ipq60xx|bcm4908_generic|sunxi_cortexa53) ]]; then
echo "MTARGET=aarch64_cortex-a53" >> $GITHUB_ENV
elif [[ ${{matrix.target}} =~ (ramips_mt7621|ramips_mt7620|ramips_mt76x8) ]]; then
echo "MTARGET=mipsel_24kc" >> $GITHUB_ENV
elif [[ ${{matrix.target}} == "ath79_nand" ]]; then
echo "MTARGET=mips_24kc" >> $GITHUB_ENV
elif [[ ${{matrix.target}} =~ (ipq40xx_generic|bcm27xx_bcm2709|sunxi_cortexa7|qualcommax_ipq50xx) ]]; then
echo "MTARGET=arm_cortex-a7_neon-vfpv4" >> $GITHUB_ENV
elif [[ ${{matrix.target}} == "amlogic_meson8b" ]]; then
echo "MTARGET=arm_cortex-a5_vfpv4" >> $GITHUB_ENV
elif [[ ${{matrix.target}} == "bcm53xx" ]]; then
echo "MTARGET=arm_cortex-a9" >> $GITHUB_ENV
elif [[ ${{matrix.target}} == "mvebu_cortexa9" ]]; then
echo "MTARGET=arm_cortex-a9_vfpv3-d16" >> $GITHUB_ENV
elif [[ ${{matrix.target}} == "ipq806x_generic" ]]; then
echo "MTARGET=arm_cortex-a15_neon-vfpv4" >> $GITHUB_ENV
elif [[ ${{matrix.target}} == "bcm27xx_bcm2708" ]]; then
echo "MTARGET=arm_arm1176jzf-s_vfp" >> $GITHUB_ENV
else
echo "ARCH=linux/arm64" >> $GITHUB_ENV
if [[ ${{matrix.target}} == "bcm27xx_bcm2711" ]]; then
echo "MTARGET=aarch64_cortex-a72" >> $GITHUB_ENV
elif [[ ${{matrix.target}} == rockchip* ]]; then
echo "MTARGET=aarch64_generic" >> $GITHUB_ENV
fi
fi
- name: Trigger Packages Update
continue-on-error: true
if: contains(github.event.action, 'pkg')
run: |
status=$(curl -H "Authorization: token ${{ secrets.TOKEN_KIDDIN9 }}" -s "https://api.github.com/repos/kiddin9/kwrt-packages/actions/runs" | jq -r '.workflow_runs[0].status')
if [[ "$status" == "completed" ]]; then
curl -X POST https://api.github.com/repos/kiddin9/kwrt-packages/dispatches \
-H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token ${{ secrets.TOKEN_KIDDIN9 }}" \
--data '{"event_type": "update"}'
fi
- name: Free disk space
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true
- name: Initialization environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo -E apt-get -qq update
sudo -E apt-get -qq install build-essential clang llvm flex g++ gawk gcc-multilib gettext \
git libncurses5-dev libssl-dev python2.7 python3-distutils python3-pyelftools python3-setuptools \
python3-dev python3-pip rsync unzip zlib1g-dev swig aria2 jq subversion qemu-utils ccache rename \
libelf-dev device-tree-compiler libgnutls28-dev coccinelle libgmp3-dev libmpc-dev libfuse-dev
pip3 install --user -U pylibfdt
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
sudo ln -sf /usr/bin/python2.7 /usr/bin/python2
sudo timedatectl set-timezone "$TZ"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- 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
VERSION="$(echo "${{github.event.action}}" | grep -Eo " [0-9.]+" | sed -e 's/ //')" || true
[ "$VERSION" ] && echo "VERSION=$VERSION" >> $GITHUB_ENV || echo "VERSION=$(date +'%m.%d')" >> $GITHUB_ENV
- name: Clone source code
run: |
TAG_INFO="$(curl -gs -H 'Content-Type: application/json' \
-H "Authorization: Bearer ${{ secrets.TOKEN_KIDDIN9 }}" \
-X POST -d '{ "query": "query {repository(owner: \"openwrt\", name: \"openwrt\") {refs(refPrefix: \"refs/tags/\", first: 4, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {nodes {name target { ... on Tag {tagger {date}}}}}}}"}' https://api.github.com/graphql)"
TAG_DATE="$( echo ${TAG_INFO} | jq -r '.data.repository.refs.nodes[] | select(.name | startswith("v23")) | .target.tagger.date' | head -n 1)"
if [[ $(( ($(date +%s) - $(date -d "$TAG_DATE" +%s)) / 86400 )) -lt 30 ]]; then
REPO_BRANCH="$( echo ${TAG_INFO} | jq -r '.data.repository.refs.nodes[].name' | grep v23 | head -n 1)"
else
REPO_BRANCH="openwrt-24.10"
fi
#echo "CONFIG_VERSION_REPO=\"https://dl.openwrt.ai/releases/`echo $REPO_BRANCH | cut -d . -f 1,2 | sed -e 's/^v//'`\"">>devices/common/.config
echo "CONFIG_VERSION_REPO=\"https://dl.openwrt.ai/releases/24.10\"">>devices/common/.config
if [[ ! "${{ env.REPO_BRANCH }}" && "$REPO_URL" == "https://github.com/openwrt/openwrt" ]]; then
git clone $REPO_URL -b $REPO_BRANCH openwrt
elif [[ ! "${{ env.REPO_BRANCH }}" ]]; then
git clone $REPO_URL openwrt
else
REPO_BRANCH="${{env.REPO_BRANCH}}"
if [[ ${#REPO_BRANCH} -lt 10 ]]; then
git clone $REPO_URL -b ${REPO_BRANCH} openwrt
else
git clone $REPO_URL openwrt
cd openwrt
git checkout ${REPO_BRANCH}
fi
fi
- name: Free up disk space
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo mkdir -p -m 777 /mnt/openwrt/dl /mnt/openwrt/staging_dir /mnt/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 openwrt/build_dir
- name: Load custom configuration
run: |
function git_clone_path() {
trap 'rm -rf "$tmpdir"' EXIT
branch="$1" rurl="$2" mv="$3"
[[ "$mv" != "mv" ]] && shift 2 || shift 3
rootdir="$PWD"
tmpdir="$(mktemp -d)" || exit 1
if [ ${#branch} -lt 10 ]; then
git clone -b "$branch" --depth 1 --filter=blob:none --sparse "$rurl" "$tmpdir"
cd "$tmpdir"
else
git clone --filter=blob:none --sparse "$rurl" "$tmpdir"
cd "$tmpdir"
git checkout $branch
fi
if [ "$?" != 0 ]; then
echo "error on $rurl"
exit 1
fi
git sparse-checkout init --cone
git sparse-checkout set $@
[[ "$mv" != "mv" ]] && cp -rn ./* $rootdir/ || mv -n $@/* $rootdir/$@/
cd $rootdir
}
export -f git_clone_path
cp -rf devices/common/. openwrt/
cp -rf devices/${{matrix.target}}/. openwrt/
cp -rf devices openwrt/
cd openwrt
chmod +x devices/common/$DIY_SH
/bin/bash "devices/common/$DIY_SH"
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
if [ -f "devices/${{matrix.target}}/$DIY_SH" ]; then
chmod +x devices/${{matrix.target}}/$DIY_SH
echo "/bin/bash devices/${{matrix.target}}/$DIY_SH"
/bin/bash "devices/${{matrix.target}}/$DIY_SH"
fi
cp -Rf ./diy/* ./ || true
- name: Apply patches
run: |
cd openwrt
cp -rn devices/common/patches devices/${{matrix.target}}/
if [ -n "$(ls -A devices/${{matrix.target}}/*.bin.patch 2>/dev/null)" ]; then
git apply devices/${{matrix.target}}/patches/*.bin.patch
fi
find "devices/${{matrix.target}}/patches" -maxdepth 1 -type f -name '*.revert.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -R -B --merge -p1 --forward"
find "devices/${{matrix.target}}/patches" -maxdepth 1 -type f -name '*.patch' ! -name '*.revert.patch' ! -name '*.bin.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -B --merge -p1 --forward"
sed -i '$a \
CONFIG_CPU_FREQ_GOV_POWERSAVE=y \
CONFIG_CPU_FREQ_GOV_USERSPACE=y \
CONFIG_CPU_FREQ_GOV_ONDEMAND=y \
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y \
CONFIG_CRYPTO_CHACHA20_NEON=y \
CONFIG_CRYPTO_CHACHA20POLY1305=y \
CONFIG_FAT_DEFAULT_IOCHARSET="utf8" \
' `find target/linux -path "target/linux/*/config-*"`
- name: Defconfig
run: |
cd openwrt
make defconfig
if [[ ! "${{matrix.target}}" =~ (amlogic_*|armsr_armv8|bcm27xx_*|rockchip_armv8|sunxi_*|x86_*) ]]; then
sed -n '/# Wireless Drivers/,/# end of Wireless Drivers/p' .config | sed -e 's/=m/=n/' >>.config
sed -i "s/\(kmod-qca.*\)=m/\1=n/" .config
if [[ "${{matrix.target}}" == "rockchip_rk35xx" ]]; then
sed -n '/# Video Support/,/# end of Video Support/p' .config | sed -e 's/=m/=n/' >>.config
fi
make defconfig
fi
cat .config
- name: Cache
uses: stupidloud/cachewrtbuild@main
with:
ccache: 'true'
mixkey: ${{ matrix.target }}
clean: ${{ contains(github.event.action, 'nocache') }}
prefix: ${{ github.workspace }}/openwrt
- name: Check space usage
run: |
shopt -s extglob
cd openwrt
if [[ -f staging_dir/*${{ env.MTARGET }}*/bin ]]; then
rm -rf staging_dir/!(*${{ env.MTARGET }}*|host|hostpkg) build_dir/!(*${{ env.MTARGET }}*|host|hostpkg)
fi
df -hT
- name: SSH connection to Actions
uses: kiddin9/debugger-action@master
if: contains(github.event.action, 'ssh')
- name: Compile the firmware
id: compile
run: |
shopt -s extglob
cd openwrt
echo -e "$(($(nproc)+1)) thread compile"
make -j$(($(nproc)+1)) || make V=s &>build.log || (tail -50 build.log; curl -k --data chat_id="${{ env.TELEGRAM_CHAT_ID }}" --data "text=❌ OpenWrt ${{ env.VERSION }} ${{matrix.target}} 编译失败 😂" "https://api.telegram.org/bot${{ env.TELEGRAM_TOKEN }}/sendMessage";df -hT;exit 1)
sed -i "s/# CONFIG_IB is not set/CONFIG_IB=y/" .config
rm -rf staging_dir/toolchain-*/bin/*openwrt-linux-musl-lto-dump
rm -rf staging_dir/toolchain-*/initial
df -hT
- name: Organize files
id: organize
continue-on-error: true
run: |
shopt -s extglob
mkdir -p firmware/${{matrix.target}}
cp -rf openwrt/bin/targets/*/*/*{combined,sysupgrade}* ./firmware/${{matrix.target}}/ || true
cd openwrt/bin/targets/*/*/
cp $GITHUB_WORKSPACE/openwrt/.config ${{matrix.target}}.config || true
cp $GITHUB_WORKSPACE/openwrt/build_dir/target-*/linux-*/linux-*/.config ${{matrix.target}}_kernel.config || true
cd -
rename -v "s/openwrt-/${{ env.VERSION }}-openwrt-/" ./firmware/*/* || true
Emoji=("🎉" "🤞" "✨" "🎁" "🎈" "🎄" "🎨" "💋" "🍓" "🍕" "🍉" "💐" "🌴" "🚀" "🛸" "🗽" "⛅" "🌈" "🔥" "⛄" "🐶" "🏅" "🦄" "🐤")
echo "EMOJI=${Emoji[$[$RANDOM % ${#Emoji[@]}]]}" >> $GITHUB_ENV
if [ ${{matrix.target}} == "x86_64" ]; then
echo "DOCKERTAG=${{ secrets.DOCKER_ID }}/openwrt-nginx:latest" >> $GITHUB_ENV
echo "NOTICE=请分配不少于1G的存储容量" >> $GITHUB_ENV
fi
- name: Deploy imagebuilder to server
uses: easingthemes/ssh-deploy@main
continue-on-error: true
if: env.SSH_PRIVATE_KEY && ! contains(github.event.action, 'noser')
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-avzr"
SOURCE: openwrt/bin/targets
REMOTE_HOST: ${{ secrets.SERVER_HOST }}
REMOTE_PORT: ${{ secrets.SERVER_PORT }}
REMOTE_USER: root
TARGET: "/www/wwwroot/dl.openwrt.ai/releases/tmp/"
- name: Upload firmware for artifact
uses: actions/upload-artifact@main
if: env.UPLOAD_FIRMWARE_FOR_ARTIFACT == 'true'
with:
name: ${{ env.VERSION }}_${{matrix.target}}
path: |
openwrt/bin/targets/
- 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://dl.openwrt.ai/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@master
continue-on-error: true
if: env.REPO_TOKEN && env.UPLOAD_FIRMWARE_FOR_RELEASE == 'true'
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_KIDDIN9 }}
with:
files: "${{ env.FIRMWARE }}/*"
name: ${{ env.date2 }} ${{matrix.target}} ${{ env.EMOJI }}
tag_name: ${{ env.date }}_${{matrix.target}}
body_path: release.txt
- name: WeChat notification
continue-on-error: true
if: env.SCKEY
run: |
# [ steps.compile.outputs.status == 'success' ] && curl https://sctapi.ftqq.com/${{ secrets.SCKEY }}.send?text=🎉OpenWrt_${{ env.VERSION }}_${{matrix.target}}编译完成😋|| curl https://sctapi.ftqq.com/${{ secrets.SCKEY }}.send?text=❌OpenWrt_${{ env.VERSION }}_${{matrix.target}}编译失败😂
- name: Telegram notification
if: env.TELEGRAM_TOKEN && ! contains(github.event.action, 'notg')
continue-on-error: true
run: |
curl -k --data chat_id="${{ env.TELEGRAM_CHAT_ID }}" --data "text=🎉 OpenWrt ${{ env.VERSION }} ${{matrix.target}} 编译成功 😋 https://dl.openwrt.ai/firmware/${{matrix.target}}/ ${{ env.COWURL }} ${{ env.WETRANS }} 🚀" "https://api.telegram.org/bot${{ env.TELEGRAM_TOKEN }}/sendMessage"
- name: Delete workflow runs
uses: GitRML/delete-workflow-runs@main
continue-on-error: true
with:
token: ${{ secrets.TOKEN_KIDDIN9 }}
retain_days: 100
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.TOKEN_KIDDIN9 }}