-
Notifications
You must be signed in to change notification settings - Fork 42
244 lines (211 loc) · 8 KB
/
main.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
name: Check and Build
env:
kernel_repository: PixelExperience-Devices/kernel_xiaomi_sdm845
kernel_branch: fourteen
device: dipper
clang_version: r487747c
defconfig: |
dipper_defconfig
kernel_patch: |
backport-path-umount.patch
kernelsu_patch: |
on:
workflow_dispatch:
inputs:
allow_rebuild:
description: "Allow Rebuild"
type: boolean
default: false
jobs:
check_kernelsu_update:
name: Check KernelSU update
runs-on: ubuntu-latest
steps:
- name: Check KernelSU version
id: check_kernelsu_version
run: |
local_version=$(curl -L --header 'authorization: Bearer ${{ github.token }}' https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
# remote_version=$(curl -L https://api.github.com/repos/tiann/KernelSU/releases/latest | jq -r .tag_name)
remote_version=v0.9.5
echo local_version=$local_version | tee -a $GITHUB_OUTPUT
echo remote_version=$remote_version | tee -a $GITHUB_OUTPUT
outputs:
local_version: ${{ steps.check_kernelsu_version.outputs.local_version }}
remote_version: ${{ steps.check_kernelsu_version.outputs.remote_version }}
build:
name: Build kernel
needs: check_kernelsu_update
if: inputs.allow_rebuild || needs.check_kernelsu_update.outputs.local_version != needs.check_kernelsu_update.outputs.remote_version
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Set env
run: |
echo kernelsu_remote_version=${{ needs.check_kernelsu_update.outputs.remote_version }} | tee -a $GITHUB_ENV
if [[ "$clang_version" = "r"* ]] || [[ "$clang_version" = "latest" ]]; then
clang_type=aosp
else
clang_type=vanilla
fi
echo clang_type=$clang_type | tee -a $GITHUB_ENV
if [[ "$clang_version" = "latest" ]]; then
clang_version=$(curl -L https://android.googlesource.com/kernel/common/+/refs/heads/android-mainline/build.config.constants | grep -Eo 'r[0-9]{6}[a-z]?[0-9]?')
echo clang_version=$clang_version | tee -a $GITHUB_ENV
fi
- name: Install packages
run: |
sudo apt update
sudo apt install -y \
binutils-arm-linux-gnueabi \
binutils-aarch64-linux-gnu
- name: Checkout kernel source
uses: actions/checkout@v4
with:
repository: ${{ env.kernel_repository }}
ref: ${{ env.kernel_branch }}
submodules: recursive
- name: Checkout this repo
uses: actions/checkout@v4
with:
path: this-repo
submodules: recursive
- name: Get latest kernel commit id
run: |
echo kernel_commit_id=$(git rev-parse HEAD) | tee -a $GITHUB_ENV
- name: Merge defconfig
run: |
while read -r line; do
if [ -z "$line" ] || [[ "$line" == "#"* ]]; then
continue
fi
echo "Merging defconfig: $line"
cat arch/arm64/configs/$line >>arch/arm64/configs/merged_defconfig
done <<<"$defconfig"
- name: Setup KernelSU
run: |
# https://kernelsu.org/zh_CN/guide/how-to-integrate-for-non-gki.html
curl -L https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh | bash -s -- $kernelsu_remote_version
echo 'CONFIG_KPROBES=y' >>arch/arm64/configs/merged_defconfig
echo 'CONFIG_HAVE_KPROBES=y' >>arch/arm64/configs/merged_defconfig
echo 'CONFIG_KPROBE_EVENTS=y' >>arch/arm64/configs/merged_defconfig
- name: Apply kernel patch
run: |
while read -r line; do
if [ -z "$line" ] || [[ "$line" == "#"* ]]; then
continue
fi
echo "Applying kernel patch: $line"
git apply "this-repo/patches/$line"
done <<<"$kernel_patch"
- name: Apply KernelSU patch
run: |
while read -r line; do
if [ -z "$line" ] || [[ "$line" == "#"* ]]; then
continue
fi
echo "Applying KernelSU patch: $line"
git apply -p2 --directory KernelSU/kernel "this-repo/patches/$line"
done <<<"$kernelsu_patch"
- name: "AOSP-Clang: Restore"
id: aosp_clang_restore
if: env.clang_type == 'aosp'
uses: actions/cache/restore@v4
with:
path: aosp-clang
key: aosp-clang-${{ env.clang_version }}
- name: "AOSP-Clang: Download"
id: aosp_clang_download
if: env.clang_type == 'aosp' && steps.aosp_clang_restore.outputs.cache-hit != 'true'
run: |
aosp_clang_branch=$(
case "$clang_version" in
r365631c ) echo android11-release;;
r383902 | r416183b) echo master-kernel-build-2021 ;;
r450784e) echo master-kernel-build-2022 ;;
r487747c) echo main-kernel-build-2023 ;;
*) echo main ;;
esac
)
mkdir -p aosp-clang
curl -L https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/$aosp_clang_branch/clang-$clang_version.tar.gz | tar xz -C aosp-clang
- name: "AOSP-Clang: Save"
id: aosp_clang_save
if: env.clang_type == 'aosp' && steps.aosp_clang_download.outcome == 'success'
uses: actions/cache/save@v4
with:
path: aosp-clang
key: aosp-clang-${{ env.clang_version }}
- name: "AOSP-Clang: Setup"
if: env.clang_type == 'aosp'
run: |
echo PATH=$(pwd)/aosp-clang/bin:$PATH | tee -a $GITHUB_ENV
- name: "Vanilla-Clang: Setup"
if: env.clang_type == 'vanilla'
run: |
curl -L https://apt.llvm.org/llvm.sh | sudo bash -s -- $clang_version
echo PATH=/usr/lib/llvm-$clang_version/bin:$PATH | tee -a $GITHUB_ENV
- name: export flags
run: |
echo flags=" \
O=out \
ARCH=arm64 \
LLVM=1 \
LLVM_IAS=1 \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi-
" | tee -a $GITHUB_ENV
- name: Make defconfig
run: |
make $flags merged_defconfig
- name: Make
run: |
make $flags -j$(nproc --all)
- name: AnyKernel3
run: |
curl -Lo AnyKernel3.zip https://github.com/osm0sis/AnyKernel3/archive/refs/heads/master.zip
unzip AnyKernel3.zip
cat >AnyKernel3-master/anykernel.sh <<EOF
properties() { '
kernel.string=$kernel_repository $kernel_branch with KernelSU $kernelsu_remote_version for $device
do.devicecheck=1
do.modules=0
do.cleanup=1
do.cleanuponabort=1
device.name1=$device
'; }
block=auto
is_slot_device=auto
ramdisk_compression=auto
patch_vbmeta_flag=auto
. tools/ak3-core.sh
split_boot
flash_boot
EOF
cp out/arch/arm64/boot/Image.gz-dtb AnyKernel3-master/
if [ -f out/arch/arm64/boot/dtbo.img ]; then
cp out/arch/arm64/boot/dtbo.img AnyKernel3-master/
fi
cd AnyKernel3-master
rm -rf .git* README.md
zip -r ../boot.zip *
- name: "Upload artifact"
uses: actions/upload-artifact@v4
with:
name: boot
path: AnyKernel3-master/*
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.kernelsu_remote_version }}
body: |
Device:
${{ env.device }}
Kernel:
https://github.com/${{ env.kernel_repository }}/tree/${{ env.kernel_commit_id }}
Branch:
${{ env.kernel_branch }}
KernelSU:
https://github.com/tiann/KernelSU/releases/tag/${{ env.kernelsu_remote_version }}
files: |
boot.zip