build.yml 32 KB

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