-
Notifications
You must be signed in to change notification settings - Fork 7
/
circle.sh
executable file
·147 lines (127 loc) · 4.37 KB
/
circle.sh
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
#!/usr/bin/env bash
# Copyright (C) 2019-2020 Jago Gardiner (nysascape)
#
# Licensed under the Raphielscape Public License, Version 1.d (the "License");
# you may not use this file except in compliance with the License.
#
# CI build script
# Needed exports
export TELEGRAM_TOKEN=${BOT_API_TOKEN}
export ANYKERNEL=$(pwd)/anykernel3
# Avoid hardcoding things
KERNEL=nysa
DEFCONFIG=b1c1_defconfig
DEVICES_TO_COMPILE="Pixel 3/XL, Pixel 3a/XL"
DEVICE="Pixel3"
DEVICE_PRETTY="Pixel 3 (XL)"
CIPROVIDER=CircleCI
PARSE_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
PARSE_ORIGIN="$(git config --get remote.origin.url)"
COMMIT_POINT="$(git log --pretty=format:'%h : %s' -1)"
# Kernel groups
CI_CHANNEL=-1001308609321
TG_GROUP=-1001401121422
# Clang is annoying
PATH="${KERNELDIR}/clang/bin:${PATH}"
which clang
# Init submodules
git submodule update --init --recursive
# Function to replace defconfig versioning
setversioning() {
# For staging branch
KERNELTYPE=nightly
KERNELNAME="${KERNEL}-${DEVICE}-$(date +%y%m%d-%H%M)-Nightly"
sed -i "50s/.*/CONFIG_LOCALVERSION=\"-${KERNELNAME}\"/g" arch/arm64/configs/${DEFCONFIG}
# Export our new localversion and zipnames
export KERNELTYPE KERNELNAME
export TEMPZIPNAME="${KERNELNAME}-unsigned.zip"
export ZIPNAME="${KERNELNAME}.zip"
}
# Send to main group
tg_groupcast() {
"${TELEGRAM}" -c "${TG_GROUP}" -H \
"$(
for POST in "${@}"; do
echo "${POST}"
done
)"
}
# Send to channel
tg_channelcast() {
"${TELEGRAM}" -c "${CI_CHANNEL}" -H \
"$(
for POST in "${@}"; do
echo "${POST}"
done
)"
}
# Fix long kernel strings
kernelstringfix() {
git config --global user.name "nysascape"
git config --global user.email "[email protected]"
git add .
git commit -m "stop adding dirty"
}
# Make the kernel
makekernel() {
# Clean any old AnyKernel
rm -rf ${ANYKERNEL}
git clone https://github.com/nysascape/AnyKernel3 -b master anykernel3
kernelstringfix
make -j$(nproc --all) CC=clang CROSS_COMPILE=aarch64-linux-gnu- CROSS_COMPILE_ARM32=arm-linux-gnueabi- O=out ARCH=arm64 ${DEFCONFIG}
make -j$(nproc --all) CC=clang CROSS_COMPILE=aarch64-linux-gnu- CROSS_COMPILE_ARM32=arm-linux-gnueabi- O=out ARCH=arm64
# Check if compilation is done successfully.
if ! [ -f "${OUTDIR}"/arch/arm64/boot/Image.lz4-dtb ]; then
END=$(date +"%s")
DIFF=$(( END - START ))
echo -e "Kernel compilation failed, See buildlog to fix errors"
tg_channelcast "Build for ${DEVICE_PRETTY} <b>failed</b> in $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! Check ${CIPROVIDER} for errors!"
tg_groupcast "Build for ${DEVICE_PRETTY} <b>failed</b> in $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! Check ${CIPROVIDER} for errors @nysascape!"
exit 1
fi
}
# Ship the compiled kernel
shipkernel() {
# Copy compiled kernel
cp "${OUTDIR}"/arch/arm64/boot/Image.lz4-dtb "${ANYKERNEL}"/
# Zip the kernel, or fail
cd "${ANYKERNEL}" || exit
zip -r9 "${TEMPZIPNAME}" *
# Sign the zip before sending it to Telegram
curl -sLo zipsigner-3.0.jar https://raw.githubusercontent.com/baalajimaestro/AnyKernel2/master/zipsigner-3.0.jar
java -jar zipsigner-3.0.jar ${TEMPZIPNAME} ${ZIPNAME}
# Ship it to the CI channel
"${TELEGRAM}" -f "$ZIPNAME" -c "${CI_CHANNEL}"
# Go back for any extra builds
cd ..
}
gcast() {
tg_groupcast "${DEVICE} kernel compilation clocked at $(date +%Y%m%d-%H%M)!"
}
ccast() {
tg_channelcast "Device(s): <b>${DEVICES_TO_COMPILE}</b>" \
"Kernel: <code>${KERNEL}, release ${KERNELTYPE}</code>" \
"Compiler: <code>${COMPILER_STRING}</code>" \
"Branch: <code>${PARSE_BRANCH}</code>" \
"Commit point: <code>${COMMIT_POINT}</code>" \
"Clocked at: <code>$(date +%Y%m%d-%H%M)</code>"
}
## Start the kernel buildflow ##
setversioning
ccast
tg_channelcast "Compiling ${DEVICE_PRETTY}..."
gcast
START=$(date +"%s")
makekernel || exit 1
shipkernel
DEVICE="Pixel3a"
DEVICE_PRETTY="Pixel 3a (XL)"
DEFCONFIG=b4s4_defconfig
setversioning
tg_channelcast "Compiling ${DEVICE_PRETTY}..."
makekernel || exit 1
shipkernel
END=$(date +"%s")
DIFF=$(( END - START ))
tg_channelcast "Build(s) for ${DEVICES_TO_COMPILE} with ${COMPILER_STRING} took $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)!"
tg_groupcast "Build(s) for ${DEVICES_TO_COMPILE} with ${COMPILER_STRING} took $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)!"