build.yml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  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. root_flavor:
  38. required: false
  39. type: string
  40. default: ""
  41. root_commit:
  42. required: false
  43. type: string
  44. default: ""
  45. nomount_commit:
  46. required: false
  47. type: string
  48. default: ""
  49. kernel_patches_commit:
  50. required: false
  51. type: string
  52. default: ""
  53. anykernel3_commit:
  54. required: false
  55. type: string
  56. default: ""
  57. droidspaces_commit:
  58. required: false
  59. type: string
  60. default: ""
  61. brand_name:
  62. required: false
  63. type: string
  64. default: Wild
  65. bypass:
  66. required: false
  67. type: boolean
  68. default: false
  69. use_cache:
  70. description: "Enable ccache/bazel cache (restore/save via release buckets)"
  71. required: false
  72. type: boolean
  73. default: true
  74. jobs:
  75. build-gki:
  76. name: "${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} (${{ inputs.variant }})"
  77. runs-on: ubuntu-latest
  78. timeout-minutes: 120
  79. steps:
  80. - name: Checkout Repository
  81. uses: actions/checkout@v7
  82. - name: Emergency Disk Cleanup
  83. if: false
  84. uses: ./.github/actions/disk-cleanup
  85. - name: Free Disk Space
  86. if: true
  87. uses: endersonmenezes/free-disk-space@v4 # Use @main for latest, @v3 for stable
  88. with:
  89. remove_android: true
  90. remove_dotnet: true
  91. remove_haskell: true
  92. remove_tool_cache: true
  93. remove_swap: true
  94. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  95. remove_packages_one_command: true
  96. 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"
  97. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  98. rmz_version: "3.2.0" # Required when rm_cmd is 'rmz'
  99. testing: false
  100. - name: Setup more Swap (for LTO)
  101. uses: pierotofy/set-swap-space@master
  102. with:
  103. swap-size-gb: 16
  104. - name: Setup Build Environment
  105. uses: ./.github/actions/setup-build-environment
  106. with:
  107. version: ${{ inputs.version }}
  108. sublevel: ${{ inputs.sublevel }}
  109. kernel_patches_commit: ${{ inputs.kernel_patches_commit }}
  110. anykernel3_commit: ${{ inputs.anykernel3_commit }}
  111. - name: Download Kernel Repository
  112. uses: ./.github/actions/download-kernel
  113. with:
  114. version: ${{ inputs.version }}
  115. android_version: ${{ inputs.android_version }}
  116. kernel_version: ${{ inputs.kernel_version }}
  117. os_patch_level: ${{ inputs.os_patch_level }}
  118. - name: Set Build Timestamp from Kernel Commit
  119. shell: bash
  120. run: |
  121. set -x
  122. # Hardcode the build timestamp to the 5th day of the patch level
  123. # at 04:20 UTC, using the existing timestamp formats expected by the build.
  124. OS_PATCH_LEVEL_INPUT="${{ inputs.os_patch_level }}"
  125. if [[ "$OS_PATCH_LEVEL_INPUT" == lts* ]]; then
  126. if [[ "$OS_PATCH_LEVEL_INPUT" =~ ^lts-([0-9]{2})$ ]]; then
  127. OS_PATCH_LEVEL_YM="$(date -u +%Y)-${BASH_REMATCH[1]}"
  128. else
  129. OS_PATCH_LEVEL_YM="$(date -u +%Y-%m)"
  130. fi
  131. else
  132. OS_PATCH_LEVEL_YM="$OS_PATCH_LEVEL_INPUT"
  133. fi
  134. FIXED_BUILD_DATE="${OS_PATCH_LEVEL_YM}-05 04:20:00 UTC"
  135. SOURCE_DATE_EPOCH=$(date -u -d "$FIXED_BUILD_DATE" +%s)
  136. echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> $GITHUB_ENV
  137. KBUILD_TS=$(date -u -d @${SOURCE_DATE_EPOCH} '+%a %b %d %H:%M:%S UTC %Y')
  138. echo "KBUILD_BUILD_TIMESTAMP=${KBUILD_TS}" >> $GITHUB_ENV
  139. # Keep git metadata aligned with the same fixed timestamp.
  140. GIT_DATE=$(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%dT%H:%M:%SZ')
  141. echo "GIT_COMMITTER_DATE=${GIT_DATE}" >> $GITHUB_ENV
  142. echo "GIT_AUTHOR_DATE=${GIT_DATE}" >> $GITHUB_ENV
  143. echo "Build timestamp set to: $(date -u -d @${SOURCE_DATE_EPOCH} '+%Y-%m-%d %H:%M:%S UTC') (epoch: $SOURCE_DATE_EPOCH)"
  144. - name: Extract Sublevel and Set File Name
  145. id: extract
  146. uses: ./.github/actions/extract-sublevel-file-name
  147. with:
  148. android_version: ${{ inputs.android_version }}
  149. kernel_version: ${{ inputs.kernel_version }}
  150. sublevel: ${{ inputs.sublevel }}
  151. os_patch_level: ${{ inputs.os_patch_level }}
  152. variant: ${{ inputs.variant }}
  153. - name: Kernel Fixes
  154. uses: ./.github/actions/kernel-fixes
  155. with:
  156. version: ${{ inputs.version }}
  157. android_version: ${{ inputs.android_version }}
  158. kernel_version: ${{ inputs.kernel_version }}
  159. sublevel: ${{ steps.extract.outputs.sublevel }}
  160. os_patch_level: ${{ inputs.os_patch_level }}
  161. - name: Setup Selected Root Implementation
  162. if: inputs.root_flavor != ''
  163. uses: ./.github/actions/root-setup
  164. with:
  165. flavor: ${{ inputs.root_flavor }}
  166. commit: ${{ inputs.root_commit }}
  167. - name: Disable SUSFS for ReSukiSU without SUSFS feature
  168. if: inputs.root_flavor == 'resukisu' && !contains(inputs.feature_set, 'SUSFS')
  169. uses: ./.github/actions/set-kernel-config
  170. with:
  171. config_list: |
  172. CONFIG_KSU_SUSFS=n
  173. - name: Resolve SUSFS commit
  174. id: susfs-cm
  175. shell: bash
  176. run: |
  177. set -euo pipefail
  178. # KernelSU-Next (next) always uses the latest susfs4ksu gki branch tip so
  179. # SUSFS stays API-matched to the always-latest KernelSU-Next tree. All
  180. # other roots (kernelsu, resukisu) use the pinned verified SUSFS commit.
  181. if [ "${{ inputs.root_flavor }}" = "next" ]; then
  182. BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  183. SUSFS_COMMIT="$(git ls-remote https://gitlab.com/simonpunk/susfs4ksu.git "refs/heads/${BRANCH}" | cut -f1)"
  184. echo "KernelSU-Next: resolving SUSFS at latest on ${BRANCH} -> ${SUSFS_COMMIT}"
  185. else
  186. SUSFS_COMMIT="${{ inputs.susfs_commit }}"
  187. echo "Using pinned SUSFS commit: ${SUSFS_COMMIT}"
  188. fi
  189. echo "commit=${SUSFS_COMMIT}" >> "$GITHUB_OUTPUT"
  190. - name: SUSFS
  191. if: contains(inputs.feature_set, 'SUSFS') || inputs.feature_set == 'All'
  192. uses: ./.github/actions/susfs
  193. with:
  194. susfs_commit: ${{ steps.susfs-cm.outputs.commit }}
  195. version: ${{ inputs.version }}
  196. android_version: ${{ inputs.android_version }}
  197. kernel_version: ${{ inputs.kernel_version }}
  198. os_patch_level: ${{ inputs.os_patch_level }}
  199. sublevel: ${{ steps.extract.outputs.sublevel }}
  200. root_flavor: ${{ inputs.root_flavor }}
  201. - name: Fix selinux_hide pointer-bool-conversion on 6.6+ (ALL branches)
  202. shell: bash
  203. run: |
  204. set -euo pipefail
  205. KVER="${{ inputs.kernel_version }}"
  206. if [ "$(printf '%s\n' "6.6" "$KVER" | sort -V | head -n1)" = "6.6" ]; then
  207. echo "[*] KVER $KVER >= 6.6, patching selinux_hide.c (all flavors/branches)"
  208. for f in $(find "${{ github.workspace }}" -name selinux_hide.c 2>/dev/null); do
  209. # After SUSFS 10_enable (kernelsu only) the declaration becomes
  210. # extern void security_dump_masked_av_fn(...) (a function)
  211. # if (func) / if (func != NULL) both trigger -Werror:
  212. # -Wpointer-bool-conversion vs -Wtautological-pointer-compare
  213. # For the function form, &func != NULL silences both (clang note).
  214. # For the pointer form (resukisu/next, no 10_enable) we want ptr != NULL.
  215. if grep -q "extern void security_dump_masked_av_fn" "$f"; then
  216. echo "[*] $f is extern-function form (10_enable applied), patching with &"
  217. sed -i 's/if (security_dump_masked_av_fn)/if (\&security_dump_masked_av_fn)/g' "$f"
  218. sed -i 's/if (security_dump_masked_av_fn != NULL)/if (\&security_dump_masked_av_fn != NULL)/g' "$f"
  219. sed -i 's/if (context_struct_compute_av_fn)/if (\&context_struct_compute_av_fn)/g' "$f"
  220. sed -i 's/if (context_struct_compute_av_fn != NULL)/if (\&context_struct_compute_av_fn != NULL)/g' "$f"
  221. echo "[+] Patched $f (function form)"
  222. elif grep -q "if (security_dump_masked_av_fn" "$f"; then
  223. echo "[*] $f is pointer form, patching with != NULL"
  224. sed -i 's/if (security_dump_masked_av_fn)/if (security_dump_masked_av_fn != NULL)/g' "$f"
  225. sed -i 's/if (context_struct_compute_av_fn)/if (context_struct_compute_av_fn != NULL)/g' "$f"
  226. echo "[+] Patched $f (pointer form)"
  227. else
  228. echo "[*] $f already patched"
  229. fi
  230. # Next (and tiann without 10_enable fallback) declares the 3 helpers as
  231. # static on 6.6, but kernel hooks.c/selinuxfs.c reference them as extern
  232. # after SUSFS (ReSukiSU uses __maybe_static -> global). Strip static so
  233. # the linker can resolve security_context_to_sid_with_policy etc.
  234. if grep -q "^static int security_context_to_sid_with_policy" "$f"; then
  235. echo "[*] Stripping static from $f helpers (Next 6.6)"
  236. sed -i 's/^static int security_context_to_sid_with_policy/int security_context_to_sid_with_policy/g' "$f"
  237. sed -i 's/^static int security_sid_to_context_with_policy/int security_sid_to_context_with_policy/g' "$f"
  238. sed -i 's/^static void security_compute_av_user_with_policy/void security_compute_av_user_with_policy/g' "$f"
  239. # also forward decls (same prefix, same sed covers them)
  240. echo "[+] Stripped static from $f"
  241. fi
  242. done
  243. else
  244. echo "[-] KVER $KVER < 6.6"
  245. fi
  246. - name: Baseband Guard
  247. if: (contains(inputs.feature_set, 'BBG') || inputs.feature_set == 'All')
  248. uses: ./.github/actions/bbg
  249. - name: Setup Networking
  250. if: contains(inputs.feature_set, 'NET') || inputs.feature_set == 'All'
  251. uses: ./.github/actions/networking
  252. with:
  253. version: ${{ inputs.version }}
  254. kernel_version: ${{ inputs.kernel_version }}
  255. android_version: ${{ inputs.android_version }}
  256. sublevel: ${{ steps.extract.outputs.sublevel }}
  257. - name: DroidSpaces-OSS Patches
  258. if: contains(inputs.feature_set, 'DS') || inputs.feature_set == 'All'
  259. uses: ./.github/actions/droidspaces
  260. with:
  261. version: ${{ inputs.version }}
  262. kernel_version: ${{ inputs.kernel_version }}
  263. droidspaces_commit: ${{ inputs.droidspaces_commit }}
  264. - name: Apply NTSync Patches
  265. if: contains(inputs.feature_set, 'NTSync')
  266. uses: ./.github/actions/ntsync
  267. with:
  268. version: ${{ inputs.version }}
  269. kernel_version: ${{ inputs.kernel_version }}
  270. sublevel: ${{ steps.extract.outputs.sublevel }}
  271. - name: Apply Ptrace Patch
  272. if: contains(inputs.feature_set, 'Ptrace')
  273. uses: ./.github/actions/ptrace
  274. with:
  275. kernel_version: ${{ inputs.kernel_version }}
  276. - name: Apply Unicode Fix Patch
  277. if: contains(inputs.feature_set, 'Unicode')
  278. uses: ./.github/actions/unicode-fix
  279. with:
  280. kernel_version: ${{ inputs.kernel_version }}
  281. - name: Apply Performance Patches
  282. uses: ./.github/actions/performance
  283. if: contains(inputs.feature_set, 'Perf')
  284. with:
  285. kernel_version: ${{ inputs.kernel_version }}
  286. - name: Setup Misc Configs
  287. uses: ./.github/actions/misc
  288. - name: Enable BPF Stack (BTF + eBPF + FUSE-BPF)
  289. if: contains(inputs.feature_set, 'BPF')
  290. uses: ./.github/actions/btf
  291. with:
  292. version: ${{ inputs.version }}
  293. kernel_version: ${{ inputs.kernel_version }}
  294. sublevel: ${{ steps.extract.outputs.sublevel }}
  295. - name: Apply Device-Specific Patches
  296. uses: ./.github/actions/apply-device-patches
  297. with:
  298. version: ${{ inputs.version }}
  299. kernel_version: ${{ inputs.kernel_version }}
  300. - name: Integrate NoMount
  301. if: contains(inputs.feature_set, 'NoMount') || inputs.feature_set == 'All'
  302. uses: ./.github/actions/nomount
  303. with:
  304. commit: ${{ inputs.nomount_commit }}
  305. kernel_version: ${{ inputs.kernel_version }}
  306. - name: Apply ABI Compare Bypass
  307. if: false
  308. working-directory: ${{ github.workspace }}/kernel
  309. run: |
  310. # ABI compare bypass per kernel/android version
  311. # Edit each block as needed per version
  312. if [[ "$ANDROID_VERSION" == "android12" && "$KERNEL_VERSION" == "5.10" ]]; then
  313. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/abi/compare_to_symbol_list
  314. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.10" ]]; then
  315. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  316. elif [[ "$ANDROID_VERSION" == "android13" && "$KERNEL_VERSION" == "5.15" ]]; then
  317. sed -i 's/^\s*exit 1$/ echo "Who Cares? Bypassing Now!"/' build/kernel/abi/compare_to_symbol_list
  318. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "5.15" ]]; then
  319. 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
  320. elif [[ "$ANDROID_VERSION" == "android14" && "$KERNEL_VERSION" == "6.1" ]]; then
  321. 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
  322. elif [[ "$ANDROID_VERSION" == "android15" && "$KERNEL_VERSION" == "6.6" ]]; then
  323. 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
  324. fi
  325. - name: Apply Kernel Branding
  326. uses: ./.github/actions/apply-kernel-branding
  327. with:
  328. variant: ${{ inputs.variant }}
  329. kernel_version: ${{ inputs.kernel_version }}
  330. android_version: ${{ inputs.android_version }}
  331. version: ${{ inputs.version }}
  332. sublevel: ${{ steps.extract.outputs.sublevel }}
  333. brand_name: ${{ inputs.brand_name }}
  334. - name: Remove Protected Exports
  335. uses: ./.github/actions/remove-protected-exports
  336. - name: Clean Kernel Flags
  337. uses: ./.github/actions/clean-kernel-flags
  338. - name: Scan and collect patch rejects
  339. id: scan
  340. if: always()
  341. uses: ./.github/actions/scan-patch-rejects
  342. - name: Upload Rejects
  343. if: always()
  344. uses: actions/upload-artifact@v7
  345. with:
  346. name: ${{ steps.extract.outputs.file_name }}-Rejects
  347. path: patch-rejects/
  348. if-no-files-found: ignore
  349. compression-level: 9
  350. - name: 'Setup Cache and Build Environment'
  351. if: inputs.use_cache
  352. uses: ./.github/actions/cache-setup
  353. with:
  354. version: ${{ inputs.version }}
  355. android_version: ${{ inputs.android_version }}
  356. kernel_version: ${{ inputs.kernel_version }}
  357. sublevel: ${{ steps.extract.outputs.sublevel }}
  358. - name: Restore ccache
  359. id: restore-ccache
  360. continue-on-error: true
  361. if: inputs.use_cache && (inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15')
  362. uses: ./.github/actions/cache-restore
  363. with:
  364. cache_path: /home/runner/.ccache
  365. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}-${{ inputs.variant }}
  366. cache_bucket: ccache-cache-${{ inputs.version }}-${{ inputs.variant }}
  367. restore_keys: |
  368. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  369. - name: Restore bazel-cache
  370. id: restore-bazel
  371. continue-on-error: true
  372. if: inputs.use_cache && (inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12')
  373. uses: ./.github/actions/cache-restore
  374. with:
  375. cache_path: /home/runner/.cache/bazel
  376. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}-${{ inputs.variant }}
  377. cache_bucket: bazel-cache-${{ inputs.version }}-${{ inputs.variant }}
  378. restore_keys: |
  379. ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  380. - name: Cache ccache (GitHub Native)
  381. if: false
  382. uses: actions/cache@v6
  383. with:
  384. path: /home/runner/.ccache
  385. key: ccache-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  386. restore-keys: |
  387. ccache-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  388. ccache-${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  389. ccache-
  390. - name: Cache bazel-cache (GitHub Native)
  391. if: false
  392. uses: actions/cache@v6
  393. with:
  394. path: /home/runner/.cache/bazel
  395. key: bazel-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  396. restore-keys: |
  397. bazel-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-
  398. bazel-${{ inputs.android_version }}-${{ inputs.kernel_version }}-
  399. bazel-
  400. - name: Check cache hit
  401. run: |
  402. echo "Cache restore status:"
  403. CCACHE_HIT="${{ steps.restore-ccache.outputs.cache-hit || 'skipped' }}"
  404. BAZEL_HIT="${{ steps.restore-bazel.outputs.cache-hit || 'skipped' }}"
  405. echo " ccache: $CCACHE_HIT"
  406. echo " bazel: $BAZEL_HIT"
  407. - name: Get Cache Stats
  408. uses: ./.github/actions/cache-stats
  409. with:
  410. clear_stats: true
  411. - name: Initialize Config Fragment
  412. run: touch "${{ github.workspace }}/wild_gki.fragment"
  413. - name: Apply Kernel Bypass Hack
  414. if: ${{ inputs.bypass == 'true' }}
  415. uses: ./.github/actions/bypass-kernel
  416. with:
  417. version: ${{ inputs.version }}
  418. bypass: true
  419. - name: Build Normal Kernel
  420. env:
  421. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  422. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  423. uses: ./.github/actions/build-kernel
  424. with:
  425. version: ${{ inputs.version }}
  426. - name: Get Cache Stats
  427. uses: ./.github/actions/cache-stats
  428. with:
  429. clear_stats: false
  430. - name: Prune ccache before save
  431. if: always() && inputs.use_cache && (inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15')
  432. shell: bash
  433. run: |
  434. if [ -d /home/runner/.ccache ]; then
  435. ccache -c 2>/dev/null || true
  436. find /home/runner/.ccache -type f -mtime +0.5 -delete 2>/dev/null || true
  437. find /home/runner/.ccache -type d -empty -delete 2>/dev/null || true
  438. echo "ccache pruned"; ccache -s 2>/dev/null | head -20 || true
  439. fi
  440. - name: Save ccache
  441. continue-on-error: true
  442. uses: ./.github/actions/cache-save
  443. if: always() && inputs.use_cache && (inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15')
  444. with:
  445. cache_path: /home/runner/.ccache
  446. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}-${{ inputs.variant }}
  447. cache_bucket: "ccache-cache-${{ inputs.version }}-${{ inputs.variant }}"
  448. compression_level: 9
  449. github_token: ${{ github.token }}
  450. - name: Save bazel-cache
  451. continue-on-error: true
  452. uses: ./.github/actions/cache-save
  453. if: always() && inputs.use_cache && (inputs.version == 'android14-5.15' || inputs.version == 'android14-6.1' || inputs.version == 'android15-6.6' || inputs.version == 'android16-6.12')
  454. with:
  455. cache_path: /home/runner/.cache/bazel
  456. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}-${{ inputs.variant }}
  457. cache_bucket: "bazel-cache-${{ inputs.version }}-${{ inputs.variant }}"
  458. compression_level: 9
  459. github_token: ${{ github.token }}
  460. - name: Build Bypass Kernel
  461. if: inputs.build_bypass
  462. env:
  463. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  464. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  465. uses: ./.github/actions/build-kernel
  466. with:
  467. version: ${{ inputs.version }}
  468. - name: Consolidated Build Summary
  469. if: always()
  470. shell: bash
  471. run: |
  472. SUMMARY_BASE="${{ steps.extract.outputs.file_name }}"
  473. if [ -z "${SUMMARY_BASE}" ]; then
  474. SUMMARY_BASE="${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }}"
  475. VARIANT="${{ inputs.variant }}"
  476. if [ -n "${VARIANT}" ] && [ "${VARIANT}" != "Normal" ]; then
  477. SUMMARY_BASE="${SUMMARY_BASE}-${VARIANT}"
  478. fi
  479. fi
  480. SUMMARY_FILE="/tmp/build-summary-${SUMMARY_BASE}.md"
  481. echo "SUMMARY_BASE=${SUMMARY_BASE}" >> "$GITHUB_ENV"
  482. # NoMount is optional (nomount_commit input is always populated, so
  483. # feature_set is the only reliable signal for whether it was built).
  484. NOMOUNT_ENABLED="false"
  485. if [ "${{ contains(inputs.feature_set, 'NoMount') || inputs.feature_set == 'All' }}" = "true" ]; then
  486. NOMOUNT_ENABLED="true"
  487. fi
  488. # Determine build status
  489. if [ "${{ job.status }}" = "success" ]; then
  490. STATUS="[+] Success"
  491. else
  492. STATUS="[-] Failed"
  493. fi
  494. # Get kernel version from Image if available
  495. KERNEL_VER_STR=""
  496. if [ -f "/home/runner/out/dist/Image" ]; then
  497. KERNEL_VER_STR=$(strings "/home/runner/out/dist/Image" | grep -m1 "^Linux version " | sed 's/Linux version //' || echo "")
  498. elif [ -f "/home/runner/out/Image" ]; then
  499. KERNEL_VER_STR=$(strings "/home/runner/out/Image" | grep -m1 "^Linux version " | sed 's/Linux version //' || echo "")
  500. fi
  501. # Get KSU version from env (set by kernelsu action)
  502. KSU_VER="${KSU_VERSION:-N/A}"
  503. KSU_TAG="${KSU_GIT_TAG:-N/A}"
  504. ROOT_IMPL="${ROOT_IMPLEMENTATION:-KernelSU-Next (legacy path)}"
  505. ROOT_MANAGER="${ROOT_MANAGER:-KernelSU-Next Manager}"
  506. ROOT_VERSION="${ROOT_VERSION:-${KSU_TAG}}"
  507. ROOT_SHA="${ROOT_COMMIT:-${KSU_COMMIT:-N/A}}"
  508. if [ "$NOMOUNT_ENABLED" = "true" ]; then
  509. NOMOUNT_SHA="${NOMOUNT_COMMIT:-${{ inputs.nomount_commit }}}"
  510. else
  511. NOMOUNT_SHA="N/A"
  512. fi
  513. SUSFS_SHA="${SUSFS_COMMIT:-${{ inputs.susfs_commit }}}"
  514. # Get SUSFS version from susfs.h if available
  515. SUSFS_VER="N/A"
  516. if [ -f "${{ github.workspace }}/kernel/common/include/linux/susfs.h" ]; then
  517. SUSFS_VER=$(grep '#define SUSFS_VERSION' "${{ github.workspace }}/kernel/common/include/linux/susfs.h" | awk -F'"' '{print $2}' || echo "N/A")
  518. fi
  519. # Get cache stats from env (set by cache-stats action)
  520. CCACHE_HIT="${CCACHE_HIT_RATE:-N/A}"
  521. # Get build time (approximate from step timing)
  522. BUILD_TIME="N/A"
  523. # Count warnings from build log if available
  524. WARNINGS="N/A"
  525. {
  526. echo "## ${{ inputs.android_version }} ${{ inputs.kernel_version }}.${{ inputs.sublevel }} (${{ inputs.variant }}) - ${STATUS}"
  527. echo
  528. echo "| Metric | Value |"
  529. echo "|--------|-------|"
  530. echo "| **Status** | ${STATUS} |"
  531. echo "| **Kernel** | ${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} |"
  532. if [ -n "$KERNEL_VER_STR" ]; then
  533. echo "| **Version String** | \`${KERNEL_VER_STR}\` |"
  534. fi
  535. echo "| **KSU Version** | ${KSU_VER} |"
  536. echo "| **KSU Tag** | ${KSU_TAG} |"
  537. echo "| **Root Implementation** | ${ROOT_IMPL} |"
  538. echo "| **Root Manager** | ${ROOT_MANAGER} |"
  539. echo "| **Root Version** | ${ROOT_VERSION} |"
  540. echo "| **Root Commit** | ${ROOT_SHA} |"
  541. echo "| **SUSFS Version** | ${SUSFS_VER} |"
  542. echo "| **SUSFS Commit** | ${SUSFS_SHA} |"
  543. echo "| **NoMount Commit** | ${NOMOUNT_SHA} |"
  544. echo "| **Feature Set** | ${{ inputs.feature_set }} |"
  545. echo "| **Variant** | ${{ inputs.variant }} |"
  546. echo
  547. # Kernel Fixes
  548. if [ -f /tmp/kernel-fixes-summary.md ]; then
  549. echo "### Kernel Fixes"
  550. cat /tmp/kernel-fixes-summary.md
  551. echo
  552. fi
  553. } > "$SUMMARY_FILE"
  554. - name: Upload Artifacts
  555. id: kernel-artifact
  556. uses: actions/upload-artifact@v7
  557. with:
  558. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  559. path: ${{ github.workspace }}/AnyKernel3/**
  560. if-no-files-found: ignore
  561. compression-level: 9
  562. - name: Write Build-verified only artifact metadata
  563. if: success() && inputs.root_flavor != ''
  564. shell: bash
  565. env:
  566. GH_TOKEN: ${{ github.token }}
  567. run: |
  568. set -euo pipefail
  569. # NoMount is optional: only resolve its artifact when requested.
  570. # (nomount_commit input is always populated, so feature_set is the
  571. # only reliable signal for whether NoMount was integrated.)
  572. NOMOUNT_ENABLED="false"
  573. if [ "${{ contains(inputs.feature_set, 'NoMount') || inputs.feature_set == 'All' }}" = "true" ]; then
  574. NOMOUNT_ENABLED="true"
  575. fi
  576. if [ "$NOMOUNT_ENABLED" = "true" ]; then
  577. METHOD="GKI source build with SHA-pinned root implementation, SUSFS, and NoMount"
  578. NOMOUNT_MODULE_COMMIT="${{ inputs.nomount_commit }}"
  579. else
  580. METHOD="GKI source build with SHA-pinned root implementation and SUSFS"
  581. NOMOUNT_MODULE_COMMIT="N/A"
  582. fi
  583. metadata_file="/tmp/${SUMMARY_BASE}-metadata.json"
  584. summary_file="/tmp/build-summary-${SUMMARY_BASE}.md"
  585. artifacts_api="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts?per_page=100"
  586. resolve_artifact() {
  587. local artifact_name="$1"
  588. local page=1
  589. local match=""
  590. local page_file
  591. page_file="$(mktemp)"
  592. # Page through the artifacts API, checking each page for the exact
  593. # artifact name. Uses a temp file for jq input (not argv) so large
  594. # artifact lists can't exceed the OS argument-length limit.
  595. while :; do
  596. curl --fail --silent --show-error --location \
  597. --header "Authorization: Bearer ${GH_TOKEN}" \
  598. --header "X-GitHub-Api-Version: 2022-11-28" \
  599. "${artifacts_api}&page=${page}" -o "$page_file"
  600. match="$(jq -r --arg name "$artifact_name" \
  601. '[.artifacts[] | select(.name == $name and .expired == false)] | .[0]
  602. | if . == null then "" else (.archive_download_url + "\t" + .digest) end' \
  603. "$page_file")"
  604. items="$(jq '(.artifacts | length) // 0' "$page_file")"
  605. if [ "$items" -lt 100 ] || [ -n "$match" ]; then
  606. break
  607. fi
  608. page=$((page + 1))
  609. done
  610. rm -f "$page_file"
  611. if [ -z "$match" ]; then
  612. echo "Expected exactly one available artifact named ${artifact_name}." >&2
  613. exit 1
  614. fi
  615. printf '%s\n' "$match"
  616. }
  617. read -r kernel_artifact_url kernel_artifact_sha256 < <(
  618. resolve_artifact "${{ steps.extract.outputs.file_name }}-AnyKernel3"
  619. )
  620. if [ "$NOMOUNT_ENABLED" = "true" ]; then
  621. read -r nomount_module_url nomount_module_sha256 < <(
  622. resolve_artifact "NoMount-Metamodule"
  623. )
  624. else
  625. nomount_module_url="N/A"
  626. nomount_module_sha256="N/A"
  627. fi
  628. jq -n \
  629. --arg method "$METHOD" \
  630. --arg root_implementation "${ROOT_IMPLEMENTATION:-KernelSU-Next (legacy path)}" \
  631. --arg root_manager "${ROOT_MANAGER:-KernelSU-Next Manager}" \
  632. --arg root_version "${ROOT_VERSION:-${KSU_GIT_TAG:-N/A}}" \
  633. --arg root_commit "${ROOT_COMMIT:-${KSU_COMMIT:-N/A}}" \
  634. --arg susfs_commit "${SUSFS_COMMIT:-N/A}" \
  635. --arg nomount_commit "${NOMOUNT_COMMIT:-N/A}" \
  636. --arg android_branch "${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}" \
  637. --arg kmi "${{ inputs.android_version }}-${{ inputs.kernel_version }}" \
  638. --arg kernel_source_commit "${KERNEL_SOURCE_COMMIT:-N/A}" \
  639. --arg provenance_url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
  640. --arg artifact_url "$kernel_artifact_url" \
  641. --arg sha256 "$kernel_artifact_sha256" \
  642. --arg nomount_module_commit "$NOMOUNT_MODULE_COMMIT" \
  643. --arg nomount_module_url "$nomount_module_url" \
  644. --arg nomount_module_sha256 "$nomount_module_sha256" \
  645. --arg status "Build-verified only" \
  646. --arg catalog_availability "eligible-with-provenance-and-checksums" \
  647. --arg device_compatibility "not-validated" \
  648. --arg flashability "not-guaranteed" \
  649. --arg boot "not-guaranteed" \
  650. '{
  651. method: $method,
  652. root: {
  653. implementation: $root_implementation,
  654. manager: $root_manager,
  655. version: $root_version,
  656. commit: $root_commit
  657. },
  658. susfs_revision: $susfs_commit,
  659. nomount_commit: $nomount_commit,
  660. android_branch: $android_branch,
  661. kmi: $kmi,
  662. kernel_source_commit: $kernel_source_commit,
  663. provenance_url: $provenance_url,
  664. artifact_url: $artifact_url,
  665. sha256: $sha256,
  666. nomount_metamodule: {
  667. commit: $nomount_module_commit,
  668. artifact_url: $nomount_module_url,
  669. sha256: $nomount_module_sha256
  670. },
  671. catalog: {
  672. availability: $catalog_availability,
  673. device_compatibility: $device_compatibility,
  674. flashability: $flashability,
  675. boot: $boot
  676. },
  677. status: $status
  678. }' > "$metadata_file"
  679. jq -e '
  680. .status == "Build-verified only" and
  681. (.root.manager | length > 0) and
  682. (.root.version | length > 0) and
  683. (.susfs_revision | test("^[0-9a-f]{40}$")) and
  684. (.kernel_source_commit | test("^[0-9a-f]{40}$")) and
  685. (.artifact_url | startswith("https://")) and
  686. (.sha256 | test("^sha256:[0-9a-f]{64}$")) and
  687. .catalog.availability == "eligible-with-provenance-and-checksums" and
  688. .catalog.device_compatibility == "not-validated" and
  689. .catalog.flashability == "not-guaranteed" and
  690. .catalog.boot == "not-guaranteed"
  691. ' "$metadata_file" > /dev/null
  692. if [ "$NOMOUNT_ENABLED" = "true" ]; then
  693. jq -e '
  694. (.nomount_commit | test("^[0-9a-f]{40}$")) and
  695. (.nomount_metamodule.commit == .nomount_commit) and
  696. (.nomount_metamodule.artifact_url | startswith("https://")) and
  697. (.nomount_metamodule.sha256 | test("^sha256:[0-9a-f]{64}$"))
  698. ' "$metadata_file" > /dev/null
  699. else
  700. jq -e '
  701. (.nomount_commit == "N/A") and
  702. (.nomount_metamodule.commit == "N/A") and
  703. (.nomount_metamodule.artifact_url == "N/A") and
  704. (.nomount_metamodule.sha256 == "N/A")
  705. ' "$metadata_file" > /dev/null
  706. fi
  707. # Merge the verified metadata into the combined summary markdown so both
  708. # live in a single artifact: human-readable table + machine JSON block.
  709. {
  710. echo
  711. echo "## Verified Metadata"
  712. echo
  713. echo '```json'
  714. cat "$metadata_file"
  715. echo '```'
  716. echo
  717. } >> "$summary_file"
  718. - name: Upload Build Summary + Metadata
  719. uses: actions/upload-artifact@v7
  720. with:
  721. name: ${{ steps.extract.outputs.file_name }}-BuildInfo
  722. path: /tmp/build-summary-${{ env.SUMMARY_BASE }}.md
  723. if-no-files-found: warn
  724. compression-level: 9