build.yml 34 KB

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