build.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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: Set Build Timestamp from Kernel Commit
  72. shell: bash
  73. run: |
  74. set -x
  75. # Verify kernel/common exists and is a git repo
  76. if [ ! -d "${{ github.workspace }}/kernel/common" ]; then
  77. echo "ERROR: kernel/common directory does not exist!"
  78. echo "Contents of kernel/:"
  79. ls -la "${{ github.workspace }}/kernel/" || true
  80. exit 1
  81. fi
  82. if [ ! -d "${{ github.workspace }}/kernel/common/.git" ]; then
  83. echo "ERROR: kernel/common is not a git repository!"
  84. exit 1
  85. fi
  86. # Try to get commit timestamp
  87. SOURCE_DATE_EPOCH=$(git -C "${{ github.workspace }}/kernel/common" log -1 --format=%ct 2>&1)
  88. if [ -z "$SOURCE_DATE_EPOCH" ] || [ "$SOURCE_DATE_EPOCH" = "0" ]; then
  89. echo "WARNING: Failed to get commit timestamp from kernel/common, using current time"
  90. SOURCE_DATE_EPOCH=$(date -u +%s)
  91. fi
  92. echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
  93. echo "KBUILD_BUILD_TIMESTAMP=$(date -u -d @${SOURCE_DATE_EPOCH} '+%a %b %d %H:%M:%S UTC %Y')" >> $GITHUB_ENV
  94. echo "Build timestamp set to: $(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%d %H:%M:%S UTC') (epoch: $SOURCE_DATE_EPOCH)"
  95. - name: Extract Sublevel and Set File Name
  96. id: extract
  97. uses: ./.github/actions/extract-sublevel-file-name
  98. with:
  99. android_version: ${{ inputs.android_version }}
  100. kernel_version: ${{ inputs.kernel_version }}
  101. sublevel: ${{ inputs.sublevel }}
  102. os_patch_level: ${{ inputs.os_patch_level }}
  103. variant: ${{ inputs.variant }}
  104. - name: Kernel Fixes
  105. uses: ./.github/actions/kernel-fixes
  106. with:
  107. version: ${{ inputs.version }}
  108. android_version: ${{ inputs.android_version }}
  109. kernel_version: ${{ inputs.kernel_version }}
  110. sublevel: ${{ steps.extract.outputs.sublevel }}
  111. os_patch_level: ${{ inputs.os_patch_level }}
  112. - name: Setup KernelSU-Next
  113. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  114. uses: ./.github/actions/kernelsu
  115. - name: SUSFS
  116. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  117. uses: ./.github/actions/susfs
  118. with:
  119. version: ${{ inputs.version }}
  120. android_version: ${{ inputs.android_version }}
  121. kernel_version: ${{ inputs.kernel_version }}
  122. os_patch_level: ${{ inputs.os_patch_level }}
  123. sublevel: ${{ steps.extract.outputs.sublevel }}
  124. - name: Baseband Guard
  125. if: (contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL')
  126. uses: ./.github/actions/bbg
  127. - name: Setup Networking
  128. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  129. uses: ./.github/actions/networking
  130. with:
  131. kernel_version: ${{ inputs.kernel_version }}
  132. android_version: ${{ inputs.android_version }}
  133. - name: DroidSpaces-OSS Patches
  134. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  135. uses: ./.github/actions/droidspaces
  136. with:
  137. version: ${{ inputs.version }}
  138. kernel_version: ${{ inputs.kernel_version }}
  139. - name: Setup Misc Configs
  140. uses: ./.github/actions/misc
  141. with:
  142. version: ${{ inputs.version }}
  143. kernel_version: ${{ inputs.kernel_version }}
  144. android_version: ${{ inputs.android_version }}
  145. sublevel: ${{ steps.extract.outputs.sublevel }}
  146. variant: ${{ inputs.variant }}
  147. - name: Apply Module Check Bypass
  148. if: ${{ inputs.variant == 'Bypass' }}
  149. uses: ./.github/actions/module-check-bypass
  150. with:
  151. kernel_version: ${{ inputs.kernel_version }}
  152. # - name: Apply Device-Specific Patches
  153. # uses: ./.github/actions/apply-device-patches
  154. # with:
  155. # version: ${{ inputs.version }}
  156. # kernel_version: ${{ inputs.kernel_version }}
  157. - name: Apply ABI Compare Bypass
  158. if: false
  159. working-directory: ${{ github.workspace }}/kernel
  160. run: |
  161. # ABI compare bypass per kernel/android version
  162. # Edit each block as needed per version
  163. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  164. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  165. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  166. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  167. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  168. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  169. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  170. 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
  171. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  172. 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
  173. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  174. 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
  175. fi
  176. - name: Apply Kernel Branding
  177. uses: ./.github/actions/apply-kernel-branding
  178. with:
  179. variant: ${{ inputs.variant }}
  180. kernel_version: ${{ inputs.kernel_version }}
  181. android_version: ${{ inputs.android_version }}
  182. sublevel: ${{ steps.extract.outputs.sublevel }}
  183. - name: Remove Protected Exports
  184. uses: ./.github/actions/remove-protected-exports
  185. - name: Clean Kernel Flags
  186. uses: ./.github/actions/clean-kernel-flags
  187. - name: Scan and collect patch rejects
  188. id: scan
  189. if: ${{ always() && inputs.variant == 'Normal' }}
  190. uses: ./.github/actions/scan-patch-rejects
  191. - name: Upload Rejects
  192. if: ${{ always() && inputs.variant == 'Normal' }}
  193. uses: actions/upload-artifact@v7
  194. with:
  195. name: ${{ steps.extract.outputs.file_name }}-Rejects
  196. path: patch-rejects/
  197. if-no-files-found: ignore
  198. compression-level: 9
  199. - name: 'Setup Cache and Build Environment'
  200. uses: ./.github/actions/cache-setup
  201. with:
  202. version: ${{ inputs.version }}
  203. android_version: ${{ inputs.android_version }}
  204. kernel_version: ${{ inputs.kernel_version }}
  205. sublevel: ${{ steps.extract.outputs.sublevel }}
  206. - name: Restore ccache
  207. id: restore-ccache
  208. if: |
  209. inputs.version == 'android12-5.10' ||
  210. inputs.version == 'android13-5.10' ||
  211. inputs.version == 'android13-5.15'
  212. uses: ./.github/actions/cache-restore
  213. with:
  214. cache_path: /home/runner/.ccache
  215. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  216. cache_bucket: ccache-cache
  217. compression_level: 9
  218. restore_keys: |
  219. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  220. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  221. - name: Restore lto-cache (ccache versions)
  222. id: restore-lto-ccache
  223. if: |
  224. inputs.version == 'android12-5.10' ||
  225. inputs.version == 'android13-5.10' ||
  226. inputs.version == 'android13-5.15'
  227. uses: ./.github/actions/cache-restore
  228. with:
  229. cache_path: /home/runner/.ld_cache
  230. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  231. cache_bucket: lto-cache
  232. compression_level: 9
  233. restore_keys: |
  234. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  235. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  236. - name: Restore bazel-cache
  237. id: restore-bazel
  238. if: |
  239. inputs.version == 'android14-5.15' ||
  240. inputs.version == 'android14-6.1' ||
  241. inputs.version == 'android15-6.6' ||
  242. inputs.version == 'android16-6.12'
  243. uses: ./.github/actions/cache-restore
  244. with:
  245. cache_path: /home/runner/.cache/bazel
  246. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  247. cache_bucket: bazel-cache
  248. compression_level: 9
  249. restore_keys: |
  250. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  251. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  252. - name: Restore lto-cache (bazel versions)
  253. id: restore-lto-bazel
  254. if: |
  255. inputs.version == 'android14-5.15' ||
  256. inputs.version == 'android14-6.1' ||
  257. inputs.version == 'android15-6.6' ||
  258. inputs.version == 'android16-6.12'
  259. uses: ./.github/actions/cache-restore
  260. with:
  261. cache_path: /home/runner/.ld_cache
  262. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  263. cache_bucket: lto-cache
  264. compression_level: 9
  265. restore_keys: |
  266. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  267. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  268. - name: Check cache hit
  269. run: |
  270. echo "Cache restore status:" CCACHE_HIT="${{ steps.restore-ccache.outputs.cache-hit || 'skipped' }}"
  271. LTO_CCACHE_HIT="${{ steps.restore-lto-ccache.outputs.cache-hit || 'skipped' }}"
  272. BAZEL_HIT="${{ steps.restore-bazel.outputs.cache-hit || 'skipped' }}"
  273. LTO_BAZEL_HIT="${{ steps.restore-lto-bazel.outputs.cache-hit || 'skipped' }}"
  274. echo " ccache: $CCACHE_HIT"
  275. echo " lto (ccache versions): $LTO_CCACHE_HIT"
  276. echo " bazel: $BAZEL_HIT"
  277. echo " lto (bazel versions): $LTO_BAZEL_HIT"
  278. - name: Get Cache Stats
  279. uses: ./.github/actions/cache-stats
  280. with:
  281. clear_stats: true
  282. - name: Build Kernel
  283. env:
  284. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  285. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  286. uses: ./.github/actions/build-kernel
  287. - name: Get Cache Stats
  288. uses: ./.github/actions/cache-stats
  289. with:
  290. clear_stats: false
  291. - name: Save ccache
  292. if: |
  293. inputs.version == 'android12-5.10' ||
  294. inputs.version == 'android13-5.10' ||
  295. inputs.version == 'android13-5.15'
  296. uses: ./.github/actions/cache-save
  297. with:
  298. cache_path: /home/runner/.ccache
  299. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  300. cache_bucket: ccache-cache
  301. compression_level: 9
  302. github_token: ${{ secrets.GITHUB_TOKEN }}
  303. - name: Save lto-cache (ccache versions)
  304. if: |
  305. inputs.version == 'android12-5.10' ||
  306. inputs.version == 'android13-5.10' ||
  307. inputs.version == 'android13-5.15'
  308. uses: ./.github/actions/cache-save
  309. with:
  310. cache_path: /home/runner/.ld_cache
  311. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  312. cache_bucket: lto-cache
  313. compression_level: 9
  314. github_token: ${{ secrets.GITHUB_TOKEN }}
  315. - name: Save bazel-cache
  316. if: |
  317. inputs.version == 'android14-5.15' ||
  318. inputs.version == 'android14-6.1' ||
  319. inputs.version == 'android15-6.6' ||
  320. inputs.version == 'android16-6.12'
  321. uses: ./.github/actions/cache-save
  322. with:
  323. cache_path: /home/runner/.cache/bazel
  324. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  325. cache_bucket: bazel-cache
  326. compression_level: 9
  327. github_token: ${{ secrets.GITHUB_TOKEN }}
  328. - name: Save lto-cache (bazel versions)
  329. if: |
  330. inputs.version == 'android14-5.15' ||
  331. inputs.version == 'android14-6.1' ||
  332. inputs.version == 'android15-6.6' ||
  333. inputs.version == 'android16-6.12'
  334. uses: ./.github/actions/cache-save
  335. with:
  336. cache_path: /home/runner/.ld_cache
  337. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  338. cache_bucket: lto-cache
  339. compression_level: 9
  340. github_token: ${{ secrets.GITHUB_TOKEN }}
  341. # Boot image building and packaging are disabled for now.
  342. # Uncomment this block later if you want to generate and upload boot artifacts again.
  343. # - name: Create Bootimgs Folder and Build Boot Images
  344. # uses: ./.github/actions/build-boot-images
  345. # with:
  346. # android_version: ${{ inputs.android_version }}
  347. # kernel_version: ${{ inputs.kernel_version }}
  348. # os_patch_level: ${{ inputs.os_patch_level }}
  349. # file_name: ${{ steps.extract.outputs.file_name }}
  350. #
  351. # - name: Upload Boot Image (.img)
  352. # uses: actions/upload-artifact@v7
  353. # with:
  354. # name: ${{ steps.extract.outputs.file_name }}-boot.img
  355. # path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot.img
  356. # if-no-files-found: error
  357. # archive: false
  358. #
  359. # - name: Upload Boot Image (.img.gz)
  360. # uses: actions/upload-artifact@v7
  361. # with:
  362. # name: ${{ steps.extract.outputs.file_name }}-boot-gz.img
  363. # path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-gz.img
  364. # if-no-files-found: error
  365. # archive: false
  366. #
  367. # - name: Upload Boot Image (.img.lz4)
  368. # uses: actions/upload-artifact@v7
  369. # with:
  370. # name: ${{ steps.extract.outputs.file_name }}-boot-lz4.img
  371. # path: ${{ github.workspace }}/boot-artifacts/${{ steps.extract.outputs.file_name }}-boot-lz4.img
  372. # if-no-files-found: error
  373. # archive: false
  374. #
  375. # - name: Prepare AnyKernel3 Zip
  376. # uses: ./.github/actions/prepare-anykernel3
  377. # with:
  378. # android_version: ${{ inputs.android_version }}
  379. # kernel_version: ${{ inputs.kernel_version }}
  380. #
  381. # - name: Upload Artifacts
  382. # uses: actions/upload-artifact@v7
  383. # with:
  384. # name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  385. # path: ${{ github.workspace }}/AnyKernel3/**
  386. # if-no-files-found: ignore
  387. # compression-level: 9