forked from liangsai12/Android-Kernel-Builder-chopin
-
Notifications
You must be signed in to change notification settings - Fork 0
303 lines (264 loc) · 11.2 KB
/
build.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
name: "Build kernels"
env:
OUT_DIR: "${{ github.workspace }}/out"
on:
workflow_dispatch:
jobs:
Set-repos:
name: "🐂 Parse repos.json"
runs-on: ubuntu-latest
outputs:
repos: ${{ steps.generate-matrix.outputs.repos }}
builddate: ${{ steps.generate-builddate.outputs.builddate }}
steps:
- name: "😄 Checkout"
uses: actions/checkout@v3
- name: "😆 Generate Matrix"
id: generate-matrix
run: |
echo "repos<<EOF" >> $GITHUB_OUTPUT
jq -s '[.[][]]' repos/repos*.json >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: "⏰ Set builddate"
id: generate-builddate
run: echo "builddate=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
Build-Kernel:
name: "🐎 Build kernel"
runs-on: ubuntu-latest
needs:
- Set-repos
strategy:
max-parallel: 4
fail-fast: false
matrix:
repos: ${{ fromJSON(needs.Set-repos.outputs.repos) }}
env:
WORKSPACE: ${{ github.workspace }}
builddate: "${{ needs.Set-repos.outputs.builddate }}"
KERNEL_NAME: ${{ matrix.repos.kernelSource.name }}
KERNEL_REPO: ${{ matrix.repos.kernelSource.repo }}
KERNEL_BRANCH: ${{ matrix.repos.kernelSource.branch }}
KERNEL_DEVICE: ${{ matrix.repos.kernelSource.device }}
DEFCONFIG_NAME: ${{ matrix.repos.kernelSource.defconfig }}
withKernelSU: ${{ matrix.repos.withKernelSU }}
ccache: ${{ matrix.repos.ccache }}
useAnykernel: ${{ matrix.repos.AnyKernel3.use }}
release: ${{ matrix.repos.AnyKernel3.release }}
steps:
- name: "⭐ Install prerequisites"
run: |
sudo apt-get update
sudo apt-get install -y build-essential bc gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi libssl-dev libfl-dev
sudo apt-get install -y curl git ftp lftp wget libarchive-tools ccache python2 python2-dev
sudo apt-get install -y zip unzip tar gzip bzip2 rar unrar
- name: "🚄 Create cache key from `repos`"
if: ${{ env.ccache == 'true' }}
id: ccache_key
run: |
ccache -o compression=false -o cache_dir=$HOME/.ccache
echo "CACHE_KEY=$(echo -n '${{ toJSON(matrix.repos) }}' | base64 -w 0 | cut -c -48)" >> $GITHUB_OUTPUT
- name: "🚅 Cache ccache files"
if: ${{ env.ccache == 'true' }}
uses: actions/cache@v3
with:
path: |
~/.ccache
${{ env.OUT_DIR }}
key: ccache-${{ env.KERNEL_NAME }}-${{ steps.ccache_key.outputs.CACHE_KEY }}-${{ env.builddate }}
restore-keys: |
ccache-${{ env.KERNEL_NAME }}-${{ steps.ccache_key.outputs.CACHE_KEY }}-${{ env.builddate }}
- name: "⏰ Setup Anykernel3"
env:
params: "${{ toJSON(matrix.repos.AnyKernel3) }}"
run: |
ANYKERNEL_REPO=$(echo $params | jq -r ".repo")
ANYKERNEL_BRANCH=$(echo $params | jq -r ".branch")
git clone --recursive --depth=1 -j $(nproc) --branch $ANYKERNEL_BRANCH $ANYKERNEL_REPO AnyKernel3
echo "🤔 Setup Anykernel3 => ($ANYKERNEL_REPO)"
- name: "🌟 Clone kernel source => (${{ env.KERNEL_REPO }})"
run: |
git clone --recursive --depth=1 -j $(nproc) --branch $KERNEL_BRANCH $KERNEL_REPO $KERNEL_NAME
echo "🤔 Clone kernel source => ($KERNEL_REPO)"
- name: "💫 Get toolchains"
env:
toolchains: "${{ toJSON(matrix.repos.toolchains) }}"
run: |
toolchains_num="$(echo $toolchains | jq 'length')"
echo "🤔 There is $toolchains_num defined toolchains."
for ((i=0;i<toolchains_num;i++)); do
toolchain_name=$(echo $toolchains | jq -r ".[$i].name")
# Github
toolchain_repo=$(echo $toolchains | jq -r ".[$i].repo")
toolchain_branch=$(echo $toolchains | jq -r ".[$i].branch")
# From archive
toolchain_url=$(echo $toolchains | jq -r ".[$i].url")
echo $toolchain_url
if [ -z "${toolchain_url:-}" ] || [ "$toolchain_url" = "null" ]; then
git clone --recursive --depth=1 -j $(nproc) --branch $toolchain_branch $toolchain_repo $toolchain_name
echo "🤔 Clone $toolchain_name => ($toolchain_repo)"
else
wget "$toolchain_url"
filename="${toolchain_url##*/}"
mkdir -p $toolchain_name
case "$filename" in
*.zip)
unzip -d $toolchain_name "$filename"
;;
*.tar)
tar xvf "$filename" -C $toolchain_name
;;
*.tar.gz)
tar zxvf "$filename" -C $toolchain_name
;;
*.rar)
unrar x "$filename" $toolchain_name
;;
*)
echo "unknown file type: $filename"
;;
esac
fi
jq -r ".[$i].binPath[] | tostring" <<< "$toolchains" | while read -r bin_path; do
echo "$WORKSPACE/$toolchain_name/$bin_path" >> $GITHUB_PATH
done
done
- name: "😎 Set args"
id: generate-args
env:
params: "${{ toJSON(matrix.repos.params) }}"
THREAD: $(nproc --all)
run: |
echo "🤔 PATH Variable: $PATH"
ARCH=$(echo $params | jq -r ".ARCH")
CC=$(echo $params | jq -r ".CC")
args="-j${{ env.THREAD }}"
if [ -n "${{ env.OUT_DIR }}" ]; then
mkdir -p ${{ env.OUT_DIR }} && args="$args O=${{ env.OUT_DIR }}"
fi
if [ -n "$ARCH" ]; then
args="$args ARCH=$ARCH"
fi
if [ -n "$CC" ]; then
if [[ "$CC" == *"/"* ]]; then
CC=${{ env.WORKSPACE }}/$CC
fi
if [ ${{ env.ccache }} = true ]; then
args="$args CC=\"ccache $CC\""
else
args="$args CC=$CC"
fi
fi
while read -r externalCommand; do
key=$(echo "$externalCommand" | cut -d= -f1)
value=$(echo "$externalCommand" | cut -d= -f2)
if [[ "$value" == *"/"* ]]; then
value="${{ env.WORKSPACE }}/$value"
fi
args="$args $key=$value"
done < <(jq -r '.externalCommand | to_entries[] | "\(.key)=\(.value)"' <<< "$params")
echo "🤔 $args"
echo "ARCH=$ARCH" >> $GITHUB_OUTPUT
echo "args=$args" >> $GITHUB_OUTPUT
- name: "😋 Update KernelSU"
working-directory: ${{ env.KERNEL_NAME }}
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
if: ${{ env.withKernelSU == 'true' }}
run: |
if [ -d "./KernelSU" ]; then
rm -rf "./KernelSU"
fi
if [ -d "./drivers/kernelsu" ]; then
rm -rf "./drivers/kernelsu"
fi
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s main
echo -e "CONFIG_KPROBES=y" >> arch/${{ env.arch }}/configs/${{ env.DEFCONFIG_NAME }}
echo -e "CONFIG_HAVE_KPROBES=y" >> arch/${{ env.arch }}/configs/${{ env.DEFCONFIG_NAME }}
echo -e "CONFIG_KPROBE_EVENTS=y" >> arch/${{ env.arch }}/configs/${{ env.DEFCONFIG_NAME }}
cat arch/${{ env.arch }}/configs/${{ env.DEFCONFIG_NAME }}
- name: "👍 Make defconfig"
working-directory: ${{ env.KERNEL_NAME }}
env:
args: ${{ steps.generate-args.outputs.args }}
arch: ${{ steps.generate-args.outputs.ARCH }}
run: |
echo "PATH Variable: $PATH"
make ${{ env.args }} ${{ env.DEFCONFIG_NAME }}
- name: "🎶 Build kernel"
working-directory: ${{ env.KERNEL_NAME }}
env:
args: ${{ steps.generate-args.outputs.args }}
run: |
echo "PATH Variable: $PATH"
make ${{ env.args }}
- name: "💛 Upload Image"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: Image-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image
if-no-files-found: ignore
retention-days: 7
- name: "💙 Upload Image.gz"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: Image.gz-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz
if-no-files-found: ignore
retention-days: 7
- name: "💜 Upload dtb"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: dtb-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtb
if-no-files-found: ignore
retention-days: 7
- name: "❤️ Upload dtbo.img"
uses: actions/upload-artifact@v3
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
with:
name: dtbo.img-${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}-${{ env.builddate }}
path: ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo.img
if-no-files-found: ignore
retention-days: 7
- name: "❤️ Pack AnyKernel3.zip"
if: ${{ env.useAnykernel == 'true' }}
env:
arch: ${{ steps.generate-args.outputs.ARCH }}
anykernel: "${{ env.WORKSPACE }}/${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}_${{ env.builddate }}"
run: |
ls -al
if [ -e "${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image ./AnyKernel3/
fi
if [ -e "${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/Image.gz ./AnyKernel3/
fi
if [ -e "${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo ./AnyKernel3/
fi
if [ -e "${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo.img" ]; then
cp -f ${{ env.OUT_DIR }}/arch/${{ env.arch }}/boot/dtbo.img ./AnyKernel3/
fi
cd AnyKernel3/
zip -q -r "${{ env.anykernel }}.zip" *
- name: "💾 Upload AnyKernel3 image => (${{ env.builddate }})"
uses: actions/upload-artifact@v3
if: ${{ env.useAnykernel == 'true' }}
with:
name: "${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}_${{ env.builddate }}"
path: AnyKernel3/*
- name: 🧧 Create GitHub Release => (${{ env.builddate }})
continue-on-error: true
uses: softprops/action-gh-release@v1
if: ${{ env.useAnykernel == 'true' && env.release == 'true' }}
with:
tag_name: v${{ env.builddate }}.${{ github.run_number }}
files: "${{ env.WORKSPACE }}/${{ env.KERNEL_DEVICE }}-${{ env.KERNEL_NAME }}_${{ env.builddate }}.zip"
generate_release_notes: true