-
Notifications
You must be signed in to change notification settings - Fork 3
252 lines (229 loc) · 8.74 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#
# Copyright (c) 2019-2023 cnbbx <https://cnbbx.com>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
name: build-openWrt
run-name: 我的OpenWrt云编译:${{ inputs.TITLE_SHOW }}
env:
REPO_URL: https://github.com/cnbbx/Openwrt-src.git
REPO_BRANCH: openwrt-23.05
BUILD_USER: ${{ github.actor }}
TZ: Asia/Shanghai
on:
repository_dispatch:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "开启tmate远程调试"
required: false
default: false
git_init_enabled:
description: "首次初始化GIT"
type: boolean
required: false
default: false
UPLOAD_BIN_DIR:
description: "保存编译后的全部文件"
type: boolean
default: true
UPLOAD_RELEASE:
description: "发布固件到Releases"
type: boolean
default: true
YOUKU_BUILD:
description: "开启youku_yk-l2编译"
type: boolean
default: true
NEWIFI_BUILD:
description: "开启d-team_newifi-d2编译"
type: boolean
default: true
X86_BUILD:
description: "开启x86_64编译"
type: boolean
default: true
TITLE_SHOW:
type: string
description: 任务流程标题
#schedule:
# - cron: '5 22 * * 0'
jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- FIRMWARE_NAME: youku_yk-l2
FIRMWARE_BUILD: ${{ inputs.YOUKU_BUILD }}
- FIRMWARE_NAME: d-team_newifi-d2
FIRMWARE_BUILD: ${{ inputs.NEWIFI_BUILD }}
- FIRMWARE_NAME: x86_64
FIRMWARE_BUILD: ${{ inputs.X86_BUILD }}
steps:
- name: checkout
uses: actions/checkout@main
- name: 检查空间使用情况
run: |
echo "警告⚠"
echo -e "-------------- ------------CPU信息------------------------------------------\n"
echo "CPU物理数量:$(cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l)"
echo -e "CPU核心及版本信息:$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \n"
echo "-------------------------------内存信息-------------------------------------------"
echo "已安装内存详细信息:"
sudo lshw -short -C memory | grep GiB
echo -e "\n"
echo "-----------------------------硬盘信息---------------------------------------------"
echo -e "硬盘数量:$(ls /dev/sd* | grep -v [1-9] | wc -l) \n"
echo "硬盘详情:"
df -Th
sudo mkdir -p /workdir
- name: 初始化系统环境
if: matrix.FIRMWARE_BUILD == true
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 libfuse-dev 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 git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo \
libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint \
device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
- name: 克隆软路由源代码
if: matrix.FIRMWARE_BUILD == true && inputs.git_init_enabled
working-directory: /workdir
run: |
git clone --depth=1 $REPO_URL -b $REPO_BRANCH openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
- name: Cache OpenWrt Source
id: cache
uses: actions/cache@v3
with:
working-directory: /workdir
path: /workdir/openwrt
key: openwrt-
restore-keys: openwrt-
- name: 更新Git仓库到最新
if: matrix.FIRMWARE_BUILD == true
run: |
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt || true
cd openwrt
git fetch origin $REPO_BRANCH
git reset --hard FETCH_HEAD
git pull
- name: 修改版本补丁
if: matrix.FIRMWARE_BUILD == truee && inputs.git_init_enabled
run: |
tree
[ -e feeds.conf.default ] && mv feeds.conf.default openwrt/feeds.conf.default
[ -e my-changes.patch ] && mv my-changes.patch openwrt/my-changes.patch
cd openwrt
[ -e my-changes.patch ] && git apply my-changes.patch
- name: 更新和安装自定义项目的清单
if: matrix.FIRMWARE_BUILD == true
run: cd openwrt && ./scripts/feeds update -a && ./scripts/feeds install -a
- name: 加载自定义固件配置
if: matrix.FIRMWARE_BUILD == true && !cancelled()
run: |
[ -e files ] && mv files openwrt/files
[ -e ${{ matrix.FIRMWARE_NAME }}.config ] && mv ${{ matrix.FIRMWARE_NAME }}.config openwrt/.config
[ -e ${{ matrix.FIRMWARE_NAME }}.sh ] && mv ${{ matrix.FIRMWARE_NAME }}.sh openwrt/diy.sh
cd openwrt/ && chmod +x diy.sh && ./diy.sh
- name: 启动tmate远程调试
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: 下载自定义固件插件
if: matrix.FIRMWARE_BUILD == true && !cancelled()
id: package
run: |
cd openwrt
make defconfig
make download -j$(nproc)
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
- name: 编译固件
if: matrix.FIRMWARE_BUILD == true && !cancelled()
id: compile
run: |
cd openwrt && mkdir -p firmware
echo -e "$(nproc) thread compile"
make -j$(nproc) || make -j1 V=s
cd bin/targets/*/*
mv *.buildinfo *.manifest *.bin $GITHUB_WORKSPACE/openwrt/firmware || true
mv *.vmdk $GITHUB_WORKSPACE/openwrt/firmware || true
mv *.vhdx $GITHUB_WORKSPACE/openwrt/firmware || true
- name: 保存编译后的固件文件
if: matrix.FIRMWARE_BUILD == true && inputs.UPLOAD_BIN_DIR == true && !cancelled()
uses: actions/upload-artifact@main
with:
name: OpenWrt_Firmware
path: openwrt/firmware
- name: 保存编译后的插件文件
if: matrix.FIRMWARE_BUILD == true && inputs.UPLOAD_BIN_DIR == true&& !cancelled()
uses: actions/upload-artifact@main
with:
name: OpenWrt_Packages
path: openwrt/bin
deploy:
needs: build
runs-on: ubuntu-20.04
steps:
- name: 调取编译后的固件文件
uses: actions/download-artifact@main
with:
name: OpenWrt_Firmware
path: openwrt/firmware
- name: 调取编译后的插件文件
uses: actions/download-artifact@main
with:
name: OpenWrt_Packages
path: openwrt/bin
- name: 优化需要发布的固件
id: organize
if: (!cancelled())
run: |
cd openwrt
tar -zcvf firmware/Packages.tar.gz ./bin/
- name: 生成 release tag
id: tag
if: (inputs.UPLOAD_RELEASE == true) && !cancelled()
run: |
echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT
touch release.txt
cat >> release.txt <<EOF
1、本固件为自动编译
2、发行版中只提供完整的固件
3、源码:${{ env.REPO_URL }}
-- Build by ${{ env.BUILD_USER }} @ with Github Action on $(date +"%Y.%m.%d-%H%M")
🚀 Auto build | 自动编译
EOF
- name: 上传固件到release
uses: softprops/action-gh-release@v1
if: (inputs.UPLOAD_RELEASE == true) && !cancelled()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.release_tag }}
body_path: release.txt
files: openwrt/firmware/*
- name: 移除老的 workflow runs
uses: zhoujinshi/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 3
- name: 移除老的 Releases
uses: dev-drprasad/delete-older-releases@master
if: (inputs.UPLOAD_RELEASE == true || inputs.UPLOAD_RELEASE == '') && !cancelled()
with:
keep_latest: 3
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}