forked from kiddin9/Kwrt
-
Notifications
You must be signed in to change notification settings - Fork 3
273 lines (244 loc) · 11.5 KB
/
dispatcher-actions.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
#=================================================
# https://github.com/P3TERX/Actions-OpenWrt
# Description: Build OpenWrt using GitHub Actions
# Lisence: MIT
# Author: P3TERX
# Blog: https://p3terx.com
#=================================================
name: Openwrt-AutoBuild
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 }}
TZ: Asia/Shanghai
jobs:
build:
if: github.event.repository.owner.id == github.event.sender.id
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
- name: Load Settings.ini
run: |
source "${GITHUB_WORKSPACE}/${{matrix.target}}/settings.ini"
echo "::set-env name=REPO_URL::${REPO_URL}"
echo "::set-env name=REPO_BRANCH::${REPO_BRANCH}"
echo "::set-env name=CONFIG_FILE::${CONFIG_FILE}"
echo "::set-env name=DIY_SH::${DIY_SH}"
echo "::set-env name=FREE_UP_DISK::${FREE_UP_DISK}"
echo "::set-env name=SSH_ACTIONS::${SSH_ACTIONS}"
echo "::set-env name=UPLOAD_BIN_DIR_FOR_ARTIFACT::${UPLOAD_BIN_DIR_FOR_ARTIFACT}"
echo "::set-env name=UPLOAD_FIRMWARE_FOR_ARTIFACT::${UPLOAD_FIRMWARE_FOR_ARTIFACT}"
echo "::set-env name=UPLOAD_FIRMWARE_FOR_RELEASE::${UPLOAD_FIRMWARE_FOR_RELEASE}"
echo "::set-env name=UPLOAD_FIRMWARE_TO_COWTRANSFER::${UPLOAD_FIRMWARE_TO_COWTRANSFER}"
echo "::set-env name=UPLOAD_FIRMWARE_TO_WETRANSFER::${UPLOAD_FIRMWARE_TO_WETRANSFER}"
- name: Initialization 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 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 swig
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 "::set-env name=date::$(date +'%m/%d_%Y_%H/%M')"
echo "::set-env name=date2::$(date +'%m/%d %Y')"
echo "::set-env name=date3::$(date +'%m.%d')"
- name: Clone source code
run: |
git clone --depth 1 $REPO_URL -b $REPO_BRANCH openwrt
if [ -f "common/feeds.conf" ]; then
(
mv common/feeds.conf openwrt/
)
fi
if [ -f "${{matrix.target}}/feeds.conf" ]; then
(
mv ${{matrix.target}}/feeds.conf openwrt/
)
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
ln -s /mnt/openwrt/dl openwrt/
ln -s /mnt/openwrt/staging_dir openwrt/
- name: Load custom configuration
run: |
cp -Rf `find ./ -maxdepth 1 -type d ! -path './openwrt' ! -path './'` openwrt
cd openwrt
echo "Apply files..."
if [ -n "$(ls -A "common/files" 2>/dev/null)" ]; then
cp -rf common/files files
fi
if [ -n "$(ls -A "${{matrix.target}}/files" 2>/dev/null)" ]; then
cp -rf ${{matrix.target}}/files/* files/
fi
if [ -f "common/$DIY_SH" ]; then
(
chmod +x common/$DIY_SH
/bin/bash "common/$DIY_SH"
)
fi
if [ -f "${{matrix.target}}/$DIY_SH" ]; then
(
chmod +x ${{matrix.target}}/$DIY_SH
/bin/bash "${{matrix.target}}/$DIY_SH"
)
fi
mv ${{matrix.target}}/$CONFIG_FILE .config
if [ -f "common/default-settings" ]; then
cp -f common/default-settings package/*/*/default-settings/files/zzz-default-settings
fi
if [ -f "${{matrix.target}}/default-settings" ]; then
cat ${{matrix.target}}/default-settings >> package/*/*/default-settings/files/zzz-default-settings
fi
if [ -n "$(ls -A "common/diy" 2>/dev/null)" ]; then
cp -Rf common/diy/* ./
fi
if [ -n "$(ls -A "${{matrix.target}}/diy" 2>/dev/null)" ]; then
cp -Rf ${{matrix.target}}/diy/* ./
fi
if [ -n "$(ls -A "common/patches" 2>/dev/null)" ]; then
(
find "common/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p0 --forward" || true
)
fi
if [ -n "$(ls -A "${{matrix.target}}/patches" 2>/dev/null)" ]; then
(
find "${{matrix.target}}/patches" -type f -name '*.patch' -print0 | sort -z | xargs -I % -t -0 -n 1 sh -c "cat '%' | patch -d './' -p0 --forward" || true
)
fi
make defconfig
[ $(grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/') == generic ] && DEVICE_NAME=$(grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/CONFIG_TARGET_(.*)_DEVICE_.*=y/\1/') || DEVICE_NAME=$(grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/')
DEVICE_NAME=`echo ${DEVICE_NAME/xiaomi_redmi-router/redmi}`
echo "::set-env name=DEVICE_NAME::$DEVICE_NAME"
- 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/zzz-default-settings
sed -i '$i uci set network.wan.password=${{ env.PPPOE_PASSWD }}' openwrt/package/*/*/default-settings/files/zzz-default-settings
sed -i '$i uci commit network' openwrt/package/*/*/default-settings/files/zzz-default-settings
- 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 download -j8
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
- name: Compile the firmware
run: |
cd openwrt
echo -e "$(($(nproc)+1)) thread compile"
make -j$(($(nproc)+1)) || make -j1 V=s
echo "::set-env name=status::success"
- 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/*/*/*/ -maxdepth 1 \
-name "*combined*" \
-or -name "*sysupgrade.bin" \
-or -name "sha256sums" \
| xargs -i mv -f {} ./firmware/
cp openwrt/.config ./firmware/${{matrix.target}}.config
cd firmware
mv sha256sums ${{matrix.target}}_sha256sums
rename -v "s/^openwrt/${{ env.date3 }}-openwrt/" *combined*
rename -v "s/xiaomi_redmi-router/redmi/" *bin
rename -v "s/^openwrt/${{ env.date3 }}-openwrt/" *bin
echo "::set-env name=FIRMWARE::$PWD"
Emoji=("🎉" "🤞" "✨" "🎁" "🎈" "🎄" "🎨" "💋" "🍓" "🍕" "🍉" "💐" "🌴" "🚀" "🛸" "🗽" "⛅" "🌈" "🔥" "⛄" "🐶" "🏅" "🦄" "🐤")
RANDOM=$$$(date +%s)
rand=$[$RANDOM % ${#Emoji[@]}]
echo "::set-env name=EMOJI::${Emoji[$rand]}"
if [ ${{matrix.target}} == "k2p" ]; then
echo "::set-env name=NOTICE::刷机时breed里的闪存布局请选择斐讯而非默认的公版"
elif [ ${{matrix.target}} == "x86_64" ]; then
echo "::set-env name=NOTICE::请分配不少于800M的存储容量"
else
echo "::set-env name=NOTICE::"
fi
- 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 "::set-env name=COWURL::$cowurl"
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 "::set-env name=WETRANS::$wetrans"
echo "Download Link: ${{ env.EMOJI }} $wetrans ${{ env.EMOJI }} 🚀"
- name: Create release
id: create_release
uses: actions/create-release@main
continue-on-error: true
if: env.REPO_TOKEN && env.UPLOAD_FIRMWARE_FOR_RELEASE == 'true' && ! contains(github.event.action, 'noup')
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
with:
tag_name: ${{ env.date }}_${{ env.DEVICE_NAME }}
release_name: ${{ env.date2 }} ${{ env.DEVICE_NAME }} ${{ env.EMOJI }}
body: |
墙内加速下载🔥:
奶牛快传: ${{ env.COWURL }} 🚀
WeTransfer: ${{ env.WETRANS }} ${{ env.EMOJI }}
${{ env.NOTICE }}
draft: false
prerelease: false
- name: Upload firmware for release
uses: csexton/release-asset-action@master
continue-on-error: true
if: env.REPO_TOKEN && env.UPLOAD_FIRMWARE_FOR_RELEASE == 'true' && ! contains(github.event.action, 'noup')
with:
pattern: "${{ env.FIRMWARE }}/*"
github-token: ${{ secrets.REPO_TOKEN }}
release-url: ${{ steps.create_release.outputs.upload_url }}
- 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 }} ${{ env.DEVICE_NAME }}
path: ${{ env.FIRMWARE }}
- name: WeChat notification
if: env.SCKEY
run: |
[ ${{ env.status }} == 'success' ] && curl https://sc.ftqq.com/${{ secrets.SCKEY }}.send?text=🎉OpenWrt_${{ env.date3 }}_${{ env.DEVICE_NAME }}编译完成😋|| curl https://sc.ftqq.com/${{ secrets.SCKEY }}.send?text=❌OpenWrt_${{ env.date3 }}_${{ env.DEVICE_NAME }}编译失败😂
- name: Telegram notification
if: env.TELEGRAM_TOKEN && ! contains(github.event.action, 'notg')
continue-on-error: true
run: |
[ ${{ env.status }} == 'success' ] && curl -k --data chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" --data "text=🎉 OpenWrt ${{ env.date3 }} ${{ env.DEVICE_NAME }} 编译成功 😋 ${{ 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 }} ${{ env.DEVICE_NAME }} 编译失败 😂" "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage"