build.yml 16 KB

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