forked from dabao1955/kernel_build_action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
477 lines (435 loc) · 17.9 KB
/
action.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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
name: 'Android Kernel Build Action'
description: "A action to built android kernel."
branding:
icon: 'activity'
color: 'blue'
inputs:
kernel-url:
description: 'Kernel Source Url'
required: true
depth:
required: false
default: 1
vendor:
required: false
default: false
vendor-url:
description: 'Kernel Vendor Source Url'
required: false
kernel-dir:
required: false
default: kernel
vendor-dir:
required: false
default: vendor
kernel-branch:
description: 'Branch name'
required: false
default: main
vendor-branch:
required: false
default: main
config:
description: 'configuration for building android kernel'
required: true
default: defconfig
arch:
required: true
default: arm64
android-version:
description: 'Android version.'
required: true
default: 12
path:
description: 'Set environment PATH'
required: true
default: false
cflags:
description: 'Make Options'
required: true
default: false
extra-version:
description: 'Kernel Extra Version'
required: false
default:
python:
description: 'Set Python Version'
required: true
default: python3
gcc64-url:
description: 'GCC64 Repo'
required: false
default:
gcc64-tar:
description: 'GCC64 tar URL'
required: false
default:
clang-url:
description: 'Clang Repo'
required: false
default:
clang-tar:
description: 'Clang tar URL'
required: false
default:
ksu:
description: 'KernelSU function support'
required: false
default: false
ksu-version:
description: 'KernelSU default branch'
required: false
default: "main"
ksu-other:
required: false
default: false
ksu-url:
description: "Use 3rd KernelSU"
required: false
default: ""
ksu-lkm:
description: "Build KernelSU as a loadable kernel module"
required: false
default: false
disable-lto:
description: 'Disable LTO configs for configs.'
required: false
default: false
lxc:
description: 'Enable lxc and docker configs for configs.'
required: false
default: false
lxc-patch:
description: 'Apply lxc patch aviod not booting'
required: false
default: false
nethunter:
description: 'Enable Kali nethunter'
required: false
default: false
nethunter-patch:
description: 'patch config'
required: false
default: false
kvm:
description: 'Enable KVM for configs.'
required: false
default: false
ccache:
description: 'Enable Ccache for compiling kernel'
required: false
default: false
aosp-clang:
description: 'Use clang from aosp project.'
required: false
default: false
aosp-clang-version:
required: false
default: "r383902"
other-clang-url:
required: false
default: ''
other-clang-branch:
required: false
default: main
android-ndk:
description: 'Use Android NDK to build kernrl (Experimental features)'
required: false
default: false
android-ndk-version:
description: 'Please press nember instead of r(e.g. : 26).'
required: false
default: r21b
anykernel3:
description: 'Package kernel use anykernel3.'
required: false
default: false
anykernel3-url:
description: '3rdparty anykernrl3 url path'
required: false
default: ""
bootimg-url:
description: "boot.img path"
required: false
default: ""
release:
description: "After the kernel compilation is completed, it will be automatically published to the releases page"
required: false
default: false
access-token:
description: 'PAT with repository scope (https://github.com/settings/tokens)'
required: false
runs:
using: 'composite'
steps:
- name: Setup ccache
if: inputs.ccache == 'true'
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ inputs.config }}-0cb68f9cbcbb3de9c966cf66ed51471fbe51419e
max-size: 4G
- name: Build Kernel
shell: bash
run: |
########
if [[ ${GITHUB_ACTIONS} != "true" || ${OSTYPE} != "linux-gnu" || ! -f /bin/apt ]]; then
printf "This Action Is Intended For Debian-based Runner.\n"
exit 127
fi
if [ "$(id -u)" -eq 0 ]; then
export SU=
else
export SU=sudo
fi
if [ -f /usr/bin/docker ]; then
echo "::group:: Cleaning necessary disk space"
"$SU" docker image prune --all --force
fi
echo "::endgroup::"
echo "::group:: Installing Building Depend Packages"
"$SU" apt-get update
"$SU" apt-get install --no-install-recommends -y git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig python2
aria2c -q https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh && NONINTERACTIVE=1 bash ./uninstall.sh -f -q
echo "::endgroup::"
export SWAP_FILE=$(swapon --show=NAME | tail -n 1)
if [ -f /bin/swapon ]; then
echo "::group:: Setting Up Swap"
"$SU" swapoff $SWAP_FILE
"$SU" rm $SWAP_FILE
"$SU" fallocate -l 16G $SWAP_FILE
"$SU" chmod 600 $SWAP_FILE
"$SU" mkswap $SWAP_FILE
"$SU" swapon $SWAP_FILE
echo "::endgroup::"
fi
echo "::endgroup::"
echo "::group:: Pulling Kernel Source"
git clone --recursive ${{ inputs.kernel-url }} -b "${{ inputs.kernel-branch }}" --depth=${{ inputs.depth }} kernel/${{ inputs.kernel-dir }}
echo "::endgroup::"
if [ "${{ inputs.vendor }}" = true ]; then
echo "::group:: Pulling Kernel vendor source"
git clone ${{ inputs.vendor-url }} --depth=${{ inputs.depth }} kernel/${{ inputs.vendor-dir }} -b ${{ inputs.vendor-branch }}
test -d kernel/${{ inputs.vendor-dir }}/vendor && cp -rv kernel/${{ inputs.vendor-dir }}/vendor kernel
test -d kernel/${{ inputs.vendor-dir }}/vendor && cp -rv kernel/${{ inputs.vendor-dir }}/vendor ./
echo "::endgroup::"
fi
cd kernel/${{ inputs.kernel-dir }}
function version_gt() { test "$(echo -e "$1\n$2" | sort -V | tail -n1)" == "$1"; }
VERSION=$(grep -E '^VERSION = ' Makefile | awk '{print $3}')
PATCHLEVEL=$(grep -E '^PATCHLEVEL = ' Makefile | awk '{print $3}')
SUBLEVEL=$(grep -E '^SUBLEVEL = ' Makefile | awk '{print $3}')
if [ "$VERSION" -lt 5 ]; then
touch nongki.txt
elif [ "PATCHLEVEL" -lt 10 ]; then
touch nongki.txt
fi
if [ ${{ inputs.ksu }} = true ]; then
echo "::group:: Initializing KernelSU"
rm -rf KernelSU
if [ ${{ inputs.ksu-other }} = true ]; then
curl -SsL "${{ inputs.ksu-url }}/raw/${{ inputs.ksu-version }}/kernel/setup.sh" | bash -s ${{ inputs.ksu-version }}
else
echo "Kernel version: $VERSION.$PATCHLEVEL.$SUBLEVEL"
curl -LSs "https://raw.githubusercontent.com/Andrey0800770/KernelSU/main/kernel/setup.sh" | bash -s ${{ inputs.ksu-version }}
fi
fi
echo "::endgroup::"
if [ -f scripts/dtc/libfdt/mkdtboimg.py ]; then
if grep python2 scripts/Makefile.lib >/dev/null; then
echo "::group:: Uning mkdtboimg Python3 version instead of Python2 version"
rm -rf -v scripts/dtc/libfdt/mkdtboimg.py && aria2c https://github.com/dabao1955/kernel_build_action/raw/main/mkdtboimg.py -o scripts/dtc/libfdt/mkdtboimg.py
elif grep scripts/ufdt && test ! -d scripts/ufdt >/dev/null; then
aria2c https://github.com/dabao1955/kernel_build_action/raw/main/mkdtboimg.py -o ufdt/libufdt/utils/src/mkdtboimg.py
fi
test -f /usr/bin/python2 || "$SU" ln -s -f -v /usr/bin/python3 /usr/bin/python2
fi
echo "::endgroup::"
if [ ${{ inputs.nethunter }} = true ]; then
echo "::group:: Initializing Kali nethunter"
aria2c https://github.com/dabao1955/kernel_build_action/raw/main/nethunter/config.sh -o nconfig.sh && bash nconfig.sh arch/${{ inputs.arch }}/configs/${{ inputs.config }} -w
if [ ${{ inputs.nethunter-patch }} = true ]; then
aria2c https://github.com/dabao1955/kernel_build_action/raw/main/nethunter/add-wifi-injection.patch && git apply add-wifi-injection.patch
aria2c apply https://github.com/dabao1955/kernel_build_action/raw/main/nethunter/fix-ath9k-naming-conflict.patch && git apply fix-ath9k-naming-confict.patch
if [ "$SUBLEVEL" -lt "19" ]; then
aria2c https://github.com/dabao1955/kernel_build_action/raw/main/nethunter/add-wifi-injection-4.14.patch && git apply add-wifi-injection-4.14.patch
fi
else
echo "skip patch"
fi
echo "::endgroup::"
fi
if [ ${{ inputs.disable-lto }} = true ]; then
if grep -q "LTO" "arch/${{ inputs.arch }}/configs/${{ inputs.config }}"
then
sed -i 's/CONFIG_LTO=y/CONFIG_LTO=n/' arch/${{ inputs.arch }}/configs/${{ inputs.config }}
sed -i 's/CONFIG_LTO_CLANG=y/CONFIG_LTO_CLANG=n/' arch/${{ inputs.arch }}/configs/${{ inputs.config }}
sed -i 's/CONFIG_THINLTO=y/CONFIG_THINLTO=n/' arch/${{ inputs.arch }}/configs/${{ inputs.config }}
echo "CONFIG_LTO_NONE=y" | tee -a arch/${{ inputs.arch }}/configs/${{ inputs.config }} >/dev/null
fi
fi
if [ ${{ inputs.kvm }} = true ]; then
echo "CONFIG_VIRTUALIZATION=y" | tee -a arch/${{ inputs.arch }}/configs/${{ inputs.config }} >/dev/null
echo "CONFIG_KVM=y" | tee -a arch/${{ inputs.arch }}/configs/${{ inputs.config }} >/dev/null
echo "CONFIG_KVM_MMIO=y" | tee -a arch/${{ inputs.arch }}/configs/${{ inputs.config }} >/dev/null
echo "CONFIG_KVM_ARM_HOST=y" | tee -a arch/${{ inputs.arch }}/configs/${{ inputs.config }} >/dev/null
fi
if [ ${{ inputs.lxc }} = true ]; then
echo "::group:: Enabling LXC"
aria2c https://github.com/dabao1955/kernel_build_action/raw/main/lxc/config.sh && bash config.sh arch/${{ inputs.arch }}/configs/${{ inputs.config }} -w
if [ ${{ inputs.lxc-patch }} = true ]; then
aria2c https://github.com/dabao1955/kernel_build_action/raw/main/lxc/xt_qtaguid.patch
aria2c https://github.com/dabao1955/kernel_build_action/raw/main/lxc/cgroup.patch
patch kernel/cgroup/cgroup.c < cgroup.patch
patch net/netfilter/xt_qtaguid.c < xt_qtaguid.patch
else
echo skip lxc patching
fi
echo "::endgroup::"
fi
echo "::group:: Python VERSION"
$SU update-alternatives --install /usr/bin/python python /usr/bin/${{ inputs.python }} 1
python --version
command -v python
echo "::endgroup::"
echo "::group:: Setting-up Toolchains"
if [ -n "${{ inputs.gcc64-url }}" ]; then
mkdir -p -v "$HOME/gcc64"
git clone ${{ inputs.gcc64-url }} $HOME/gcc64
GCC64="$HOME/gcc64/bin"
echo "$GCC64"
ls "$HOME/gcc64"
fi
if [ -n "${{ inputs.gcc64-tar }}" ]; then
mkdir -p -v "$HOME/gcc64"
wget -q -O gcc64.tar "${{ inputs.gcc64-tar }}"
case "$(file -b --mime-type gcc64.tar)" in
application/x-gzip) tar -xzf gcc64.tar -C "$HOME/gcc64" ;; # .tar.gz
application/x-xz) tar -xJf gcc64.tar -C "$HOME/gcc64" ;; # .tar.xz
application/zip) unzip gcc64.tar -d "$HOME/gcc64" ;; # .zip
application/x-tar) tar -xf gcc64.tar -C "$HOME/gcc64" ;; # .tar
*) echo "Tipo de arquivo não suportado: $(file -b --mime-type gcc64.tar)"; exit 1 ;;
esac
GCC64="$HOME/gcc64/bin"
echo "$GCC64"
ls "$HOME/gcc64"
fi
if [ -n "${{ inputs.clang-url }}" ]; then
mkdir -p -v "$HOME/clang"
git clone ${{ inputs.clang-url }} $HOME/clang
CLANG="$HOME/clang/bin"
echo "$CLANG"
ls "$HOME/clang"
fi
if [ -n "${{ inputs.clang-tar }}" ]; then
mkdir -p -v "$HOME/clang"
wget -q -O clang.tar ${{ inputs.clang-tar }}
case "$(file -b --mime-type clang.tar)" in
application/x-gzip | application/gzip) tar -xzf clang.tar -C "$HOME/clang" ;; # .tar.gz
application/x-xz) tar -xJf clang.tar -C "$HOME/clang" ;; # .tar.xz
application/zip) unzip clang.tar -d "$HOME/clang" ;; # .zip
application/x-tar) tar -xf clang.tar -C "$HOME/clang" ;; # .tar
*) echo "Tipo de arquivo não suportado: $(file -b --mime-type clang.tar)"; exit 1 ;;
esac
CLANG="$HOME/clang/bin"
echo "$CLANG"
ls "$HOME/clang"
fi
export PATH="${{ inputs.path }}"
${{ inputs.cflags }}
${CROSS_COMPILE}gcc --version || true
clang --version || true
echo "::endgroup::"
echo "::group:: Compiling Linux Kernel "
mkdir out -p -v
export PLATFORM_VERSION=10.0
export EXTRAVERSION=${{ inputs.extra-version }}
make O=out ARCH=arm64 ${{ inputs.config }}
echo "Starting compilaton"
make -j$(nproc --all) ${{ inputs.cflags }} O=out ARCH=arm64
echo "::endgroup::"
unset USE_CCACHE CLANG_TRIPLE CROSS_COMPILE_ARM32 CROSS_COMPILE CLANG_PATH HOMES SUBLEVEL KVER COMMAND SWAP_FILE SUBLEVEL PATCHLEVEL VERSION
if [ ${{ inputs.anykernel3 }} = false ]; then
echo "::group:: Preparing to Upload boot.img"
mkdir split
cd split
export HOST_ARCH=$(dpkg --print-architecture)
case ${HOST_ARCH} in
armv7* | armv8l | arm64 | armhf | arm) aria2c https://github.com/Shubhamvis98/AIK/raw/4ac321dfd48e16344e6146c505708aa720ff0bb3/bin/magiskboot_arm -o magiskboot && chmod 755 magiskboot ;;
i*86 | x86 | amd64 | x86_64) aria2c https://github.com/Shubhamvis98/AIK/raw/4ac321dfd48e16344e6146c505708aa720ff0bb3/bin/magiskboot_x86 -o magiskboot && chmod 755 magiskboot ;;
*) echo "Unknow cpu architecture for this device !" && exit 1 ;;
esac
aria2c ${{ inputs.bootimg-url }} -o boot.img
nohup ./magiskboot unpack boot.img
export FMT=$(cat nohup.out | grep "KERNEL_FMT" | awk '{gsub("\\[", "", $2); gsub("\\]", "", $2); print $2}')
if [ "$FMT" = "raw" ] ; then
cp -v ../out/arch/${{ inputs.arch }}/boot/Image kernel
else
if ls dtb >/dev/null ; then
cp -v ../out/arch/${{ inputs.arch }}/boot/Image.*-dtb kernel
else
cp -v ../out/arch/${{ inputs.arch }}/boot/Image.* kernel
fi
fi
./magiskboot repack boot.img
rm -rf boot.img
mkdir -p -v ../../../build
mv *.img ../../../build/boot.img -v
cd ..
echo "::endgroup::"
else
echo "::group:: Packaging Anykernel3 flasher"
if [ ! -z ${{ inputs.anykernel3-url }} ]; then
git clone ${{ inputs.anykernel3-url }} AnyKernel3
else
git clone https://github.com/osm0sis/AnyKernel3
sed -i 's!BLOCK=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot;!BLOCK=auto;!g' AnyKernel3/anykernel.sh
sed -i 's/do.devicecheck=1/do.devicecheck=0/g' AnyKernel3/anykernel.sh
sed -i 's/is_slot_device=0;/IS_SLOT_DEVICE=auto;/g' AnyKernel3/anykernel.sh
fi
if [ -f out/arch/${{ inputs.arch }}/boot/Image.*-dtb ]; then
cp out/arch/${{ inputs.arch }}/boot/Image.*-dtb AnyKernel3/ -rv
elif [ -f out/arch/${{ inputs.arch }}/boot/Image.* ]; then
cp out/arch/${{ inputs.arch }}/boot/Image.* AnyKernel3/ -rv
else
cp out/arch/${{ inputs.arch }}/boot/Image AnyKernel3/ -rv
fi
test -f out/arch/${{ inputs.arch }}/boot/dtbo.img && cp -v out/arch/${{ inputs.arch }}/boot/dtbo.img AnyKernel3/
rm -rf -v AnyKernel3/.git* AnyKernel3/README.md
if [ ${{ inputs.release }} = false ]; then
cp AnyKernel3 ../../build -r -v
else
zip ${{ inputs.config }}.zip AnyKernel3/*
mv ${{ inputs.config }}.zip ../../build -v
fi
echo "::endgroup::"
fi
- id: uploadi
if: ${{ inputs.release == 'false' && inputs.anykernel3 == 'false' }}
uses: actions/upload-artifact@v4
with:
name: kernel-built-bootimg
path: build/*
if-no-files-found: error
overwrite: true
- id: uploada
if: ${{ inputs.release == 'false' && inputs.anykernel3 == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.config }}
path: build/*
if-no-files-found: error
overwrite: true
- id: release
if: inputs.release == 'true'
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ inputs.access-token }}
with:
name: Last CI build kernel
tag_name: last-ci
files: build/*
make_latest: true
body: |
config: ${{ inputs.config }}
branch: ${{ inputs.kernel-branch }}
source: ${{ inputs.kernel-url }}