build.yml 19 KB

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