generated from P3TERX/Actions-OpenWrt
-
Notifications
You must be signed in to change notification settings - Fork 1
254 lines (220 loc) · 8.73 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
253
254
#
# Copyright (c) 2019-2020 P3TERX <https://p3terx.com>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
# https://github.com/P3TERX/Actions-OpenWrt
# Description: Build OpenWrt using GitHub Actions
#
name: Build Lede
on:
repository_dispatch:
workflow_dispatch:
inputs:
ssh:
description: 'SSH connection to Actions'
required: false
default: 'false'
schedule:
- cron: 0 4 * * 5
env:
REPO_URL: https://github.com/coolsnowwolf/lede
REPO_BRANCH: master
FEEDS_CONF: feeds.conf.default
CONFIG_FILE: .config
DIY_P1_SH: diy-part1.sh
DIY_P2_SH: diy-part2.sh
UPLOAD_BIN_DIR: true
UPLOAD_FIRMWARE: true
UPLOAD_RELEASE: true
UPLOAD_COWTRANSFER: false
UPLOAD_WETRANSFER: false
TZ: Asia/Shanghai
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
REPO_BRANCH:
- master
ARCHITECTURE:
- armv8
os:
- ubuntu-24.04
steps:
- name: 准备完成
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 -e "------------------------------- 内存信息 -------------------------------\n"
echo "已安装内存详细信息: "
sudo lshw -short -C memory | grep GiB
echo -e "\n"
echo -e "------------------------------- 磁盘信息 -------------------------------\n"
echo -e "磁盘数量: $(ls /dev/sd* | grep -v [1-9] | wc -l) \n"
echo "------------------------------- 磁盘详情 -------------------------------\n"
df -Th
echo -e "------------------------------- 系统信息 -------------------------------\n"
cat /etc/os-release
uname -a
echo -e "------------------------------- 网络信息 -------------------------------\n"
ip addr show
echo -e "------------------------------- 网络连接信息 -------------------------------\n"
netstat -ntlp
echo -e "------------------------------- 进程信息 -------------------------------\n"
ps -ef | grep -v grep
echo -e "------------------------------- 系统负载信息 -------------------------------\n"
uptime
echo -e "------------------------------- 系统日志信息 -------------------------------\n"
cat /var/log/syslog
- name: 初始化编译环境
env:
DEBIAN_FRONTEND: noninteractive
run: |
echo "------------------------------- 更新并安装依赖 -------------------------------"
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /etc/mysql /usr/local/lib/android /opt/ghc
sudo -E apt-get -y update
sudo -E apt-get upgrade -qq -y
#sudo -E apt-get -qq -y install dialog
echo "------------------------------- 安装工具 --------------------------------------"
cat $GITHUB_WORKSPACE/depends/${{ matrix.os }}
sudo -E apt-get -qq -y install $(cat $GITHUB_WORKSPACE/depends/${{ matrix.os }})
echo "------------------------------- 添加Python2符号链接 --------------------------------------"
sudo -E ln -s /usr/bin/python2.7 /usr/bin/python2
echo "------------------------------- 清理Docker镜像和软件 -------------------------------"
docker rmi `docker images -q`
docker image prune -a -f
sudo -E apt-get -qq -y purge ghc* zulu* llvm* firefox google* dotnet* openjdk* mysql* php* mongodb* dotnet* moby* snapd* || true
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
echo "------------------------------- 设置工作目录及时区 -------------------------------"
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
echo "------------------------------- 清理后磁盘详情 -------------------------------\n"
df -Th
- name: 克隆源码
working-directory: /workdir
run: |
df -hT $PWD
git clone $REPO_URL -b ${{ matrix.REPO_BRANCH }} openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
- name: 缓存构建动作
uses: klever1988/cachewrtbuild@main
with:
ccache: 'true'
mixkey: ${{ matrix.os }}-${{ matrix.ARCHITECTURE }}-${{ matrix.REPO_BRANCH }}
prefix: ${{ github.workspace }}/openwrt
- name: 加载自定义 feeds
env:
FEEDS_CONF_PATH: ${{ matrix.ARCHITECTURE }}/${{ env.FEEDS_CONF }}
run: |
[ -e $FEEDS_CONF_PATH ] && mv $FEEDS_CONF_PATH openwrt/$FEEDS_CONF
chmod +x $DIY_P1_SH
cd openwrt
$GITHUB_WORKSPACE/$DIY_P1_SH
- name: 更新 feeds
run: cd openwrt && ./scripts/feeds update -a
- name: 安装 feeds
run: cd openwrt && ./scripts/feeds install -a
- name: 加载自定义配置
env:
CONFIG_FILE_PATH: ${{ matrix.ARCHITECTURE }}/config
run: |
[ -e files ] && mv files openwrt/files
[ -e $CONFIG_FILE_PATH ] && mv $CONFIG_FILE_PATH openwrt/$CONFIG_FILE
chmod +x $DIY_P2_SH
cd openwrt
$GITHUB_WORKSPACE/$DIY_P2_SH
- name: SSH 连接到 Actions
uses: P3TERX/[email protected]
if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh')
env:
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
- name: 下载软件包
id: package
run: |
cd openwrt
yes ""|make oldconfig
make download -j8
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
- name: 编译固件
id: compile
run: |
cd openwrt
echo -e "$(nproc) thread compile"
make -j$(nproc) || make -j1 V=s
echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV
# echo "::set-output name=status::success"
echo "status=success" >> $GITHUB_OUTPUT
- name: 检查磁盘空间
if: (!cancelled())
run: df -hT
- name: 上传 bin 文件夹
uses: actions/upload-artifact@main
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true'
with:
name: OpenWrt_bin${{ env.FILE_DATE }}
path: openwrt/bin
- name: 整理固件文件
id: organize
if: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
run: |
cd openwrt/bin/targets/*/*
ls -la
rm -rf packages
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
# echo "::set-output name=status::success"
echo "status=success" >> $GITHUB_OUTPUT
ls $PWD/*
- name: 上传固件目录
uses: actions/upload-artifact@main
if: steps.organize.outputs.status == 'success' && !cancelled()
with:
name: OpenWrt_firmware${{ env.FILE_DATE }}
path: ${{ env.FIRMWARE }}
- name: 生成发布标签
id: tag
if: steps.compile.outputs.status == 'success' && env.UPLOAD_RELEASE == 'true' && !cancelled()
run: |
# echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H.%M")"
echo "release_tag=$(date +"%Y.%m.%d-%H.%M")" >> $GITHUB_OUTPUT
touch release.txt
echo "
💻 架构: ${{ matrix.ARCHITECTURE }}
📂 源码: ${{ env.REPO_URL }}
🌳 分支: ${{ matrix.REPO_BRANCH }}
⏱️ 编译时间: $(date +"%Y年%m月%d日%H时%M分")
🌐 管理地址: 192.168.100.1
👤 用户名: root
🔒 密码: password " >> release.txt
# echo "::set-output name=status::success"
echo "status=success" >> $GITHUB_OUTPUT
- name: 自动发布固件到 Releases
uses: softprops/action-gh-release@v2
if: steps.tag.outputs.status == 'success' && env.UPLOAD_RELEASE == 'true' && !cancelled()
with:
tag_name: ${{ steps.tag.outputs.release_tag }}
body_path: release.txt
files: ${{ env.FIRMWARE }}/*
token: ${{ env.GITHUB_TOKE }}
- name: 删除运行记录
uses: GitRML/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 1
token: ${{ env.GITHUB_TOKEN }}
- name: 删除自动发布的旧固件
uses: dev-drprasad/[email protected]
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
with:
keep_latest: 4
delete_tags: true