build.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. use_latest_commits:
  33. required: false
  34. type: boolean
  35. default: true
  36. jobs:
  37. build-gki:
  38. name: "${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} (${{ inputs.variant }})"
  39. runs-on: ubuntu-latest
  40. timeout-minutes: 60
  41. steps:
  42. - name: Checkout Repository
  43. uses: actions/checkout@v5
  44. - name: 🧹 Emergency Disk Cleanup
  45. if: false
  46. uses: ./.github/actions/disk-cleanup
  47. - name: Free Disk Space
  48. if: true
  49. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  50. with:
  51. remove_android: true
  52. remove_dotnet: true
  53. remove_haskell: true
  54. remove_tool_cache: true
  55. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  56. remove_packages_one_command: true
  57. 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"
  58. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  59. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  60. testing: false
  61. - name: Setup more Swap (for LTO)
  62. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  63. with:
  64. swap-size-gb: 16 # 10-24 GB is common for heavy LTO
  65. # swap-space-path: /mnt/swapfile # optional
  66. - name: Setup Build Environment
  67. uses: ./.github/actions/setup-build-environment
  68. env:
  69. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  70. - name: Download Kernel Repository
  71. uses: ./.github/actions/download-kernel
  72. with:
  73. version: ${{ inputs.version }}
  74. android_version: ${{ inputs.android_version }}
  75. kernel_version: ${{ inputs.kernel_version }}
  76. os_patch_level: ${{ inputs.os_patch_level }}
  77. use_repo: ${{ inputs.use_repo }}
  78. - name: Set Build Timestamp from Kernel Commit
  79. shell: bash
  80. run: |
  81. set -x
  82. # Hardcode the build timestamp to the 5th day of the patch level
  83. # at 04:20 UTC, using the existing timestamp formats expected by the build.
  84. OS_PATCH_LEVEL_INPUT="${{ inputs.os_patch_level }}"
  85. if [[ "$OS_PATCH_LEVEL_INPUT" == lts* ]]; then
  86. if [[ "$OS_PATCH_LEVEL_INPUT" =~ ^lts-([0-9]{2})$ ]]; then
  87. OS_PATCH_LEVEL_YM="$(date -u +%Y)-${BASH_REMATCH[1]}"
  88. else
  89. OS_PATCH_LEVEL_YM="$(date -u +%Y-%m)"
  90. fi
  91. else
  92. OS_PATCH_LEVEL_YM="$OS_PATCH_LEVEL_INPUT"
  93. fi
  94. FIXED_BUILD_DATE="${OS_PATCH_LEVEL_YM}-05 04:20:00 UTC"
  95. SOURCE_DATE_EPOCH=$(date -u -d "$FIXED_BUILD_DATE" +%s)
  96. echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
  97. KBUILD_TS=$(date -u -d @${SOURCE_DATE_EPOCH} '+%a %b %d %H:%M:%S UTC %Y')
  98. echo "KBUILD_BUILD_TIMESTAMP=${KBUILD_TS}" >> $GITHUB_ENV
  99. # Keep git metadata aligned with the same fixed timestamp.
  100. GIT_DATE=$(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%dT%H:%M:%SZ')
  101. echo "GIT_COMMITTER_DATE=${GIT_DATE}" >> $GITHUB_ENV
  102. echo "GIT_AUTHOR_DATE=${GIT_DATE}" >> $GITHUB_ENV
  103. echo "Build timestamp set to: $(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%d %H:%M:%S UTC') (epoch: $SOURCE_DATE_EPOCH)"
  104. - name: Extract Sublevel and Set File Name
  105. id: extract
  106. uses: ./.github/actions/extract-sublevel-file-name
  107. with:
  108. android_version: ${{ inputs.android_version }}
  109. kernel_version: ${{ inputs.kernel_version }}
  110. sublevel: ${{ inputs.sublevel }}
  111. os_patch_level: ${{ inputs.os_patch_level }}
  112. variant: ${{ inputs.variant }}
  113. - name: Kernel Fixes
  114. uses: ./.github/actions/kernel-fixes
  115. with:
  116. version: ${{ inputs.version }}
  117. android_version: ${{ inputs.android_version }}
  118. kernel_version: ${{ inputs.kernel_version }}
  119. sublevel: ${{ steps.extract.outputs.sublevel }}
  120. os_patch_level: ${{ inputs.os_patch_level }}
  121. - name: Setup KernelSU-Next
  122. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  123. uses: ./.github/actions/kernelsu
  124. with:
  125. use_latest_commits: ${{ inputs.use_latest_commits }}
  126. - name: SUSFS
  127. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  128. uses: ./.github/actions/susfs
  129. with:
  130. use_latest_commits: ${{ inputs.use_latest_commits }}
  131. version: ${{ inputs.version }}
  132. android_version: ${{ inputs.android_version }}
  133. kernel_version: ${{ inputs.kernel_version }}
  134. os_patch_level: ${{ inputs.os_patch_level }}
  135. sublevel: ${{ steps.extract.outputs.sublevel }}
  136. - name: Baseband Guard
  137. if: (contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL')
  138. uses: ./.github/actions/bbg
  139. - name: Setup Networking
  140. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  141. uses: ./.github/actions/networking
  142. with:
  143. version: ${{ inputs.version }}
  144. kernel_version: ${{ inputs.kernel_version }}
  145. android_version: ${{ inputs.android_version }}
  146. sublevel: ${{ steps.extract.outputs.sublevel }}
  147. - name: DroidSpaces-OSS Patches
  148. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  149. uses: ./.github/actions/droidspaces
  150. with:
  151. version: ${{ inputs.version }}
  152. kernel_version: ${{ inputs.kernel_version }}
  153. - name: Setup Misc Configs
  154. uses: ./.github/actions/misc
  155. with:
  156. version: ${{ inputs.version }}
  157. kernel_version: ${{ inputs.kernel_version }}
  158. android_version: ${{ inputs.android_version }}
  159. sublevel: ${{ steps.extract.outputs.sublevel }}
  160. variant: ${{ inputs.variant }}
  161. - name: Apply Device-Specific Patches
  162. uses: ./.github/actions/apply-device-patches
  163. with:
  164. version: ${{ inputs.version }}
  165. kernel_version: ${{ inputs.kernel_version }}
  166. - name: Apply ABI Compare Bypass
  167. if: false
  168. working-directory: ${{ github.workspace }}/kernel
  169. run: |
  170. # ABI compare bypass per kernel/android version
  171. # Edit each block as needed per version
  172. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  173. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  174. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  175. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  176. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  177. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  178. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  179. 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
  180. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  181. 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
  182. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  183. 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
  184. fi
  185. - name: Apply Kernel Branding
  186. uses: ./.github/actions/apply-kernel-branding
  187. with:
  188. variant: ${{ inputs.variant }}
  189. kernel_version: ${{ inputs.kernel_version }}
  190. android_version: ${{ inputs.android_version }}
  191. version: ${{ inputs.version }}
  192. sublevel: ${{ steps.extract.outputs.sublevel }}
  193. - name: Remove Protected Exports
  194. uses: ./.github/actions/remove-protected-exports
  195. - name: Clean Kernel Flags
  196. uses: ./.github/actions/clean-kernel-flags
  197. - name: Scan and collect patch rejects
  198. id: scan
  199. if: ${{ always() }}
  200. uses: ./.github/actions/scan-patch-rejects
  201. - name: Upload Rejects
  202. if: ${{ always() }}
  203. uses: actions/upload-artifact@v7
  204. with:
  205. name: ${{ steps.extract.outputs.file_name }}-Rejects
  206. path: patch-rejects/
  207. if-no-files-found: ignore
  208. compression-level: 9
  209. - name: 'Setup Cache and Build Environment'
  210. uses: ./.github/actions/cache-setup
  211. with:
  212. version: ${{ inputs.version }}
  213. android_version: ${{ inputs.android_version }}
  214. kernel_version: ${{ inputs.kernel_version }}
  215. sublevel: ${{ steps.extract.outputs.sublevel }}
  216. - name: Restore ccache
  217. id: restore-ccache
  218. continue-on-error: true
  219. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  220. uses: ./.github/actions/cache-restore
  221. with:
  222. cache_path: /home/runner/.ccache
  223. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  224. cache_bucket: ccache-cache
  225. restore_keys: |
  226. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  227. - name: Restore lto-cache (ccache versions)
  228. id: restore-lto-ccache
  229. continue-on-error: true
  230. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  231. uses: ./.github/actions/cache-restore
  232. with:
  233. cache_path: /home/runner/.ld_cache
  234. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  235. cache_bucket: lto-cache
  236. restore_keys: |
  237. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  238. - name: Restore bazel-cache
  239. id: restore-bazel
  240. continue-on-error: true
  241. if: inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12'
  242. uses: ./.github/actions/cache-restore
  243. with:
  244. cache_path: /home/runner/.cache/bazel
  245. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  246. cache_bucket: bazel-cache
  247. restore_keys: |
  248. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  249. - name: Check cache hit
  250. run: |
  251. echo "Cache restore status:"
  252. CCACHE_HIT="${{ steps.restore-ccache.outputs.cache-hit || 'skipped' }}"
  253. LTO_CCACHE_HIT="${{ steps.restore-lto-ccache.outputs.cache-hit || 'skipped' }}"
  254. BAZEL_HIT="${{ steps.restore-bazel.outputs.cache-hit || 'skipped' }}"
  255. LTO_BAZEL_HIT="skipped"
  256. echo " ccache: $CCACHE_HIT"
  257. echo " lto (ccache versions): $LTO_CCACHE_HIT"
  258. echo " bazel: $BAZEL_HIT"
  259. echo " lto (bazel versions): $LTO_BAZEL_HIT"
  260. - name: Get Cache Stats
  261. uses: ./.github/actions/cache-stats
  262. with:
  263. clear_stats: true
  264. - name: Initialize Config Fragment
  265. run: touch "${{ github.workspace }}/wild_gki.fragment"
  266. - name: Build Normal Kernel
  267. env:
  268. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  269. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  270. uses: ./.github/actions/build-kernel
  271. with:
  272. version: ${{ inputs.version }}
  273. bypass: false
  274. - name: Get Cache Stats
  275. uses: ./.github/actions/cache-stats
  276. with:
  277. clear_stats: false
  278. - name: Save ccache
  279. continue-on-error: true
  280. uses: ./.github/actions/cache-save
  281. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  282. with:
  283. cache_path: /home/runner/.ccache
  284. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  285. cache_bucket: "ccache-cache"
  286. compression_level: 9
  287. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  288. - name: Save lto-cache
  289. continue-on-error: true
  290. uses: ./.github/actions/cache-save
  291. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  292. with:
  293. cache_path: /home/runner/.ld_cache
  294. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  295. cache_bucket: "lto-cache"
  296. compression_level: 9
  297. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  298. - name: Save bazel-cache
  299. continue-on-error: true
  300. uses: ./.github/actions/cache-save
  301. if: inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12'
  302. with:
  303. cache_path: /home/runner/.cache/bazel
  304. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  305. cache_bucket: "bazel-cache"
  306. compression_level: 9
  307. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  308. - name: Build Bypass Kernel
  309. env:
  310. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  311. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  312. uses: ./.github/actions/build-kernel
  313. with:
  314. bypass: true
  315. version: ${{ inputs.version }}
  316. - name: 📋 Consolidated Build Summary
  317. if: ${{ always() }}
  318. shell: bash
  319. run: |
  320. SUMMARY_FILE="/tmp/build-summary-${{ steps.extract.outputs.file_name }}.md"
  321. {
  322. echo "## ${{ inputs.android_version }} ${{ inputs.kernel_version }}.${{ inputs.sublevel }} (${{ inputs.variant }})"
  323. echo
  324. # Kernel Fixes
  325. if [ -f /tmp/kernel-fixes-summary.md ]; then
  326. cat /tmp/kernel-fixes-summary.md
  327. echo
  328. fi
  329. # Add more summary files here as other actions adopt this pattern:
  330. # if [ -f /tmp/kernelsu-summary.md ]; then cat /tmp/kernelsu-summary.md; echo; fi
  331. # if [ -f /tmp/susfs-summary.md ]; then cat /tmp/susfs-summary.md; echo; fi
  332. # if [ -f /tmp/networking-summary.md ]; then cat /tmp/networking-summary.md; echo; fi
  333. } > "$SUMMARY_FILE"
  334. - name: Upload Build Summary Artifact
  335. if: ${{ always() }}
  336. uses: actions/upload-artifact@v7
  337. with:
  338. name: ${{ steps.extract.outputs.file_name }}-Summary
  339. path: /tmp/build-summary-${{ steps.extract.outputs.file_name }}.md
  340. if-no-files-found: ignore
  341. compression-level: 9
  342. - name: Upload Artifacts
  343. uses: actions/upload-artifact@v7
  344. with:
  345. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  346. path: ${{ github.workspace }}/AnyKernel3/**
  347. if-no-files-found: ignore
  348. compression-level: 9