build.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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: 120
  42. steps:
  43. - name: Checkout Repository
  44. uses: actions/checkout@v7
  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: Build FUSE-BPF Userspace Daemon (Issue #211)
  79. if: ${{ contains(inputs.version, 'lts') && inputs.version == 'android16-6.12' }}
  80. uses: ./.github/actions/fuse-bpf
  81. with:
  82. version: ${{ inputs.version }}
  83. kernel_version: ${{ inputs.kernel_version }}
  84. android_version: ${{ inputs.android_version }}
  85. - name: Set Build Timestamp from Kernel Commit
  86. shell: bash
  87. run: |
  88. set -x
  89. # Hardcode the build timestamp to the 5th day of the patch level
  90. # at 04:20 UTC, using the existing timestamp formats expected by the build.
  91. OS_PATCH_LEVEL_INPUT="${{ inputs.os_patch_level }}"
  92. if [[ "$OS_PATCH_LEVEL_INPUT" == lts* ]]; then
  93. if [[ "$OS_PATCH_LEVEL_INPUT" =~ ^lts-([0-9]{2})$ ]]; then
  94. OS_PATCH_LEVEL_YM="$(date -u +%Y)-${BASH_REMATCH[1]}"
  95. else
  96. OS_PATCH_LEVEL_YM="$(date -u +%Y-%m)"
  97. fi
  98. else
  99. OS_PATCH_LEVEL_YM="$OS_PATCH_LEVEL_INPUT"
  100. fi
  101. FIXED_BUILD_DATE="${OS_PATCH_LEVEL_YM}-05 04:20:00 UTC"
  102. SOURCE_DATE_EPOCH=$(date -u -d "$FIXED_BUILD_DATE" +%s)
  103. echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
  104. KBUILD_TS=$(date -u -d @${SOURCE_DATE_EPOCH} '+%a %b %d %H:%M:%S UTC %Y')
  105. echo "KBUILD_BUILD_TIMESTAMP=${KBUILD_TS}" >> $GITHUB_ENV
  106. # Keep git metadata aligned with the same fixed timestamp.
  107. GIT_DATE=$(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%dT%H:%M:%SZ')
  108. echo "GIT_COMMITTER_DATE=${GIT_DATE}" >> $GITHUB_ENV
  109. echo "GIT_AUTHOR_DATE=${GIT_DATE}" >> $GITHUB_ENV
  110. echo "Build timestamp set to: $(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%d %H:%M:%S UTC') (epoch: $SOURCE_DATE_EPOCH)"
  111. - name: Extract Sublevel and Set File Name
  112. id: extract
  113. uses: ./.github/actions/extract-sublevel-file-name
  114. with:
  115. android_version: ${{ inputs.android_version }}
  116. kernel_version: ${{ inputs.kernel_version }}
  117. sublevel: ${{ inputs.sublevel }}
  118. os_patch_level: ${{ inputs.os_patch_level }}
  119. variant: ${{ inputs.variant }}
  120. - name: Kernel Fixes
  121. uses: ./.github/actions/kernel-fixes
  122. with:
  123. version: ${{ inputs.version }}
  124. android_version: ${{ inputs.android_version }}
  125. kernel_version: ${{ inputs.kernel_version }}
  126. sublevel: ${{ steps.extract.outputs.sublevel }}
  127. os_patch_level: ${{ inputs.os_patch_level }}
  128. - name: Setup KernelSU-Next
  129. if: contains(inputs.feature_set, 'KSUN') || inputs.feature_set == 'FULL'
  130. uses: ./.github/actions/kernelsu
  131. with:
  132. ksu_branch: ${{ inputs.ksu_branch }}
  133. - name: SUSFS
  134. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'FULL'
  135. uses: ./.github/actions/susfs
  136. with:
  137. susfs_commit: ${{ inputs.susfs_commit }}
  138. version: ${{ inputs.version }}
  139. android_version: ${{ inputs.android_version }}
  140. kernel_version: ${{ inputs.kernel_version }}
  141. os_patch_level: ${{ inputs.os_patch_level }}
  142. sublevel: ${{ steps.extract.outputs.sublevel }}
  143. - name: Baseband Guard
  144. if: (contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'FULL')
  145. uses: ./.github/actions/bbg
  146. - name: Setup Networking
  147. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'FULL'
  148. uses: ./.github/actions/networking
  149. with:
  150. version: ${{ inputs.version }}
  151. kernel_version: ${{ inputs.kernel_version }}
  152. android_version: ${{ inputs.android_version }}
  153. sublevel: ${{ steps.extract.outputs.sublevel }}
  154. - name: DroidSpaces-OSS Patches
  155. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'FULL'
  156. uses: ./.github/actions/droidspaces
  157. with:
  158. version: ${{ inputs.version }}
  159. kernel_version: ${{ inputs.kernel_version }}
  160. - name: Apply NTSync Patches
  161. uses: ./.github/actions/ntsync
  162. with:
  163. version: ${{ inputs.version }}
  164. kernel_version: ${{ inputs.kernel_version }}
  165. sublevel: ${{ steps.extract.outputs.sublevel }}
  166. - name: Apply Ptrace Patch
  167. uses: ./.github/actions/ptrace
  168. with:
  169. kernel_version: ${{ inputs.kernel_version }}
  170. - name: Apply Unicode Fix Patch
  171. uses: ./.github/actions/unicode-fix
  172. with:
  173. kernel_version: ${{ inputs.kernel_version }}
  174. - name: Apply Performance Patches
  175. uses: ./.github/actions/performance
  176. if: false
  177. with:
  178. kernel_version: ${{ inputs.kernel_version }}
  179. - name: Setup Misc Configs
  180. uses: ./.github/actions/misc
  181. - name: Enable BTF
  182. if: ${{ inputs.kernel_version != '5.10' }}
  183. uses: ./.github/actions/set-kernel-config
  184. with:
  185. config_list: |
  186. CONFIG_DEBUG_INFO_BTF=y
  187. - name: Apply Device-Specific Patches
  188. uses: ./.github/actions/apply-device-patches
  189. with:
  190. version: ${{ inputs.version }}
  191. kernel_version: ${{ inputs.kernel_version }}
  192. - name: Apply ABI Compare Bypass
  193. if: false
  194. working-directory: ${{ github.workspace }}/kernel
  195. run: |
  196. # ABI compare bypass per kernel/android version
  197. # Edit each block as needed per version
  198. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  199. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  200. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  201. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  202. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  203. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  204. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  205. 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
  206. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  207. 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
  208. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  209. 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
  210. fi
  211. - name: Apply Kernel Branding
  212. uses: ./.github/actions/apply-kernel-branding
  213. with:
  214. variant: ${{ inputs.variant }}
  215. kernel_version: ${{ inputs.kernel_version }}
  216. android_version: ${{ inputs.android_version }}
  217. version: ${{ inputs.version }}
  218. sublevel: ${{ steps.extract.outputs.sublevel }}
  219. - name: Remove Protected Exports
  220. uses: ./.github/actions/remove-protected-exports
  221. - name: Clean Kernel Flags
  222. uses: ./.github/actions/clean-kernel-flags
  223. - name: Scan and collect patch rejects
  224. id: scan
  225. if: ${{ always() }}
  226. uses: ./.github/actions/scan-patch-rejects
  227. - name: Upload Rejects
  228. if: ${{ always() }}
  229. uses: actions/upload-artifact@v7
  230. with:
  231. name: ${{ steps.extract.outputs.file_name }}-Rejects
  232. path: patch-rejects/
  233. if-no-files-found: ignore
  234. compression-level: 9
  235. - name: Get prebuilt ccache (downloaded once by prepare-ccache)
  236. uses: actions/download-artifact@v8
  237. with:
  238. name: ccache-binary
  239. path: ccache-dl
  240. continue-on-error: true
  241. - name: 'Setup Cache and Build Environment'
  242. uses: ./.github/actions/cache-setup
  243. with:
  244. version: ${{ inputs.version }}
  245. android_version: ${{ inputs.android_version }}
  246. kernel_version: ${{ inputs.kernel_version }}
  247. sublevel: ${{ steps.extract.outputs.sublevel }}
  248. - name: Restore ccache
  249. id: restore-ccache
  250. continue-on-error: true
  251. if: false && (inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15')
  252. uses: ./.github/actions/cache-restore
  253. with:
  254. cache_path: /home/runner/.ccache
  255. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  256. cache_bucket: ccache-cache
  257. restore_keys: |
  258. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  259. - name: Restore bazel-cache
  260. id: restore-bazel
  261. continue-on-error: true
  262. if: false && (inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12')
  263. uses: ./.github/actions/cache-restore
  264. with:
  265. cache_path: /home/runner/.cache/bazel
  266. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  267. cache_bucket: bazel-cache
  268. restore_keys: |
  269. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  270. - name: Cache ccache (GitHub Native)
  271. uses: actions/cache@v6
  272. with:
  273. path: /home/runner/.ccache
  274. key: ccache-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  275. restore-keys: |
  276. ccache-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  277. ccache-${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  278. ccache-
  279. - name: Cache bazel-cache (GitHub Native)
  280. uses: actions/cache@v6
  281. with:
  282. path: /home/runner/.cache/bazel
  283. key: bazel-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  284. restore-keys: |
  285. bazel-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  286. bazel-${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  287. bazel-
  288. - name: Check cache hit
  289. run: |
  290. echo "Cache restore status:"
  291. CCACHE_HIT="${{ steps.restore-ccache.outputs.cache-hit || 'skipped' }}"
  292. BAZEL_HIT="${{ steps.restore-bazel.outputs.cache-hit || 'skipped' }}"
  293. echo " ccache: $CCACHE_HIT"
  294. echo " bazel: $BAZEL_HIT"
  295. - name: Get Cache Stats
  296. uses: ./.github/actions/cache-stats
  297. with:
  298. clear_stats: true
  299. - name: Initialize Config Fragment
  300. run: touch "${{ github.workspace }}/wild_gki.fragment"
  301. - name: Build Normal Kernel
  302. env:
  303. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  304. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  305. uses: ./.github/actions/build-kernel
  306. with:
  307. version: ${{ inputs.version }}
  308. bypass: false
  309. - name: Get Cache Stats
  310. uses: ./.github/actions/cache-stats
  311. with:
  312. clear_stats: false
  313. - name: Save ccache
  314. continue-on-error: true
  315. uses: ./.github/actions/cache-save
  316. if: false && (inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15')
  317. with:
  318. cache_path: /home/runner/.ccache
  319. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  320. cache_bucket: "ccache-cache"
  321. compression_level: 9
  322. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  323. - name: Save bazel-cache
  324. continue-on-error: true
  325. uses: ./.github/actions/cache-save
  326. if: false && (inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12')
  327. with:
  328. cache_path: /home/runner/.cache/bazel
  329. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  330. cache_bucket: "bazel-cache"
  331. compression_level: 9
  332. github_token: ${{ secrets.MY_GITHUB_TOKEN }}
  333. - name: Build Bypass Kernel
  334. env:
  335. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  336. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  337. uses: ./.github/actions/build-kernel
  338. with:
  339. bypass: true
  340. version: ${{ inputs.version }}
  341. - name: 📋 Consolidated Build Summary
  342. if: ${{ always() }}
  343. shell: bash
  344. run: |
  345. SUMMARY_FILE="/tmp/build-summary-${{ steps.extract.outputs.file_name }}.md"
  346. # Determine build status
  347. if [ "${{ job.status }}" = "success" ]; then
  348. STATUS="✅ Success"
  349. else
  350. STATUS="❌ Failed"
  351. fi
  352. # Get kernel version from Image if available
  353. KERNEL_VER_STR=""
  354. if [ -f "/home/runner/out/dist/Image" ]; then
  355. KERNEL_VER_STR=$(strings "/home/runner/out/dist/Image" | grep -m1 "^Linux version " | sed 's/Linux version //' || echo "")
  356. elif [ -f "/home/runner/out/Image" ]; then
  357. KERNEL_VER_STR=$(strings "/home/runner/out/Image" | grep -m1 "^Linux version " | sed 's/Linux version //' || echo "")
  358. fi
  359. # Get KSU version from env (set by kernelsu action)
  360. KSU_VER="${KSU_VERSION:-N/A}"
  361. KSU_TAG="${KSU_GIT_TAG:-N/A}"
  362. # Get SUSFS version from susfs.h if available
  363. SUSFS_VER="N/A"
  364. if [ -f "${{ github.workspace }}/kernel/common/include/linux/susfs.h" ]; then
  365. SUSFS_VER=$(grep '#define SUSFS_VERSION' "${{ github.workspace }}/kernel/common/include/linux/susfs.h" | awk -F'"' '{print $2}' || echo "N/A")
  366. fi
  367. # Get cache stats from env (set by cache-stats action)
  368. CCACHE_HIT="${CCACHE_HIT_RATE:-N/A}"
  369. # Get build time (approximate from step timing)
  370. BUILD_TIME="N/A"
  371. # Count warnings from build log if available
  372. WARNINGS="N/A"
  373. {
  374. echo "## ${{ inputs.android_version }} ${{ inputs.kernel_version }}.${{ inputs.sublevel }} (${{ inputs.variant }}) — ${STATUS}"
  375. echo
  376. echo "| Metric | Value |"
  377. echo "|--------|-------|"
  378. echo "| **Status** | ${STATUS} |"
  379. echo "| **Kernel** | ${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} |"
  380. if [ -n "$KERNEL_VER_STR" ]; then
  381. echo "| **Version String** | \`${KERNEL_VER_STR}\` |"
  382. fi
  383. echo "| **KSU Version** | ${KSU_VER} |"
  384. echo "| **KSU Tag** | ${KSU_TAG} |"
  385. echo "| **SUSFS Version** | ${SUSFS_VER} |"
  386. echo "| **Feature Set** | ${{ inputs.feature_set }} |"
  387. echo "| **Variant** | ${{ inputs.variant }} |"
  388. echo
  389. # Kernel Fixes
  390. if [ -f /tmp/kernel-fixes-summary.md ]; then
  391. echo "### 🔧 Kernel Fixes"
  392. cat /tmp/kernel-fixes-summary.md
  393. echo
  394. fi
  395. } > "$SUMMARY_FILE"
  396. - name: Upload Build Summary Artifact
  397. if: ${{ always() }}
  398. uses: actions/upload-artifact@v7
  399. with:
  400. name: ${{ steps.extract.outputs.file_name }}-Summary
  401. path: /tmp/build-summary-${{ steps.extract.outputs.file_name }}.md
  402. if-no-files-found: ignore
  403. compression-level: 9
  404. - name: Upload Artifacts
  405. uses: actions/upload-artifact@v7
  406. with:
  407. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  408. path: ${{ github.workspace }}/AnyKernel3/**
  409. if-no-files-found: ignore
  410. compression-level: 9