-
Notifications
You must be signed in to change notification settings - Fork 1
299 lines (267 loc) · 11.6 KB
/
Copy pathbuild-linuxbox.yml
File metadata and controls
299 lines (267 loc) · 11.6 KB
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
name: Build LinuxBox-Dev firmware
on:
workflow_dispatch:
inputs:
board:
description: "Board: trhubv3, trhubv3b, linuxbox"
required: true
default: "trhubv3"
dist:
description: "Distribution: cn, us, kr"
required: true
default: "us"
revision:
description: "Revision (optional)"
required: true
default: "v1.14.01.24"
jobs:
build-linuxbox:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: hubv3
- name: Free up disk space
run: |
echo "=== Initial disk usage ==="
uname -a
lsb_release -a
cat /etc/os-release
cat /etc/lsb-release
cat /etc/debian_version || true
cat /etc/redhat-release || true
cat /etc/system-release || true
cat /etc/issue || true
cat /etc/issue.net || true
cat /etc/motd || true
df -h
echo ""
echo "=== Removing unnecessary software ==="
# Remove Android SDK
sudo rm -rf /usr/local/lib/android || true
# Remove .NET
sudo rm -rf /usr/share/dotnet || true
# Remove Haskell
sudo rm -rf /opt/ghc || true
sudo rm -rf /usr/local/.ghcup || true
# Remove CodeQL
sudo rm -rf /opt/hostedtoolcache/CodeQL || true
# Remove large tool caches
sudo rm -rf /opt/hostedtoolcache/* || true
# Remove large packages
sudo apt-get remove -y '^aspnetcore-.*' '^dotnet-.*' '^llvm-.*' 'php.*' '^mongodb-.*' '^mysql-.*' azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri >/dev/null 2>&1 || true
# Remove Docker images and containers
docker rmi $(docker image ls -aq) >/dev/null 2>&1 || true
docker system prune -a -f >/dev/null 2>&1 || true
# Remove swap
sudo swapoff -a || true
sudo rm -f /mnt/swapfile || true
sudo rm -f /swapfile || true
# Additional cleanup
echo "=== Additional cleanup ==="
sudo rm -rf /tmp/* || true
sudo rm -rf /var/tmp/* || true
sudo rm -rf ~/.cache/* || true
sudo rm -rf /root/.cache/* || true
sudo find /tmp -type f -atime +0 -delete 2>/dev/null || true
sudo find /var/tmp -type f -atime +0 -delete 2>/dev/null || true
echo ""
echo "=== Disk usage after cleanup ==="
df -h
echo ""
echo "=== Cleaning up previous build artifacts ==="
sudo rm -rf /mnt/linuxbox
echo "=== Final disk usage ==="
df -h
- name: Ensure DNS and apt fallback
run: |
echo "Setting fallback DNS and apt retries..."
sudo rm -f /etc/resolv.conf
printf "nameserver 1.1.1.1\nnameserver 8.8.8.8\n" | sudo tee /etc/resolv.conf
sudo bash -c 'printf "%s\n" \
"Acquire::ForceIPv4 \"true\";" \
"Acquire::Retries \"5\";" \
"Acquire::http::Timeout \"30\";" \
"Acquire::https::Timeout \"30\";" \
"Acquire::Languages \"none\";" \
> /etc/apt/apt.conf.d/99force-ipv4'
sudo systemd-resolve --flush-caches || true
- name: Clone repository to /mnt/linuxbox
run: |
echo "Cloning repository to /mnt/linuxbox..."
sudo mkdir -p /mnt/linuxbox
sudo chown -R $USER:$USER /mnt/linuxbox
git clone --depth 1 --branch hubv3 https://github.com/${{ github.repository }}.git /mnt/linuxbox
echo "Repository cloned successfully"
ls -lah /mnt/linuxbox/
- name: Install dependencies
run: |
sudo apt-get update
# Install essential build tools for U-boot and kernel compilation
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y uuid-runtime systemd acl sudo git dialog psmisc uuid curl gawk ca-certificates \
gcc build-essential python3 python3-dev python3-venv python3-pip pv xz-utils patchutils \
binfmt-support qemu-user-static \
bc bison flex libssl-dev libncurses5-dev libncursesw5-dev \
device-tree-compiler u-boot-tools swig libpython3-dev \
gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu \
ccache ntpdate imagemagick pixz
sudo DEBIAN_FRONTEND=noninteractive apt-get autoremove -y || true
sudo DEBIAN_FRONTEND=noninteractive apt-get clean || true
# Clean apt cache
sudo rm -rf /var/lib/apt/lists/* || true
sudo rm -rf /var/cache/apt/archives/* || true
echo "Disk usage after installing dependencies:"
df -h
- name: Setup QEMU for ARM emulation
run: |
echo "Setting up QEMU for ARM emulation..."
sudo systemctl restart systemd-binfmt.service || true
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes || true
echo "Verifying QEMU registration..."
ls -la /proc/sys/fs/binfmt_misc/ || true
cat /proc/sys/fs/binfmt_misc/qemu-aarch64 || echo "qemu-aarch64 not registered"
- name: Clean build cache
working-directory: /mnt/linuxbox
run: |
echo "Cleaning build cache..."
sudo rm -rf cache/
sudo rm -rf .tmp/
echo "Build cache cleaned"
echo "Disk usage after cache cleanup:"
df -h
- name: Build userpatches
working-directory: /mnt/linuxbox
run: |
echo "Setting up userpatches..."
mkdir -p userpatches/overlay/
cp custom/config-hubv3-images.conf userpatches/
cp custom/config-jethubj100-images.conf userpatches/
cp custom/customize-image.sh userpatches/
#cp custom/*.deb userpatches/overlay/
cp custom/bl706_cache userpatches/overlay/ -R
echo "Cleaning output directory..."
rm -rf output/images
mkdir -p output/images
- name: Check disk space before build
working-directory: /mnt/linuxbox
run: |
echo "=== Disk space check before build ==="
df -h
echo ""
echo "Available space:"
df -h . | tail -1 | awk '{print "Available: " $4}'
echo ""
# Check if we have at least 20GB free
AVAILABLE=$(df -BG . | tail -1 | awk '{print $4}' | sed 's/G//')
if [ "$AVAILABLE" -lt 20 ]; then
echo "WARNING: Less than 20GB available. Attempting additional cleanup..."
sudo rm -rf /tmp/* || true
sudo rm -rf /var/tmp/* || true
sudo find /tmp -type f -atime +1 -delete 2>/dev/null || true
sudo find /var/tmp -type f -atime +1 -delete 2>/dev/null || true
df -h
fi
- name: Build firmware
working-directory: /mnt/linuxbox
env:
NO_APT_CACHER: yes
run: |
set -e
# Calculate version ID from revision
r3version="${{ github.event.inputs.revision }}"
ver_no_v=${r3version#v}
IFS='.' read -r major minor patch build <<< "$ver_no_v"
r3_version_id=$((10#$major * 1000000 + 10#$minor * 10000 + 10#$patch * 100 + 10#$build))
echo "Building firmware with parameters:"
echo "Board: ${{ github.event.inputs.board }}"
echo "Dist: ${{ github.event.inputs.dist }}"
echo "Revision: $r3version"
echo "Version ID: $r3_version_id"
echo ""
echo "Disk space before build:"
df -h .
# Set destination based on dist input
if [[ "${{ github.event.inputs.dist }}" == "cn" ]]; then
destination="china"
else
destination=""
fi
# Execute compile.sh with error handling
if ! ./compile.sh hubv3-images BOARD=${{ github.event.inputs.board }} BRANCH=current RELEASE=bookworm R3VERSION=$r3version R3VERSION_ID=$r3_version_id \
BUILD_MINIMAL=no BUILD_DESKTOP=no KERNEL_ONLY=no KERNEL_CONFIGURE=no \
COMPRESS_OUTPUTIMAGE=sha,gpg,img INSTALL_HEADERS=no WIREGUARD=no \
UBOOT_MIRROR=github NO_APT_CACHER=yes \
DOWNLOAD_MIRROR=$destination; then
echo ""
echo "=== Build failed. Checking logs and disk space ==="
echo "Disk space after failure:"
df -h .
echo ""
echo "Checking for install.log:"
find . -name "install.log" -type f -exec tail -100 {} \; 2>/dev/null || echo "No install.log found"
echo ""
echo "Checking .tmp directory size:"
du -sh .tmp 2>/dev/null || echo ".tmp not found"
exit 1
fi
- name: Convert image
working-directory: /mnt/linuxbox
run: |
echo "Checking for generated images..."
IMG_FILE=$(find "output/images" -maxdepth 1 -type f -name "*.img")
if [[ -n "$IMG_FILE" ]]; then
echo "Enter convert directory Armbian_Convert ..."
UBOOT=$(find cache/sources/u-boot/ -name u-boot.bin -type f -print -quit)
IMAGE=$(find output/images -name '*.img' -type f -print -quit)
echo "UBOOT: ${UBOOT}"
echo "Image: ${IMAGE}"
mkdir -p tools/Armbian_Convert/output
./tools/Armbian_Convert/convert.sh ${IMAGE} ${{ github.event.inputs.board }} armbian no ${UBOOT}
IMGBURN=$(find tools -maxdepth 8 -type f -name "*.burn.img")
if [[ -n "$IMGBURN" && -f "$IMGBURN" ]]; then
mkdir -p output/images/
mv "$IMGBURN" output/images/
IMGBURN=$(find output -maxdepth 4 -type f -name "*.burn.img")
# 重命名 .burn.img 为 .${r3version}.img
r3version="${{ github.event.inputs.revision }}"
new_imgburn="${IMGBURN/.burn.img/.${r3version}.img}"
mv "$IMGBURN" "$new_imgburn"
rm -rf "${IMAGE}"
echo "File build: $new_imgburn"
# 转换完成后,清理不需要的文件
echo "Cleaning up after successful conversion..."
sudo rm -rf .tmp
sudo rm -rf tools/Armbian_Convert/output/*.zip
echo "Disk usage after final cleanup:"
df -h .
df -h /
else
echo "Fail: No burn.img file exist."
fi
else
echo "No .img files found in output/images/"
fi
- name: List output files for debugging
working-directory: /mnt/linuxbox
run: |
echo "Checking output directory structure..."
ls -lah output/ || echo "output/ not found"
ls -lah output/images/ || echo "output/images/ not found"
find output -name "*.img" -type f 2>/dev/null || echo "No .img files found in output/"
echo "Disk usage after build:"
df -h
- name: Upload images as artifact
uses: actions/upload-artifact@v4
with:
name: LinuxBox-images${{ github.event.inputs.revision && format('-{0}', github.event.inputs.revision) || '' }}
path: |
/mnt/linuxbox/output/images/*.img
/mnt/linuxbox/output/images/*.xz
if-no-files-found: warn
- name: Clean up after upload
run: |
echo "Cleaning up after successful upload..."
sudo rm -rf /mnt/linuxbox
echo "Final disk usage:"
df -h