build.yml 33 KB

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