build.yml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. name: Build Script
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. android_version:
  9. required: true
  10. type: string
  11. kernel_version:
  12. required: true
  13. type: string
  14. sub_level:
  15. required: true
  16. type: string
  17. os_patch_level:
  18. required: true
  19. type: string
  20. kernelsu_variant:
  21. required: true
  22. type: string
  23. kernelsu_branch:
  24. required: true
  25. type: string
  26. kernelsu_branch_other:
  27. required: false
  28. type: string
  29. revision:
  30. required: false
  31. type: string
  32. jobs:
  33. build-gki:
  34. runs-on: ubuntu-latest
  35. timeout-minutes: 120
  36. env:
  37. CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
  38. CCACHE_NOHASHDIR: "true"
  39. CCACHE_HARDLINK: "true"
  40. steps:
  41. - name: Maximize Build Space
  42. uses: AdityaGarg8/remove-unwanted-software@v5
  43. with:
  44. remove-dotnet: 'true' # Frees ~2 GB
  45. remove-android: 'true' # Frees ~9 GB
  46. remove-haskell: 'true' # Frees ~5.2 GB
  47. remove-codeql: 'true' # Frees ~5.4 GB
  48. remove-docker-images: 'true' # Frees ~3.2 GB
  49. remove-large-packages: 'true' # Frees ~3.1 GB
  50. remove-swapfile: 'true' # Frees ~4 GB
  51. remove-cached-tools: 'false' # Avoid unless confirmed safe
  52. verbose: 'true' # Enable detailed logging
  53. - name: Set CONFIG Environment Variable
  54. run: |
  55. # Set CONFIG dynamically based on inputs values
  56. CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
  57. # Set CONFIG as an environment variable for future steps
  58. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  59. echo "CONFIG set to: $CONFIG"
  60. - name: Install ccache
  61. run: sudo apt update && sudo apt install -y ccache
  62. - name: Set up ccache
  63. run: |
  64. mkdir -p ~/.cache/bazel
  65. ccache --version
  66. ccache --max-size=2G
  67. ccache --set-config=compression=true
  68. echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
  69. - name: Restore ccache from cache
  70. uses: actions/cache@v4
  71. with:
  72. path: ~/.ccache
  73. key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}-ccache-${{ github.sha }}
  74. restore-keys: |
  75. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}-ccache-
  76. - name: Cache toolchain
  77. id: cache-toolchain
  78. uses: actions/cache@v4
  79. with:
  80. path: |
  81. kernel-build-tools
  82. mkbootimg
  83. key: toolchain-${{ runner.os }}-v1
  84. - name: Download toolchain (if cache not found)
  85. if: steps.cache-toolchain.outputs.cache-hit != 'true'
  86. run: |
  87. AOSP_MIRROR=https://android.googlesource.com
  88. BRANCH=main-kernel-build-2024
  89. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools
  90. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg
  91. - name: Set environment variables
  92. run: |
  93. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  94. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  95. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  96. - name: Set boot sign key
  97. env:
  98. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  99. run: |
  100. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  101. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  102. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  103. else
  104. echo "BOOT_SIGN_KEY is not set. Using AOSP sign key..."
  105. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  106. fi
  107. - name: Install Repo
  108. run: |
  109. mkdir -p ./git-repo
  110. echo "Downloading repo tool..."
  111. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  112. chmod a+rx ./git-repo/repo
  113. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  114. - name: Clone AnyKernel3 and Other Dependencies
  115. run: |
  116. echo "Cloning AnyKernel3 and other dependencies..."
  117. ANYKERNEL_BRANCH="gki-2.0"
  118. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  119. echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH"
  120. echo "Using branch for SUSFS: $SUSFS_BRANCH"
  121. git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  122. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  123. git clone https://github.com/WildPlusKernel/kernel_patches.git
  124. - name: Check Disk Space Before Sync
  125. run: |
  126. echo "Disk space before kernel source sync:"
  127. df -h
  128. - name: Initialize and Sync Kernel Source
  129. run: |
  130. echo "Creating folder for configuration: $CONFIG..."
  131. mkdir -p "$CONFIG"
  132. cd "$CONFIG"
  133. echo "Initializing and syncing kernel source..."
  134. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  135. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  136. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  137. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  138. if grep -q deprecated <<< $REMOTE_BRANCH; then
  139. echo "Found deprecated branch: $FORMATTED_BRANCH"
  140. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  141. fi
  142. $REPO --version
  143. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  144. - name: Determine the branch for KernelSU
  145. run: |
  146. case "${{ inputs.kernelsu_branch }}" in
  147. "Stable")
  148. echo "BRANCH=-" >> $GITHUB_ENV
  149. ;;
  150. "Dev")
  151. if [[ "${{ inputs.kernelsu_variant }}" =~ ^(KSU|MKSU)$ ]]; then
  152. echo "BRANCH=-s main" >> $GITHUB_ENV
  153. elif [[ "${{ inputs.kernelsu_variant }}" == "NEXT" ]]; then
  154. echo "BRANCH=-s next" >> $GITHUB_ENV
  155. elif [[ "${{ inputs.kernelsu_variant }}" == "WILD" ]]; then
  156. echo "BRANCH=-s wild" >> $GITHUB_ENV
  157. fi
  158. ;;
  159. "Other")
  160. if [[ -n "${{ inputs.kernelsu_branch_other }}" ]]; then
  161. echo "BRANCH=-s ${{ inputs.kernelsu_branch_other }}" >> $GITHUB_ENV
  162. else
  163. echo "Error: Custom branch not provided for 'Other'" >&2
  164. exit 1
  165. fi
  166. ;;
  167. esac
  168. - name: Add KernelSU
  169. run: |
  170. echo "Changing to configuration directory: $CONFIG..."
  171. cd "$CONFIG"
  172. case "${{ inputs.kernelsu_variant }}" in
  173. "WILD")
  174. echo "Adding Wild KSU..."
  175. curl -LSs "https://raw.githubusercontent.com/WildKernels/Wild_KSU/wild/kernel/setup.sh" | bash ${{ env.BRANCH }}
  176. ;;
  177. "KSU")
  178. echo "Adding KernelSU Official..."
  179. curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  180. ;;
  181. "NEXT")
  182. echo "Adding KernelSU Next..."
  183. curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash ${{ env.BRANCH }}
  184. ;;
  185. "MKSU")
  186. echo "Adding KernelSU MKSU..."
  187. curl -LSs "https://raw.githubusercontent.com/5ec1cff/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  188. ;;
  189. esac
  190. - name: Apply SUSFS Patches for KernelSU Variants
  191. run: |
  192. echo "Changing to configuration directory: $CONFIG..."
  193. cd "$CONFIG"
  194. echo "Applying SUSFS patches..."
  195. # Copy SUSFS patches
  196. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
  197. cd common
  198. patch -p1 --forward --fuzz=3 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch
  199. cd ..
  200. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  201. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  202. case "${{ inputs.kernelsu_variant }}" in
  203. "WILD")
  204. echo "Applying SUSFS patches for Official KernelSU..."
  205. cd ./Wild_KSU
  206. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  207. patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch || true
  208. cp ../../kernel_patches/wild/fix_core_hook.c.patch ./
  209. patch -p1 --forward --fuzz=3 < fix_core_hook.c.patch
  210. cp ../../kernel_patches/wild/fix_selinux.c.patch ./
  211. patch -p1 --forward --fuzz=3 < fix_selinux.c.patch
  212. cp ../../kernel_patches/wild/fix_ksud.c.patch ./
  213. patch -p1 --forward --fuzz=3 < fix_ksud.c.patch
  214. cp ../../kernel_patches/wild/fix_sucompat.c.patch ./
  215. patch -p1 --forward --fuzz=3 < fix_sucompat.c.patch
  216. sed -i '/bool ksu_devpts_hook = false;/d' ./kernel/sucompat.c
  217. ;;
  218. "KSU")
  219. echo "Applying SUSFS patches for Official KernelSU..."
  220. cd ./KernelSU
  221. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  222. patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch
  223. ;;
  224. "NEXT")
  225. echo "Applying SUSFS patches for KernelSU Next..."
  226. cd ./KernelSU-Next
  227. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  228. patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch || true
  229. cp ../../kernel_patches/next/fix_apk_sign.c.patch ./
  230. patch -p1 --forward --fuzz=3 < fix_apk_sign.c.patch
  231. cp ../../kernel_patches/next/fix_core_hook.c.patch ./
  232. patch -p1 --forward --fuzz=3 < fix_core_hook.c.patch
  233. cp ../../kernel_patches/next/fix_selinux.c.patch ./
  234. patch -p1 --forward --fuzz=3 < fix_selinux.c.patch
  235. cp ../../kernel_patches/next/fix_ksud.c.patch ./
  236. patch -p1 --forward --fuzz=3 < fix_ksud.c.patch
  237. #cp ../../kernel_patches/next/fix_sucompat.c.patch ./
  238. #patch -p1 --forward --fuzz=3 < fix_sucompat.c.patch
  239. #sed -i '/bool ksu_devpts_hook = false;/d' ./kernel/sucompat.c
  240. ;;
  241. "MKSU")
  242. echo "Applying SUSFS patches for MKSU..."
  243. cd ./KernelSU
  244. cp ../../kernel_patches/next/0001_susfs_157_for_ksunext.patch ./
  245. patch -p1 --forward --fuzz=3 < 0001_susfs_157_for_ksunext.patch
  246. ;;
  247. esac
  248. - name: Getting KernelSU Version
  249. run: |
  250. echo "Changing to configuration directory: $CONFIG..."
  251. cd "$CONFIG"
  252. case "${{ inputs.kernelsu_variant }}" in
  253. "WILD")
  254. echo "Applying SUSFS patches for Official KernelSU..."
  255. cd ./Wild_KSU
  256. BASE_VERSION=10200
  257. ;;
  258. "KSU")
  259. echo "Applying SUSFS patches for Official KernelSU..."
  260. cd ./KernelSU
  261. BASE_VERSION=10200
  262. ;;
  263. "NEXT")
  264. cd ./KernelSU-Next
  265. BASE_VERSION=10200
  266. ;;
  267. "MKSU")
  268. ;;
  269. esac
  270. cd ./kernel
  271. KSU_VERSION=$(expr $(/usr/bin/git rev-list --count HEAD) "+" $BASE_VERSION)
  272. echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
  273. - name: Apply Hooks Patches
  274. run: |
  275. echo "Changing to configuration directory: $CONFIG..."
  276. cd "$CONFIG/common"
  277. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ]; then
  278. echo "Applying hooks for KernelSU-Next..."
  279. cp ../../kernel_patches/next/scope_min_manual_hooks_v1.4.patch ./
  280. patch -p1 -F 3 < scope_min_manual_hooks_v1.4.patch
  281. elif [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  282. echo "Applying hooks for Wild KSU..."
  283. cp ../../kernel_patches/wild/syscall_hooks.patch ./
  284. patch -p1 -F 3 < syscall_hooks.patch
  285. fi
  286. - name: Apply Hide Stuff Patches
  287. run: |
  288. echo "Changing to configuration directory: $CONFIG..."
  289. cd "$CONFIG/common"
  290. cp ../../kernel_patches/69_hide_stuff.patch ./
  291. patch -p1 -F 3 < 69_hide_stuff.patch
  292. - name: Add All Managers
  293. run: |
  294. cd "$CONFIG"
  295. case "${{ inputs.kernelsu_variant }}" in
  296. "WILD")
  297. echo "Applying Manager patch for Wild KSU..."
  298. cd Wild_KSU
  299. cp ../../kernel_patches/wild/manager.patch ./
  300. ;;
  301. "KSU")
  302. echo "Applying Manager patch for Official KernelSU..."
  303. cd KernelSU
  304. cp ../../kernel_patches/wild/manager.patch ./
  305. ;;
  306. "NEXT")
  307. echo "Applying Manager patch for KernelSU Next..."
  308. cd KernelSU-Next
  309. cp ../../kernel_patches/next/manager.patch ./
  310. ;;
  311. "MKSU")
  312. echo "Applying Manager patch for MKSU..."
  313. #cp ../kernel_patches/mksu/manager.patch .//
  314. ;;
  315. esac
  316. patch -p1 --fuzz=3 < manager.patch || echo "No Manager Patch"
  317. - name: Add Configuration Settings
  318. run: |
  319. echo "Changing to configuration directory: $CONFIG..."
  320. cd "$CONFIG"
  321. echo "Adding configuration settings to gki_defconfig..."
  322. # Add KSU configuration settings
  323. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  324. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ] || [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  325. echo "CONFIG_KSU_KPROBES_HOOK=n" >> ./common/arch/arm64/configs/gki_defconfig
  326. fi
  327. # Add additional tmpfs config setting
  328. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  329. echo "CONFIG_TMPFS_POSIX_ACL=y" >> ./common/arch/arm64/configs/gki_defconfig
  330. # Add additional config setting
  331. echo "CONFIG_IP_NF_TARGET_TTL=y" >> ./common/arch/arm64/configs/gki_defconfig
  332. echo "CONFIG_IP6_NF_TARGET_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  333. echo "CONFIG_IP6_NF_MATCH_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  334. # Add BBR Config
  335. echo "CONFIG_TCP_CONG_ADVANCED=y" >> ./common/arch/arm64/configs/gki_defconfig
  336. echo "CONFIG_TCP_CONG_BBR=y" >> ./common/arch/arm64/configs/gki_defconfig
  337. echo "CONFIG_NET_SCH_FQ=y" >> ./common/arch/arm64/configs/gki_defconfig
  338. echo "CONFIG_TCP_CONG_BIC=n" >> ./common/arch/arm64/configs/gki_defconfig
  339. echo "CONFIG_TCP_CONG_WESTWOOD=n" >> ./common/arch/arm64/configs/gki_defconfig
  340. echo "CONFIG_TCP_CONG_HTCP=n" >> ./common/arch/arm64/configs/gki_defconfig
  341. # Remove check_defconfig
  342. sed -i 's/check_defconfig//' ./common/build.config.gki
  343. - name: Add SUSFS Configuration Settings
  344. run: |
  345. echo "Changing to configuration directory: $CONFIG..."
  346. cd "$CONFIG"
  347. # Add SUSFS configuration settings
  348. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  349. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  350. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  351. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  352. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  353. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  354. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  355. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> ./common/arch/arm64/configs/gki_defconfig
  356. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  357. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  358. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  359. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  360. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  361. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  362. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  363. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ] || [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  364. echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
  365. else
  366. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  367. fi
  368. - name: Change Kernel Name
  369. run: |
  370. cd "$CONFIG"
  371. # modify UTS_VERSION
  372. perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT Sat Apr 20 04:20:00 UTC 2024"}' ./common/scripts/mkcompile_h
  373. sed -i '$s|echo "\$res"|echo "\$res-${{ inputs.kernelsu_variant }}-v$KSUVER-SUSFS-v1.5.7-WildKernels"|' ./common/scripts/setlocalversion
  374. if [ -f "build/build.sh" ]; then
  375. sed -i 's/-dirty//' ./common/scripts/setlocalversion
  376. else
  377. sed -i '/^[[:space:]]*"protected_exports_list"[[:space:]]*:[[:space:]]*"android\/abi_gki_protected_exports_aarch64",$/d' ./common/BUILD.bazel
  378. rm -rf ./common/android/abi_gki_protected_exports_*
  379. sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl
  380. sed -E -i "/^CONFIG_LOCALVERSION=/ s/(.*)\"/\\1-${{ inputs.kernelsu_variant }}-v$KSUVER-SUSFS-v1.5.7-WildKernels\"/" ./common/arch/arm64/configs/gki_defconfig
  381. fi
  382. - name: Build
  383. run : |
  384. set -e
  385. set -x
  386. cd "$CONFIG"
  387. echo "Building the kernel..."
  388. if [ -f "build/build.sh" ]; then
  389. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh CC="/usr/bin/ccache clang" || exit 1
  390. else
  391. tools/bazel build --disk_cache=/home/runner/.cache/bazel --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
  392. fi
  393. ccache --show-stats
  394. - name: Create Bootimgs Folder and Copy Images for Android 12/13
  395. if: ${{ inputs.android_version == 'android12' || inputs.android_version == 'android13' }}
  396. run: |
  397. mkdir bootimgs
  398. echo "Creating bootimgs folder and copying images..."
  399. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./bootimgs
  400. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./bootimgs
  401. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./
  402. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./
  403. # Create gzip of the Image file
  404. gzip -n -k -f -9 ./Image > ./Image.gz
  405. - name: Create Bootimgs Folder and Copy Images for Android 14/15
  406. if: ${{ inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  407. run: |
  408. mkdir bootimgs
  409. echo "Creating bootimgs folder and copying images..."
  410. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
  411. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  412. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./
  413. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./
  414. # Create gzip of the Image file
  415. gzip -n -k -f -9 ./Image > ./Image.gz
  416. - name: Create ZIP Files for Different Formats
  417. run: |
  418. echo "Creating zip files for all formats..."
  419. cd ./AnyKernel3
  420. # Create and upload zip for each format
  421. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3.zip"
  422. echo "Creating zip file: $ZIP_NAME..."
  423. mv ../Image ./Image
  424. zip -r "../$ZIP_NAME" ./*
  425. rm ./Image
  426. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-lz4.zip"
  427. echo "Creating zip file: $ZIP_NAME..."
  428. mv ../Image.lz4 ./Image.lz4
  429. zip -r "../$ZIP_NAME" ./*
  430. rm ./Image.lz4
  431. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-gz.zip"
  432. echo "Creating zip file: $ZIP_NAME..."
  433. mv ../Image.gz ./Image.gz
  434. zip -r "../$ZIP_NAME" ./*
  435. rm ./Image.gz
  436. - name: Android 12 boot image build script
  437. if: ${{ inputs.android_version == 'android12' }}
  438. run: |
  439. echo "Changing to configuration directory: $CONFIG..."
  440. cd bootimgs
  441. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_"${{ inputs.revision }}".zip
  442. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  443. # Check if the GKI URL is available
  444. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  445. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  446. if [ "$status" = "200" ]; then
  447. echo "[+] Downloading from GKI_URL"
  448. curl -Lo gki-kernel.zip "$GKI_URL"
  449. else
  450. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  451. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  452. fi
  453. # Unzip the downloaded kernel and remove the zip
  454. echo "Unzipping the downloaded kernel..."
  455. unzip gki-kernel.zip && rm gki-kernel.zip
  456. echo "Unpacking boot.img..."
  457. FULL_PATH=$(pwd)/boot-5.10.img
  458. echo "Unpacking using: $FULL_PATH"
  459. echo "Running unpack_bootimg.py..."
  460. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  461. # Create gzip of the Image file
  462. gzip -n -k -f -9 ./Image > ./Image.gz
  463. echo "Building boot.img"
  464. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  465. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  466. cp ./boot.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  467. echo "Building boot-gz.img"
  468. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  469. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  470. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  471. echo "Building boot-lz4.img"
  472. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  473. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  474. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  475. - name: Android 13/14/15 boot image build script
  476. if: ${{ inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  477. run: |
  478. cd bootimgs
  479. # Create gzip of the Image file
  480. gzip -n -k -f -9 ./Image > ./Image.gz
  481. echo "Building boot.img"
  482. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  483. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  484. cp ./boot.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  485. echo "Building boot-gz.img"
  486. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  487. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  488. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  489. echo "Building boot-lz4.img"
  490. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  491. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  492. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  493. - name: Compress all img files with gzip
  494. run: |
  495. for image in *.img; do
  496. gzip -vnf9 "$image"
  497. done
  498. - name: Upload Build Artifacts
  499. uses: actions/upload-artifact@v4
  500. with:
  501. name: ${{ inputs.kernelsu_variant }}-kernel-${{ env.CONFIG }}
  502. path: |
  503. *.zip
  504. *.img.gz
  505. *Image*