build.yml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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: inputs.nomount_commit != '' || 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 }}
  367. cache_bucket: ccache-cache
  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 }}
  378. cache_bucket: bazel-cache
  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. bypass: false
  428. - name: Get Cache Stats
  429. uses: ./.github/actions/cache-stats
  430. with:
  431. clear_stats: false
  432. - name: Prune ccache before save
  433. if: always() && inputs.use_cache && (inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15')
  434. shell: bash
  435. run: |
  436. if [ -d /home/runner/.ccache ]; then
  437. ccache -c 2>/dev/null || true
  438. find /home/runner/.ccache -type f -mtime +0.5 -delete 2>/dev/null || true
  439. find /home/runner/.ccache -type d -empty -delete 2>/dev/null || true
  440. echo "ccache pruned"; ccache -s 2>/dev/null | head -20 || true
  441. fi
  442. - name: Save ccache
  443. continue-on-error: true
  444. uses: ./.github/actions/cache-save
  445. if: always() && inputs.use_cache && (inputs.version == 'android12-5.10' || inputs.version == 'android13-5.10' || inputs.version == 'android13-5.15')
  446. with:
  447. cache_path: /home/runner/.ccache
  448. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  449. cache_bucket: "ccache-cache"
  450. compression_level: 9
  451. github_token: ${{ github.token }}
  452. - name: Save bazel-cache
  453. continue-on-error: true
  454. uses: ./.github/actions/cache-save
  455. 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')
  456. with:
  457. cache_path: /home/runner/.cache/bazel
  458. cache_key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ steps.extract.outputs.sublevel }}-${{ inputs.os_patch_level }}
  459. cache_bucket: "bazel-cache"
  460. compression_level: 9
  461. github_token: ${{ github.token }}
  462. - name: Build Bypass Kernel
  463. if: inputs.build_bypass
  464. env:
  465. SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
  466. KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
  467. uses: ./.github/actions/build-kernel
  468. with:
  469. bypass: true
  470. version: ${{ inputs.version }}
  471. - name: Consolidated Build Summary
  472. if: always()
  473. shell: bash
  474. run: |
  475. SUMMARY_BASE="${{ steps.extract.outputs.file_name }}"
  476. if [ -z "${SUMMARY_BASE}" ]; then
  477. SUMMARY_BASE="${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }}"
  478. VARIANT="${{ inputs.variant }}"
  479. if [ -n "${VARIANT}" ] && [ "${VARIANT}" != "Normal" ]; then
  480. SUMMARY_BASE="${SUMMARY_BASE}-${VARIANT}"
  481. fi
  482. fi
  483. SUMMARY_FILE="/tmp/build-summary-${SUMMARY_BASE}.md"
  484. echo "SUMMARY_BASE=${SUMMARY_BASE}" >> "$GITHUB_ENV"
  485. # Determine build status
  486. if [ "${{ job.status }}" = "success" ]; then
  487. STATUS="[+] Success"
  488. else
  489. STATUS="[-] Failed"
  490. fi
  491. # Get kernel version from Image if available
  492. KERNEL_VER_STR=""
  493. if [ -f "/home/runner/out/dist/Image" ]; then
  494. KERNEL_VER_STR=$(strings "/home/runner/out/dist/Image" | grep -m1 "^Linux version " | sed 's/Linux version //' || echo "")
  495. elif [ -f "/home/runner/out/Image" ]; then
  496. KERNEL_VER_STR=$(strings "/home/runner/out/Image" | grep -m1 "^Linux version " | sed 's/Linux version //' || echo "")
  497. fi
  498. # Get KSU version from env (set by kernelsu action)
  499. KSU_VER="${KSU_VERSION:-N/A}"
  500. KSU_TAG="${KSU_GIT_TAG:-N/A}"
  501. ROOT_IMPL="${ROOT_IMPLEMENTATION:-KernelSU-Next (legacy path)}"
  502. ROOT_MANAGER="${ROOT_MANAGER:-KernelSU-Next Manager}"
  503. ROOT_VERSION="${ROOT_VERSION:-${KSU_TAG}}"
  504. ROOT_SHA="${ROOT_COMMIT:-${KSU_COMMIT:-N/A}}"
  505. NOMOUNT_SHA="${NOMOUNT_COMMIT:-${{ inputs.nomount_commit }}}"
  506. SUSFS_SHA="${SUSFS_COMMIT:-${{ inputs.susfs_commit }}}"
  507. # Get SUSFS version from susfs.h if available
  508. SUSFS_VER="N/A"
  509. if [ -f "${{ github.workspace }}/kernel/common/include/linux/susfs.h" ]; then
  510. SUSFS_VER=$(grep '#define SUSFS_VERSION' "${{ github.workspace }}/kernel/common/include/linux/susfs.h" | awk -F'"' '{print $2}' || echo "N/A")
  511. fi
  512. # Get cache stats from env (set by cache-stats action)
  513. CCACHE_HIT="${CCACHE_HIT_RATE:-N/A}"
  514. # Get build time (approximate from step timing)
  515. BUILD_TIME="N/A"
  516. # Count warnings from build log if available
  517. WARNINGS="N/A"
  518. {
  519. echo "## ${{ inputs.android_version }} ${{ inputs.kernel_version }}.${{ inputs.sublevel }} (${{ inputs.variant }}) - ${STATUS}"
  520. echo
  521. echo "| Metric | Value |"
  522. echo "|--------|-------|"
  523. echo "| **Status** | ${STATUS} |"
  524. echo "| **Kernel** | ${{ inputs.kernel_version }}.${{ inputs.sublevel }}-${{ inputs.android_version }}-${{ inputs.os_patch_level }} |"
  525. if [ -n "$KERNEL_VER_STR" ]; then
  526. echo "| **Version String** | \`${KERNEL_VER_STR}\` |"
  527. fi
  528. echo "| **KSU Version** | ${KSU_VER} |"
  529. echo "| **KSU Tag** | ${KSU_TAG} |"
  530. echo "| **Root Implementation** | ${ROOT_IMPL} |"
  531. echo "| **Root Manager** | ${ROOT_MANAGER} |"
  532. echo "| **Root Version** | ${ROOT_VERSION} |"
  533. echo "| **Root Commit** | ${ROOT_SHA} |"
  534. echo "| **SUSFS Version** | ${SUSFS_VER} |"
  535. echo "| **SUSFS Commit** | ${SUSFS_SHA} |"
  536. echo "| **NoMount Commit** | ${NOMOUNT_SHA} |"
  537. echo "| **Feature Set** | ${{ inputs.feature_set }} |"
  538. echo "| **Variant** | ${{ inputs.variant }} |"
  539. echo
  540. # Kernel Fixes
  541. if [ -f /tmp/kernel-fixes-summary.md ]; then
  542. echo "### Kernel Fixes"
  543. cat /tmp/kernel-fixes-summary.md
  544. echo
  545. fi
  546. } > "$SUMMARY_FILE"
  547. - name: Upload Artifacts
  548. id: kernel-artifact
  549. uses: actions/upload-artifact@v7
  550. with:
  551. name: ${{ steps.extract.outputs.file_name }}-AnyKernel3
  552. path: ${{ github.workspace }}/AnyKernel3/**
  553. if-no-files-found: ignore
  554. compression-level: 9
  555. - name: Write Build-verified only artifact metadata
  556. if: success() && inputs.root_flavor != '' && inputs.nomount_commit != ''
  557. shell: bash
  558. env:
  559. GH_TOKEN: ${{ github.token }}
  560. run: |
  561. set -euo pipefail
  562. metadata_file="/tmp/${SUMMARY_BASE}-metadata.json"
  563. summary_file="/tmp/build-summary-${SUMMARY_BASE}.md"
  564. artifacts_api="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts?per_page=100"
  565. resolve_artifact() {
  566. local artifact_name="$1"
  567. local page=1
  568. local match=""
  569. local page_file
  570. page_file="$(mktemp)"
  571. # Page through the artifacts API, checking each page for the exact
  572. # artifact name. Uses a temp file for jq input (not argv) so large
  573. # artifact lists can't exceed the OS argument-length limit.
  574. while :; do
  575. curl --fail --silent --show-error --location \
  576. --header "Authorization: Bearer ${GH_TOKEN}" \
  577. --header "X-GitHub-Api-Version: 2022-11-28" \
  578. "${artifacts_api}&page=${page}" -o "$page_file"
  579. match="$(jq -r --arg name "$artifact_name" \
  580. '[.artifacts[] | select(.name == $name and .expired == false)] | .[0]
  581. | if . == null then "" else (.archive_download_url + "\t" + .digest) end' \
  582. "$page_file")"
  583. items="$(jq '(.artifacts | length) // 0' "$page_file")"
  584. if [ "$items" -lt 100 ] || [ -n "$match" ]; then
  585. break
  586. fi
  587. page=$((page + 1))
  588. done
  589. rm -f "$page_file"
  590. if [ -z "$match" ]; then
  591. echo "Expected exactly one available artifact named ${artifact_name}." >&2
  592. exit 1
  593. fi
  594. printf '%s\n' "$match"
  595. }
  596. read -r kernel_artifact_url kernel_artifact_sha256 < <(
  597. resolve_artifact "${{ steps.extract.outputs.file_name }}-AnyKernel3"
  598. )
  599. read -r nomount_module_url nomount_module_sha256 < <(
  600. resolve_artifact "NoMount-Metamodule"
  601. )
  602. jq -n \
  603. --arg method "GKI source build with SHA-pinned root implementation, SUSFS, and NoMount" \
  604. --arg root_implementation "${ROOT_IMPLEMENTATION:-KernelSU-Next (legacy path)}" \
  605. --arg root_manager "${ROOT_MANAGER:-KernelSU-Next Manager}" \
  606. --arg root_version "${ROOT_VERSION:-${KSU_GIT_TAG:-N/A}}" \
  607. --arg root_commit "${ROOT_COMMIT:-${KSU_COMMIT:-N/A}}" \
  608. --arg susfs_commit "${SUSFS_COMMIT:-N/A}" \
  609. --arg nomount_commit "${NOMOUNT_COMMIT:-N/A}" \
  610. --arg android_branch "${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}" \
  611. --arg kmi "${{ inputs.android_version }}-${{ inputs.kernel_version }}" \
  612. --arg kernel_source_commit "${KERNEL_SOURCE_COMMIT:-N/A}" \
  613. --arg provenance_url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
  614. --arg artifact_url "$kernel_artifact_url" \
  615. --arg sha256 "$kernel_artifact_sha256" \
  616. --arg nomount_module_commit "${{ inputs.nomount_commit }}" \
  617. --arg nomount_module_url "$nomount_module_url" \
  618. --arg nomount_module_sha256 "$nomount_module_sha256" \
  619. --arg status "Build-verified only" \
  620. --arg catalog_availability "eligible-with-provenance-and-checksums" \
  621. --arg device_compatibility "not-validated" \
  622. --arg flashability "not-guaranteed" \
  623. --arg boot "not-guaranteed" \
  624. '{
  625. method: $method,
  626. root: {
  627. implementation: $root_implementation,
  628. manager: $root_manager,
  629. version: $root_version,
  630. commit: $root_commit
  631. },
  632. susfs_revision: $susfs_commit,
  633. nomount_commit: $nomount_commit,
  634. android_branch: $android_branch,
  635. kmi: $kmi,
  636. kernel_source_commit: $kernel_source_commit,
  637. provenance_url: $provenance_url,
  638. artifact_url: $artifact_url,
  639. sha256: $sha256,
  640. nomount_metamodule: {
  641. commit: $nomount_module_commit,
  642. artifact_url: $nomount_module_url,
  643. sha256: $nomount_module_sha256
  644. },
  645. catalog: {
  646. availability: $catalog_availability,
  647. device_compatibility: $device_compatibility,
  648. flashability: $flashability,
  649. boot: $boot
  650. },
  651. status: $status
  652. }' > "$metadata_file"
  653. jq -e '
  654. .status == "Build-verified only" and
  655. (.root.manager | length > 0) and
  656. (.root.version | length > 0) and
  657. (.susfs_revision | test("^[0-9a-f]{40}$")) and
  658. (.nomount_commit | test("^[0-9a-f]{40}$")) and
  659. (.kernel_source_commit | test("^[0-9a-f]{40}$")) and
  660. (.artifact_url | startswith("https://")) and
  661. (.sha256 | test("^sha256:[0-9a-f]{64}$")) and
  662. (.nomount_metamodule.commit == .nomount_commit) and
  663. (.nomount_metamodule.artifact_url | startswith("https://")) and
  664. (.nomount_metamodule.sha256 | test("^sha256:[0-9a-f]{64}$")) and
  665. .catalog.availability == "eligible-with-provenance-and-checksums" and
  666. .catalog.device_compatibility == "not-validated" and
  667. .catalog.flashability == "not-guaranteed" and
  668. .catalog.boot == "not-guaranteed"
  669. ' "$metadata_file" > /dev/null
  670. # Merge the verified metadata into the combined summary markdown so both
  671. # live in a single artifact: human-readable table + machine JSON block.
  672. {
  673. echo
  674. echo "## Verified Metadata"
  675. echo
  676. echo '```json'
  677. cat "$metadata_file"
  678. echo '```'
  679. echo
  680. } >> "$summary_file"
  681. - name: Upload Build Summary + Metadata
  682. uses: actions/upload-artifact@v7
  683. with:
  684. name: ${{ steps.extract.outputs.file_name }}-BuildInfo
  685. path: /tmp/build-summary-${{ env.SUMMARY_BASE }}.md
  686. if-no-files-found: warn
  687. compression-level: 9