forked from sbwml/r4s_build_script
-
Notifications
You must be signed in to change notification settings - Fork 0
237 lines (217 loc) · 10.2 KB
/
build-release.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
name: Build releases
on:
workflow_dispatch:
inputs:
device:
description: 'Select the build device(选择构建设备)'
required: true
default: 'x86_64'
type: choice
options:
- 'armv8'
- 'nanopi-r4s'
- 'nanopi-r5s'
- 'netgear_r8500'
- 'x86_64'
version:
description: 'Select the build version(选择编译版本)'
required: true
default: 'release'
type: choice
options:
- 'release'
- 'snapshot-24.10'
ccache:
description: 'Enable ccache (Use Cache to speed up next build)(启用缓存)'
type: boolean
default: false
lan_addr:
description: 'Setting default LAN address(设置LAN IP)'
required: true
default: '10.0.0.1'
type: string
build_options:
description: 'Build options (separate multiple options with spaces)(编译额外选项)'
required: false
default: 'BUILD_FAST=y ENABLE_BPF=y ENABLE_LTO=y ENABLE_LRNG=y ENABLE_MOLD=y KERNEL_CLANG_LTO=y'
type: string
jobs:
build:
name: Build ${{ github.event.inputs.device }}
runs-on: ubuntu-24.04
defaults:
run:
shell: bash
steps:
- name: Checkout
continue-on-error: true
uses: actions/checkout@main
with:
path: r4s_build_script
- name: Setup variables (校准编译环境)
run: |
sudo timedatectl set-timezone 'Asia/Shanghai'
git config --global user.name 'actions'
git config --global user.email '[email protected]'
echo build_dir="/builder" >> "$GITHUB_ENV"
[ "${{ github.event.inputs.version }}" = release ] && echo build_version="rc2" >> "$GITHUB_ENV" || echo build_version="dev" >> "$GITHUB_ENV"
- name: Show system (系统信息)
run: |
echo -e "\n\e[1;32mCPU:\e[0m"
echo "$(grep 'model name' /proc/cpuinfo | head -1 | awk -F ': ' '{print $2}') ($(grep 'cpu MHz' /proc/cpuinfo | head -1 | awk -F ': ' '{print $2}')MHz) x $(grep processor /proc/cpuinfo | wc -l)"
echo -e "\n\e[1;32mMemory:\e[0m"
free -h
echo -e "\n\e[1;32mStorage:\e[0m"
df -Th / /mnt
echo -e "\n\e[1;32mSystem:\e[0m"
lsb_release -a
echo -e "\n\e[1;32mKernel:\e[0m"
uname -a
echo
- name: Install Caddy Server (安装Caddy服务器)
run: |
sudo curl -sL -o /usr/bin/caddy https://github.com/sbwml/r4s_build_script/releases/download/caddy/caddy
sudo chmod 755 /usr/bin/caddy
echo ":8080 {" > caddyfile
echo " root * $(pwd)/r4s_build_script" >> caddyfile
echo " file_server browse" >> caddyfile
echo "}" >> caddyfile
sudo /usr/bin/caddy start --config caddyfile --adapter caddyfile
- name: Free disk space (整理磁盘)
uses: sbwml/actions@free-disk
with:
build-mount-path: /builder
- name: Build System Setup (构建编译环境)
uses: sbwml/actions@openwrt-build-setup
- name: Install LLVM (安装LLVM)
uses: sbwml/actions@install-llvm
- name: Restore Cached (拉取编译缓存)
if: ${{ github.event.inputs.ccache == 'true' && github.event.inputs.device != 'armv8' && github.event.inputs.device != 'nanopi-r4s' }}
uses: actions/cache/restore@v4
with:
path: /builder/.ccache
key: openwrt-24.10-${{ github.event.inputs.device }}-ccache
- name: Restore Cached (releases) (写入编译缓存)
if: ${{ github.event.inputs.ccache == 'true' && github.event.inputs.device == 'armv8' || github.event.inputs.device == 'nanopi-r4s' }}
continue-on-error: true
working-directory: /builder
run: |
curl -s https://api.github.com/repos/${{ github.repository }}/releases | grep 'browser_download_url' | grep ccache | grep ${{ github.event.inputs.device }} | awk -F '"' '{print $4}' | grep -v '^$' | xargs -n 1 wget -q
cat ${{ github.event.inputs.device }}.tar.* | tar -xf - || true
rm -rf ${{ github.event.inputs.device }}.tar.* || true
[ -d .ccache ] && cache_size=$(du -sb .ccache | awk '{print $1}') || cache_size=0
cache_size_mb=$(echo "scale=0; ${cache_size} / (1024 * 1024)" | bc)
echo "Cache Size: ~${cache_size_mb} MB (${cache_size} B)"
echo "Cache restored successfully"
echo "Cache restored from key: ${{ github.event.inputs.device }}"
- name: Compile OpenWrt (开始编译Openwrt)
working-directory: /builder
id: compile
continue-on-error: true
run: |
export ${{ github.event.inputs.build_options }} LAN=${{ github.event.inputs.lan_addr }} USE_GCC15=y
[ ${{ github.event.inputs.ccache }} = 'true' ] && export ENABLE_CCACHE=y
bash <(curl -sS http://127.0.0.1:8080/build.sh) ${{ env.build_version }} ${{ github.event.inputs.device }}
cd openwrt
if [ "${{ github.event.inputs.version }}" = release ]; then
tags=OpenWrt-$(git describe --abbrev=0 --tags)
else
tags=snapshot-24.10-$(git log -n 1 --date=format:"%Y%m%d" --format="%cd")-$(git log --pretty=format:"%h" -1)
fi
echo "latest_release=$tags" >>$GITHUB_ENV
- name: Extensive logs after a failed compilation (输出构建失败日志信息)
working-directory: /builder
if: steps.compile.outcome == 'failure'
run: |
cd openwrt
make V=s
- name: Delete Cached (整理编译缓存)
if: ${{ github.event.inputs.ccache == 'true' && github.event.inputs.device != 'armv8' && github.event.inputs.device != 'nanopi-r4s' }}
continue-on-error: true
working-directory: /builder
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
gh cache delete openwrt-24.10-${{ github.event.inputs.device }}-ccache || true
- name: Save Cached (选取编译缓存)
if: ${{ github.event.inputs.ccache == 'true' && github.event.inputs.device != 'armv8' && github.event.inputs.device != 'nanopi-r4s' }}
continue-on-error: true
uses: actions/cache/save@v4
with:
path: /builder/.ccache
key: openwrt-24.10-${{ github.event.inputs.device }}-ccache
- name: Create ccache tar files (打包编译缓存)
if: ${{ github.event.inputs.ccache == 'true' && github.event.inputs.device == 'armv8' || github.event.inputs.device == 'nanopi-r4s' }}
continue-on-error: true
working-directory: /builder
run: |
mkdir -p ccache
tar cf - .ccache | split -d -b 1800m - ccache/${{ github.event.inputs.device }}.tar.
- name: Upload Cached (releases - ccache) (上传编译缓存)
if: ${{ github.event.inputs.ccache == 'true' && github.event.inputs.device == 'armv8' || github.event.inputs.device == 'nanopi-r4s' }}
continue-on-error: true
uses: ncipollo/[email protected]
with:
name: ccache
allowUpdates: true
tag: ccache
commit: master
replacesArtifacts: true
prerelease: true
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: |
${{ env.build_dir }}/ccache/*
- name: Prepare Firmware Files (整理固件)
working-directory: /builder
run: |
mkdir -p rom info
if [ "${{ github.event.inputs.device }}" = "nanopi-r4s" ]; then
cp -a openwrt/bin/targets/rockchip/*/*.img.gz rom/
cp -a openwrt/bin/targets/rockchip/*/*-r4s.manifest info/manifest.txt
cp -a openwrt/bin/targets/rockchip/*/config.buildinfo info/config.buildinfo
cd rom && sha256sum *gz > ../info/sha256sums.txt
elif [ "${{ github.event.inputs.device }}" = "nanopi-r5s" ]; then
cp -a openwrt/bin/targets/rockchip/*/*.img.gz rom/
cp -a openwrt/bin/targets/rockchip/*/*.manifest info/manifest.txt
cp -a openwrt/bin/targets/rockchip/*/config.buildinfo info/config.buildinfo
cd rom && sha256sum *gz > ../info/sha256sums.txt
elif [ "${{ github.event.inputs.device }}" = "x86_64" ]; then
cp -a openwrt/bin/targets/x86/*/*-ext4-combined-efi.img.gz rom/
cp -a openwrt/bin/targets/x86/*/*-squashfs-combined-efi.img.gz rom/
cp -a openwrt/bin/targets/x86/*/*-generic-rootfs.tar.gz rom/
cp -a openwrt/bin/targets/x86/*/*-x86-64-generic.manifest info/manifest.txt
cp -a openwrt/bin/targets/x86/*/config.buildinfo info/config.buildinfo
cd rom && sha256sum *gz > ../info/sha256sums.txt
elif [ "${{ github.event.inputs.device }}" = "netgear_r8500" ]; then
cp -a openwrt/bin/targets/bcm53xx/generic/*-bcm53xx-generic-netgear_r8500-squashfs.chk rom/
cp -a openwrt/bin/targets/bcm53xx/generic/*.manifest info/manifest.txt
cp -a openwrt/bin/targets/bcm53xx/generic/config.buildinfo info/config.buildinfo
cd rom && sha256sum * > ../info/sha256sums.txt
elif [ "${{ github.event.inputs.device }}" = "armv8" ]; then
tar zcf rom/u-boot-qemu_armv8.tar.gz -C openwrt/bin/targets/armsr/armv8*/ ./u-boot-qemu_armv8
cp -a openwrt/bin/targets/armsr/armv8*/*-generic-initramfs-kernel.bin rom/
cp -a openwrt/bin/targets/armsr/armv8*/*-generic-kernel.bin rom/
cp -a openwrt/bin/targets/armsr/armv8*/*-generic-ext4-combined-efi.img.gz rom/
cp -a openwrt/bin/targets/armsr/armv8*/*-generic-squashfs-combined-efi.img.gz rom/
cp -a openwrt/bin/targets/armsr/armv8*/*-rootfs.tar.gz rom/
cp -a openwrt/bin/targets/armsr/armv8*/*.manifest info/manifest.txt
cp -a openwrt/bin/targets/armsr/armv8*/config.buildinfo info/config.buildinfo
cd rom && sha256sum * > ../info/sha256sums.txt
fi
- name: Upload artifacts (上传固件)
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.inputs.device }}-openwrt-${{ env.latest_release }}
path: ${{ env.build_dir }}/rom/*
- name: Create release (发布固件)
continue-on-error: true
uses: ncipollo/release-action@v1
with:
name: ${{ env.latest_release }}
allowUpdates: true
tag: ${{ env.latest_release }}
commit: master
replacesArtifacts: true
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: ${{ env.build_dir }}/rom/*