forked from kiddin9/Kwrt
-
Notifications
You must be signed in to change notification settings - Fork 0
233 lines (209 loc) · 9.98 KB
/
build-openwrt.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
#=================================================
# https://github.com/P3TERX/Actions-OpenWrt
# Description: Build OpenWrt using GitHub Actions
# Lisence: MIT
# Author: P3TERX
# Blog: https://p3terx.com
#=================================================
name: Build OpenWrt
on:
push:
branches:
- master
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_TO : ${{ secrets.TELEGRAM_TO }}
TZ: Asia/Shanghai
jobs:
build:
if: github.event.repository.owner.id == github.event.sender.id
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Load Settings.ini
run: |
source "${GITHUB_WORKSPACE}/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}"
- name: Initialization environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo swapoff /swapfile
sudo rm -rf /swapfile /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 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
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
sudo timedatectl set-timezone "$TZ"
curl -fsSL https://raw.githubusercontent.com/P3TERX/dotfiles/master/.bashrc >> ~/.bashrc
- 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
mv feeds.conf openwrt/
- name: Free up disk space
if: env.FREE_UP_DISK == 'true'
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo mkdir -p -m 777 /mnt/openwrt/build_dir/hostpkg /mnt/openwrt/build_dir/host openwrt/build_dir /mnt/openwrt/dl /mnt/openwrt/staging_dir
ln -s /mnt/openwrt/build_dir/hostpkg openwrt/build_dir/hostpkg
ln -s /mnt/openwrt/build_dir/host openwrt/build_dir/host
ln -s /mnt/openwrt/dl openwrt/dl
ln -s /mnt/openwrt/staging_dir openwrt/staging_dir
- name: Update feeds
run: cd openwrt && ./scripts/feeds update custom -a
- name: Load custom configuration
run: |
cp -Rf * openwrt/ || true
cd openwrt
chmod +x $DIY_SH
./$DIY_SH >/dev/null
[ -e $CONFIG_FILE ] && mv $CONFIG_FILE .config
[ ${{ github.event.repository.owner.id }} != '48883331' ] && {
sed -i "s/=m/=n/g" .config
}
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/')
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: env.SSH_ACTIONS == 'true'
- 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@master
if: env.UPLOAD_BIN_DIR_FOR_ARTIFACT == 'true'
with:
name: OpenWrt_bin
path: openwrt/bin
- name: Organize files
id: organize
run: |
mkdir firmware && find openwrt/bin/*/*/*/ -maxdepth 1 \
-name "*combined*" \
-or -name "sha256sums" \
-or -name "*adbyby*" \
-or -name "*passwall*" \
-or -name "*kodexplorer*" \
-or -name "*chinadns*" \
-or -name "*cifs-mount*" \
-or -name "*music-remote-center*" -or -name "*forked-daapd*" \
-or -name "*airplay2*" \
-or -name "*openclash*" \
-or -name "*softethervpn*" \
-or -name "*syncdial*" \
-or -name "*usb-printer*" \
-or -name "*verysync*" \
-or -name "*vsftpd*" \
-or -name "*xlnetacc*" \
-or -name "*zerotier*" \
| xargs -i mv -f {} ./firmware/
cp openwrt/.config ./firmware/config.txt
cd firmware
rename -v "s/^openwrt/${{ env.date3 }}-openwrt/" *combined*
zip -r luci-app-adbyby-plus.zip *adbyby* || true
zip -r luci-app-php-kodexplorer *kodexplorer* || true
zip -r luci-app-passwall.zip *passwall* *chinadns* *haproxy* || true
zip -r luci-app-baidupcs-web.zip *baidupcs* || true
zip -r luci-app-cifs-mount.zip *cifs-mount* || true
zip -r luci-app-music-remote-center.zip *music-remote-center* *forked-daapd* || true
zip -r luci-app-airplay2.zip *airplay2* || true
zip -r luci-app-openclash.zip *openclash* || true
zip -r luci-app-softethervpn.zip *softethervpn* || true
zip -r luci-app-syncdial.zip *syncdial* || true
zip -r luci-app-usb-printer.zip *usb-printer* || true
zip -r luci-app-verysync.zip *verysync* || true
zip -r luci-app-vsftpd.zip *vsftpd* || true
zip -r luci-app-xlnetacc.zip *xlnetacc* || true
zip -r luci-app-zerotier.zip *zerotier* || true
rm -Rf *.ipk
echo "::set-env name=FIRMWARE::$PWD"
Emoji=("🎉" "🤞" "✨" "🎁" "🎈" "🎄" "🎨" "💋" "🍓" "🍕" "🍉" "💐" "🌴" "🚀" "🛸" "🗽" "⛅" "🌈" "🔥" "⛄" "🐶" "🏅" "🦄" "🐤")
RANDOM=$$$(date +%s)
rand=$[$RANDOM % ${#Emoji[@]}]
echo "::set-env name=EMOJI::${Emoji[$rand]}"
- 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: Create release
id: create_release
uses: actions/create-release@master
continue-on-error: true
if: env.REPO_TOKEN && env.UPLOAD_FIRMWARE_FOR_RELEASE == 'true'
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 }} 🚀
请分配不低于1G 的内存和存储空间💾.
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'
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@master
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 && !cancelled()
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 && !cancelled()
run: |
[ ${{ env.status }} == 'success' ] && 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" || 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"