build.yml 35 KB

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