build.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. name: Kernel Build Process
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. version:
  9. required: true
  10. type: string
  11. android_version:
  12. required: true
  13. type: string
  14. kernel_version:
  15. required: true
  16. type: string
  17. sublevel:
  18. required: true
  19. type: string
  20. os_patch_level:
  21. required: true
  22. type: string
  23. variant:
  24. required: false
  25. type: string
  26. feature_set:
  27. required: true
  28. type: string
  29. use_repo:
  30. required: false
  31. type: boolean
  32. jobs:
  33. build-gki:
  34. name: "${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} (${{ inputs.variant }})"
  35. runs-on: ubuntu-latest
  36. timeout-minutes: 60
  37. steps:
  38. - name: Checkout Repository
  39. uses: actions/checkout@v5
  40. - name: Free Disk Space
  41. if: false
  42. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  43. with:
  44. remove_android: true
  45. remove_dotnet: true
  46. remove_haskell: true
  47. remove_tool_cache: true
  48. #remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  49. #remove_packages_one_command: true
  50. remove_folders: "/usr/share/swift /usr/share/miniconda /usr/share/az* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/local/julia /usr/local/aws-cli /usr/local/aws-sam-cli /usr/share/gradle"
  51. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  52. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  53. testing: false
  54. - name: Setup more Swap (for LTO)
  55. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  56. with:
  57. swap-size-gb: 10 # 10-24 GB is common for heavy LTO
  58. # swap-space-path: /mnt/swapfile # optional
  59. - name: Setup Build Environment
  60. uses: ./.github/actions/setup-build-environment
  61. env:
  62. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  63. - name: Download Kernel Repository
  64. uses: ./.github/actions/download-kernel
  65. with:
  66. version: ${{ inputs.version }}
  67. android_version: ${{ inputs.android_version }}
  68. kernel_version: ${{ inputs.kernel_version }}
  69. os_patch_level: ${{ inputs.os_patch_level }}
  70. use_repo: ${{ inputs.use_repo }}
  71. - name: Extract Sublevel and Set File Name
  72. id: extract
  73. uses: ./.github/actions/extract-sublevel-file-name
  74. with:
  75. android_version: ${{ inputs.android_version }}
  76. kernel_version: ${{ inputs.kernel_version }}
  77. sublevel: ${{ inputs.sublevel }}
  78. os_patch_level: ${{ inputs.os_patch_level }}
  79. variant: ${{ inputs.variant }}
  80. - name: Kernel Fixes
  81. uses: ./.github/actions/kernel-fixes
  82. with:
  83. version: ${{ inputs.version }}
  84. android_version: ${{ inputs.android_version }}
  85. kernel_version: ${{ inputs.kernel_version }}
  86. sublevel: ${{ steps.extract.outputs.sublevel }}
  87. os_patch_level: ${{ inputs.os_patch_level }}
  88. - name: Setup KernelSU-Next
  89. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  90. uses: ./.github/actions/kernelsu
  91. - name: SUSFS
  92. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  93. uses: ./.github/actions/susfs
  94. with:
  95. version: ${{ inputs.version }}
  96. android_version: ${{ inputs.android_version }}
  97. kernel_version: ${{ inputs.kernel_version }}
  98. os_patch_level: ${{ inputs.os_patch_level }}
  99. sublevel: ${{ steps.extract.outputs.sublevel }}
  100. - name: Baseband Guard
  101. if: (contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL')
  102. uses: ./.github/actions/bbg
  103. - name: Setup Networking
  104. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  105. uses: ./.github/actions/networking
  106. with:
  107. kernel_version: ${{ inputs.kernel_version }}
  108. android_version: ${{ inputs.android_version }}
  109. - name: DroidSpaces-OSS Patches
  110. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  111. uses: ./.github/actions/droidspaces
  112. with:
  113. version: ${{ inputs.version }}
  114. kernel_version: ${{ inputs.kernel_version }}
  115. - name: Setup Misc Configs
  116. uses: ./.github/actions/misc
  117. with:
  118. version: ${{ inputs.version }}
  119. kernel_version: ${{ inputs.kernel_version }}
  120. android_version: ${{ inputs.android_version }}
  121. sublevel: ${{ steps.extract.outputs.sublevel }}
  122. variant: ${{ inputs.variant }}
  123. - name: Apply Module Check Bypass
  124. if: ${{ inputs.variant == 'Bypass' }}
  125. uses: ./.github/actions/module-check-bypass
  126. with:
  127. kernel_version: ${{ inputs.kernel_version }}
  128. - name: Apply Device-Specific Patches
  129. uses: ./.github/actions/apply-device-patches
  130. with:
  131. version: ${{ inputs.version }}
  132. kernel_version: ${{ inputs.kernel_version }}
  133. - name: Apply ABI Compare Bypass
  134. if: false
  135. working-directory: ${{ github.workspace }}/kernel
  136. run: |
  137. # ABI compare bypass per kernel/android version
  138. # Edit each block as needed per version
  139. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  140. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  141. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  142. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  143. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  144. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  145. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  146. perl -i -pe 's/^(\s*)return 1$/$1print("Who Cares? Bypassing Now!")\n$1return 0/g if /if missing_symbols:/../return 1/' build/kernel/abi/check_buildtime_symbol_protection.py
  147. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  148. perl -i -pe 's/^(\s*)return 1$/$1print("Who Cares? Bypassing Now!")\n$1return 0/g if /if missing_symbols:/../return 1/' build/kernel/abi/check_buildtime_symbol_protection.py
  149. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  150. perl -i -pe 's/^(\s*)return 1$/$1print("Who Cares? Bypassing Now!")\n$1return 0/g if /if missing_symbols:/../return 1/' build/kernel/abi/check_buildtime_symbol_protection.py
  151. fi
  152. - name: Apply Kernel Branding
  153. uses: ./.github/actions/apply-kernel-branding
  154. with:
  155. variant: ${{ inputs.variant }}
  156. kernel_version: ${{ inputs.kernel_version }}
  157. android_version: ${{ inputs.android_version }}
  158. sublevel: ${{ steps.extract.outputs.sublevel }}
  159. - name: Remove Protected Exports
  160. uses: ./.github/actions/remove-protected-exports
  161. - name: Clean Kernel Flags
  162. uses: ./.github/actions/clean-kernel-flags
  163. - name: Scan and collect patch rejects
  164. id: scan
  165. if: ${{ always() && inputs.variant == 'Normal' }}
  166. uses: ./.github/actions/scan-patch-rejects
  167. - name: Upload Rejects
  168. if: ${{ always() && inputs.variant == 'Normal' }}
  169. uses: actions/upload-artifact@v7
  170. with:
  171. name: ${{ steps.extract.outputs.file_name }}-Rejects
  172. path: patch-rejects/
  173. if-no-files-found: ignore
  174. compression-level: 9
  175. - name: 'Setup Cache and Build Environment'
  176. uses: ./.github/actions/cache-setup
  177. with:
  178. version: ${{ inputs.version }}
  179. android_version: ${{ inputs.android_version }}
  180. kernel_version: ${{ inputs.kernel_version }}
  181. sublevel: ${{ steps.extract.outputs.sublevel }}
  182. - name: Restore build caches (ccache, lto)
  183. id: restore-caches
  184. if: |
  185. inputs.version == 'android12-5.10' ||
  186. inputs.version == 'android13-5.10' ||
  187. inputs.version == 'android13-5.15'
  188. uses: ./.github/actions/cache-restore
  189. with:
  190. cache_paths: |
  191. /home/runner/.ccache
  192. /home/runner/.ld_cache
  193. cache_keys: |
  194. buildcache-${{ inputs.kernel_version }}
  195. buildcache-${{ inputs.kernel_version }}
  196. cache_buckets: |
  197. ccache-cache
  198. lto-cache
  199. compression_level: 9
  200. restore_keys: |
  201. buildcache-
  202. - name: Restore build caches (bazel, lto)
  203. id: restore-caches-bazel
  204. if: |
  205. inputs.version == 'android14-5.15' ||
  206. inputs.version == 'android14-6.1' ||
  207. inputs.version == 'android15-6.6' ||
  208. inputs.version == 'android16-6.12'
  209. uses: ./.github/actions/cache-restore
  210. with:
  211. cache_paths: |
  212. /home/runner/.cache/bazel
  213. /home/runner/.ld_cache
  214. cache_keys: |
  215. buildcache-${{ inputs.kernel_version }}
  216. buildcache-${{ inputs.kernel_version }}
  217. cache_buckets: |
  218. bazel-cache
  219. lto-cache
  220. compression_level: 9
  221. restore_keys: |
  222. buildcache-
  223. - name: Check cache hit
  224. run: |
  225. CACHE_HIT="${{ steps.restore-caches.outputs.cache-hit || steps.restore-caches-bazel.outputs.cache-hit }}"
  226. if [ "$CACHE_HIT" = "true" ]; then
  227. echo "✅ Cache HIT"
  228. CACHE_OUTPUT="${{ steps.restore-caches.outputs.cache-key || steps.restore-caches-bazel.outputs.cache-key }}"
  229. SIZE_OUTPUT="${{ steps.restore-caches.outputs.cache-size || steps.restore-caches-bazel.outputs.cache-size }}"
  230. IFS=',' read -ra KEYS <<< "$CACHE_OUTPUT"
  231. IFS=',' read -ra SIZES <<< "$SIZE_OUTPUT"
  232. for i in "${!KEYS[@]}"; do
  233. echo " [${i}] ${KEYS[$i]} (${SIZES[$i]})"
  234. done
  235. else
  236. echo "❌ No caches found - Fresh build"
  237. fi
  238. - name: Get Cache Stats
  239. uses: ./.github/actions/cache-stats
  240. with:
  241. clear_stats: true
  242. - name: Build Kernel
  243. env:
  244. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  245. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  246. uses: ./.github/actions/build-kernel
  247. - name: Get Cache Stats
  248. uses: ./.github/actions/cache-stats
  249. with:
  250. clear_stats: false
  251. - name: Save build caches (ccache, lto)
  252. if: |
  253. inputs.version == 'android12-5.10' ||
  254. inputs.version == 'android13-5.10' ||
  255. inputs.version == 'android13-5.15'
  256. uses: ./.github/actions/cache-save
  257. with:
  258. cache_paths: |
  259. /home/runner/.ccache
  260. /home/runner/.ld_cache
  261. cache_keys: |
  262. buildcache-${{ inputs.kernel_version }}
  263. buildcache-${{ inputs.kernel_version }}
  264. cache_buckets: |
  265. ccache-cache
  266. lto-cache
  267. compression_level: 9
  268. github_token: ${{ secrets.GITHUB_TOKEN }}
  269. - name: Save build caches (bazel, lto)
  270. if: |
  271. inputs.version == 'android14-5.15' ||
  272. inputs.version == 'android14-6.1' ||
  273. inputs.version == 'android15-6.6' ||
  274. inputs.version == 'android16-6.12'
  275. uses: ./.github/actions/cache-save
  276. with:
  277. cache_paths: |
  278. /home/runner/.cache/bazel
  279. /home/runner/.ld_cache
  280. cache_keys: |
  281. buildcache-${{ inputs.kernel_version }}
  282. buildcache-${{ inputs.kernel_version }}
  283. cache_buckets: |
  284. bazel-cache
  285. lto-cache
  286. compression_level: 9
  287. github_token: ${{ secrets.GITHUB_TOKEN }}
  288. - name: Create Bootimgs Folder and Build Boot Images
  289. uses: ./.github/actions/build-boot-images
  290. with:
  291. android_version: ${{ inputs.android_version }}
  292. kernel_version: ${{ inputs.kernel_version }}
  293. os_patch_level: ${{ inputs.os_patch_level }}
  294. file_name: ${{ steps.extract.outputs.file_name }}
  295. - name: Upload Boot Image (.img)
  296. uses: actions/upload-artifact@v7
  297. with:
  298. name: ${{ steps.extract.outputs.file_name }}-boot.img
  299. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot.img
  300. if-no-files-found: error
  301. archive: false
  302. - name: Upload Boot Image (.img.gz)
  303. uses: actions/upload-artifact@v7
  304. with:
  305. name: ${{ steps.extract.outputs.file_name }}-boot-gz.img
  306. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-gz.img
  307. if-no-files-found: error
  308. archive: false
  309. - name: Upload Boot Image (.img.lz4)
  310. uses: actions/upload-artifact@v7
  311. with:
  312. name: ${{ steps.extract.outputs.file_name }}-boot-lz4.img
  313. path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-lz4.img
  314. if-no-files-found: error
  315. archive: false
  316. - name: Prepare AnyKernel3 Zip
  317. uses: ./.github/actions/prepare-anykernel3
  318. with:
  319. android_version: ${{ inputs.android_version }}
  320. kernel_version: ${{ inputs.kernel_version }}
  321. - name: Upload Artifacts
  322. uses: actions/upload-artifact@v7
  323. with:
  324. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  325. path: ${{ github.workspace }}/AnyKernel3/**
  326. if-no-files-found: ignore
  327. compression-level: 9