build.yml 31 KB

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