build.yml 31 KB

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