build.yml 34 KB

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