build.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. ksu_branch:
  30. required: false
  31. type: string
  32. default: ""
  33. susfs_commit:
  34. required: false
  35. type: string
  36. default: ""
  37. jobs:
  38. build-gki:
  39. name: "${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} (${{ inputs.variant }})"
  40. runs-on: ubuntu-latest
  41. timeout-minutes: 60
  42. steps:
  43. - name: Checkout Repository
  44. uses: actions/checkout@v5
  45. - name: 🧹 Emergency Disk Cleanup
  46. if: false
  47. uses: ./.github/actions/disk-cleanup
  48. - name: Free Disk Space
  49. if: true
  50. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  51. with:
  52. remove_android: true
  53. remove_dotnet: true
  54. remove_haskell: true
  55. remove_tool_cache: true
  56. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  57. remove_packages_one_command: true
  58. 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"
  59. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  60. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  61. testing: false
  62. - name: Setup more Swap (for LTO)
  63. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  64. with:
  65. swap-size-gb: 16 # 10-24 GB is common for heavy LTO
  66. # swap-space-path: /mnt/swapfile # optional
  67. - name: Setup Build Environment
  68. uses: ./.github/actions/setup-build-environment
  69. env:
  70. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  71. - name: Download Kernel Repository
  72. uses: ./.github/actions/download-kernel
  73. with:
  74. version: ${{ inputs.version }}
  75. android_version: ${{ inputs.android_version }}
  76. kernel_version: ${{ inputs.kernel_version }}
  77. os_patch_level: ${{ inputs.os_patch_level }}
  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. ksu_branch: ${{ inputs.ksu_branch }}
  126. - name: SUSFS
  127. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  128. uses: ./.github/actions/susfs
  129. with:
  130. susfs_commit: ${{ inputs.susfs_commit }}
  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: Apply BBRv3 Patches
  140. uses: ./.github/actions/bbrv3
  141. with:
  142. version: ${{ inputs.version }}
  143. sublevel: ${{ steps.extract.outputs.sublevel }}
  144. - name: Setup Networking
  145. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  146. uses: ./.github/actions/networking
  147. with:
  148. version: ${{ inputs.version }}
  149. kernel_version: ${{ inputs.kernel_version }}
  150. android_version: ${{ inputs.android_version }}
  151. sublevel: ${{ steps.extract.outputs.sublevel }}
  152. - name: DroidSpaces-OSS Patches
  153. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  154. uses: ./.github/actions/droidspaces
  155. with:
  156. version: ${{ inputs.version }}
  157. kernel_version: ${{ inputs.kernel_version }}
  158. - name: Apply NTSync Patches
  159. uses: ./.github/actions/ntsync
  160. with:
  161. version: ${{ inputs.version }}
  162. kernel_version: ${{ inputs.kernel_version }}
  163. - name: Apply Ptrace Patch
  164. uses: ./.github/actions/ptrace
  165. with:
  166. kernel_version: ${{ inputs.kernel_version }}
  167. - name: Apply Unicode Fix Patch
  168. uses: ./.github/actions/unicode-fix
  169. with:
  170. kernel_version: ${{ inputs.kernel_version }}
  171. - name: Apply Performance Patches
  172. uses: ./.github/actions/performance
  173. with:
  174. kernel_version: ${{ inputs.kernel_version }}
  175. - name: Setup Misc Configs
  176. uses: ./.github/actions/misc
  177. - name: Apply Device-Specific Patches
  178. uses: ./.github/actions/apply-device-patches
  179. with:
  180. version: ${{ inputs.version }}
  181. kernel_version: ${{ inputs.kernel_version }}
  182. - name: Apply ABI Compare Bypass
  183. if: false
  184. working-directory: ${{ github.workspace }}/kernel
  185. run: |
  186. # ABI compare bypass per kernel/android version
  187. # Edit each block as needed per version
  188. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  189. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  190. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  191. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  192. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  193. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  194. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  195. 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
  196. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  197. 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
  198. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  199. 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
  200. fi
  201. - name: Apply Kernel Branding
  202. uses: ./.github/actions/apply-kernel-branding
  203. with:
  204. variant: ${{ inputs.variant }}
  205. kernel_version: ${{ inputs.kernel_version }}
  206. android_version: ${{ inputs.android_version }}
  207. version: ${{ inputs.version }}
  208. sublevel: ${{ steps.extract.outputs.sublevel }}
  209. - name: Remove Protected Exports
  210. uses: ./.github/actions/remove-protected-exports
  211. - name: Clean Kernel Flags
  212. uses: ./.github/actions/clean-kernel-flags
  213. - name: Scan and collect patch rejects
  214. id: scan
  215. if: ${{ always() }}
  216. uses: ./.github/actions/scan-patch-rejects
  217. - name: Upload Rejects
  218. if: ${{ always() }}
  219. uses: actions/upload-artifact@v7
  220. with:
  221. name: ${{ steps.extract.outputs.file_name }}-Rejects
  222. path: patch-rejects/
  223. if-no-files-found: ignore
  224. compression-level: 9
  225. - name: Get prebuilt ccache (downloaded once by prepare-ccache)
  226. uses: actions/download-artifact@v8
  227. with:
  228. name: ccache-binary
  229. path: ccache-dl
  230. continue-on-error: true
  231. - name: 'Setup Cache and Build Environment'
  232. uses: ./.github/actions/cache-setup
  233. with:
  234. version: ${{ inputs.version }}
  235. android_version: ${{ inputs.android_version }}
  236. kernel_version: ${{ inputs.kernel_version }}
  237. sublevel: ${{ steps.extract.outputs.sublevel }}
  238. - name: Restore ccache
  239. id: restore-ccache
  240. continue-on-error: true
  241. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  242. uses: ./.github/actions/cache-restore
  243. with:
  244. cache_path: /home/runner/.ccache
  245. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  246. cache_bucket: ccache-cache
  247. restore_keys: |
  248. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  249. - name: Restore lto-cache (ccache versions)
  250. id: restore-lto-ccache
  251. continue-on-error: true
  252. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  253. uses: ./.github/actions/cache-restore
  254. with:
  255. cache_path: /home/runner/.ld_cache
  256. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  257. cache_bucket: lto-cache
  258. restore_keys: |
  259. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  260. - name: Restore bazel-cache
  261. id: restore-bazel
  262. continue-on-error: true
  263. if: inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12'
  264. uses: ./.github/actions/cache-restore
  265. with:
  266. cache_path: /home/runner/.cache/bazel
  267. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  268. cache_bucket: bazel-cache
  269. restore_keys: |
  270. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  271. - name: Check cache hit
  272. run: |
  273. echo "Cache restore status:"
  274. CCACHE_HIT="${{ steps.restore-ccache.outputs.cache-hit || 'skipped' }}"
  275. LTO_CCACHE_HIT="${{ steps.restore-lto-ccache.outputs.cache-hit || 'skipped' }}"
  276. BAZEL_HIT="${{ steps.restore-bazel.outputs.cache-hit || 'skipped' }}"
  277. LTO_BAZEL_HIT="skipped"
  278. echo " ccache: $CCACHE_HIT"
  279. echo " lto (ccache versions): $LTO_CCACHE_HIT"
  280. echo " bazel: $BAZEL_HIT"
  281. echo " lto (bazel versions): $LTO_BAZEL_HIT"
  282. - name: Get Cache Stats
  283. uses: ./.github/actions/cache-stats
  284. with:
  285. clear_stats: true
  286. - name: Initialize Config Fragment
  287. run: touch "${{ github.workspace }}/wild_gki.fragment"
  288. - name: Build Normal Kernel
  289. env:
  290. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  291. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  292. uses: ./.github/actions/build-kernel
  293. with:
  294. version: ${{ inputs.version }}
  295. bypass: false
  296. - name: Get Cache Stats
  297. uses: ./.github/actions/cache-stats
  298. with:
  299. clear_stats: false
  300. - name: Save ccache
  301. continue-on-error: true
  302. uses: ./.github/actions/cache-save
  303. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  304. with:
  305. cache_path: /home/runner/.ccache
  306. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  307. cache_bucket: "ccache-cache"
  308. compression_level: 9
  309. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  310. - name: Save lto-cache
  311. continue-on-error: true
  312. uses: ./.github/actions/cache-save
  313. if: inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15'
  314. with:
  315. cache_path: /home/runner/.ld_cache
  316. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  317. cache_bucket: "lto-cache"
  318. compression_level: 9
  319. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  320. - name: Save bazel-cache
  321. continue-on-error: true
  322. uses: ./.github/actions/cache-save
  323. if: inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12'
  324. with:
  325. cache_path: /home/runner/.cache/bazel
  326. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  327. cache_bucket: "bazel-cache"
  328. compression_level: 9
  329. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  330. - name: Build Bypass Kernel
  331. env:
  332. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  333. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  334. uses: ./.github/actions/build-kernel
  335. with:
  336. bypass: true
  337. version: ${{ inputs.version }}
  338. - name: 📋 Consolidated Build Summary
  339. if: ${{ always() }}
  340. shell: bash
  341. run: |
  342. SUMMARY_FILE="/tmp/build-summary-${{ steps.extract.outputs.file_name }}.md"
  343. # Determine build status
  344. if [ "${{ job.status }}" = "success" ]; then
  345. STATUS="✅ Success"
  346. else
  347. STATUS="❌ Failed"
  348. fi
  349. # Get kernel version from Image if available
  350. KERNEL_VER_STR=""
  351. if [ -f "/home/runner/out/dist/Image" ]; then
  352. KERNEL_VER_STR=$(strings "/home/runner/out/dist/Image" | grep -m1 "^Linux version " | sed 's/Linux version //' || echo "")
  353. elif [ -f "/home/runner/out/Image" ]; then
  354. KERNEL_VER_STR=$(strings "/home/runner/out/Image" | grep -m1 "^Linux version " | sed 's/Linux version //' || echo "")
  355. fi
  356. # Get KSU version from env (set by kernelsu action)
  357. KSU_VER="${KSU_VERSION:-N/A}"
  358. KSU_TAG="${KSU_GIT_TAG:-N/A}"
  359. # Get SUSFS version from susfs.h if available
  360. SUSFS_VER="N/A"
  361. if [ -f "${{ github.workspace }}/kernel/common/include/linux/susfs.h" ]; then
  362. SUSFS_VER=$(grep '#define SUSFS_VERSION' "${{ github.workspace }}/kernel/common/include/linux/susfs.h" | awk -F'"' '{print $2}' || echo "N/A")
  363. fi
  364. # Get cache stats from env (set by cache-stats action)
  365. CCACHE_HIT="${CCACHE_HIT_RATE:-N/A}"
  366. # Get build time (approximate from step timing)
  367. BUILD_TIME="N/A"
  368. # Count warnings from build log if available
  369. WARNINGS="N/A"
  370. {
  371. echo "## ${{ inputs.android_version }} ${{ inputs.kernel_version }}.${{ inputs.sublevel }} (${{ inputs.variant }}) — ${STATUS}"
  372. echo
  373. echo "| Metric | Value |"
  374. echo "|--------|-------|"
  375. echo "| **Status** | ${STATUS} |"
  376. echo "| **Kernel** | ${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} |"
  377. if [ -n "$KERNEL_VER_STR" ]; then
  378. echo "| **Version String** | \`${KERNEL_VER_STR}\` |"
  379. fi
  380. echo "| **KSU Version** | ${KSU_VER} |"
  381. echo "| **KSU Tag** | ${KSU_TAG} |"
  382. echo "| **SUSFS Version** | ${SUSFS_VER} |"
  383. echo "| **Feature Set** | ${{ inputs.feature_set }} |"
  384. echo "| **Variant** | ${{ inputs.variant }} |"
  385. echo
  386. # Kernel Fixes
  387. if [ -f /tmp/kernel-fixes-summary.md ]; then
  388. echo "### 🔧 Kernel Fixes"
  389. cat /tmp/kernel-fixes-summary.md
  390. echo
  391. fi
  392. } > "$SUMMARY_FILE"
  393. - name: Upload Build Summary Artifact
  394. if: ${{ always() }}
  395. uses: actions/upload-artifact@v7
  396. with:
  397. name: ${{ steps.extract.outputs.file_name }}-Summary
  398. path: /tmp/build-summary-${{ steps.extract.outputs.file_name }}.md
  399. if-no-files-found: ignore
  400. compression-level: 9
  401. - name: Upload Artifacts
  402. uses: actions/upload-artifact@v7
  403. with:
  404. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  405. path: ${{ github.workspace }}/AnyKernel3/**
  406. if-no-files-found: ignore
  407. compression-level: 9