build.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. name: Kernel Build Process
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. branch:
  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. build_type:
  18. required: false
  19. type: string
  20. susfs:
  21. required: true
  22. type: string
  23. bbg:
  24. required: true
  25. type: string
  26. unicodefix:
  27. required: true
  28. type: string
  29. zeromount:
  30. required: true
  31. type: string
  32. nomount:
  33. required: true
  34. type: string
  35. ksun:
  36. required: true
  37. type: string
  38. droidspace:
  39. required: true
  40. type: string
  41. chroot:
  42. required: true
  43. type: string
  44. ntsync:
  45. required: true
  46. type: string
  47. bbrv1:
  48. required: true
  49. type: string
  50. bbrv3:
  51. required: true
  52. type: string
  53. cache:
  54. required: true
  55. type: string
  56. ipv6_nat:
  57. required: true
  58. type: string
  59. optimization:
  60. required: true
  61. type: string
  62. ttl:
  63. required: true
  64. type: string
  65. jobs:
  66. build-samsung-gki:
  67. name: "${{ inputs.branch }}-${{ inputs.kernel_version }}-${{ inputs.android_version }}"
  68. runs-on: ubuntu-latest
  69. strategy:
  70. fail-fast: false
  71. steps:
  72. - name: Checkout Repository
  73. uses: actions/checkout@v5
  74. - name: Free Disk Space
  75. if: true
  76. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  77. with:
  78. remove_android: true
  79. remove_dotnet: true
  80. remove_haskell: true
  81. remove_tool_cache: true
  82. remove_swap: true
  83. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  84. remove_packages_one_command: true
  85. 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"
  86. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  87. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  88. testing: false
  89. - name: Setup more Swap (for LTO)
  90. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  91. with:
  92. swap-size-gb: 25 # 10-24 GB is common for heavy LTO
  93. # swap-space-path: /mnt/swapfile # optional
  94. - name: Parse branch for cache keys
  95. if: inputs.cache == 'true'
  96. uses: ./.github/actions/parse-branch
  97. with:
  98. branch: ${{ inputs.branch }}
  99. # - name: set up bazel cache dir
  100. # if: inputs.build_type == 'Bazel' && inputs.cache == 'true'
  101. # run: |
  102. # BCACHE_DIR="${{ github.workspace }}/.cache/bazel-disk-kernel"
  103. # mkdir -p "$BCACHE_DIR"
  104. # echo "BCACHE_DIR=$BCACHE_DIR" >> $GITHUB_ENV
  105. # - name: set up bazel cache
  106. # if: inputs.build_type == 'Bazel' && inputs.cache == 'true'
  107. # uses: actions/cache@v4
  108. # with:
  109. # path: ${{ env.BCACHE_DIR }}
  110. # key: bcache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.FULL_BRANCH }}
  111. # restore-keys: |
  112. # bcache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.FULL_BRANCH }}
  113. - name: Install ccache
  114. if: inputs.cache == 'true' && inputs.build_type == 'make'
  115. run: sudo apt-get update && sudo apt-get install -y ccache
  116. - name: Export ccache + determinism
  117. if: inputs.cache == 'true' && inputs.build_type == 'make'
  118. run: |
  119. CACHE_DIR="${{ github.workspace }}/.ccache"
  120. mkdir -p "$CACHE_DIR"
  121. CCACHE_LOG="${{ github.workspace }}/ccache.log"
  122. SETTINGS=(
  123. "CCACHE_DIR=$CACHE_DIR"
  124. "CCACHE_MAXSIZE=12G"
  125. "CCACHE_COMPILERCHECK=content"
  126. "CCACHE_BASEDIR=${GITHUB_WORKSPACE}"
  127. "CCACHE_NOHASHDIR=true"
  128. "CCACHE_IGNOREOPTIONS=-sysroot* -fdebug-prefix-map=* -fmacro-prefix-map=*"
  129. "CCACHE_COMPRESS=true"
  130. "CCACHE_COMPRESSLEVEL=8"
  131. "CCACHE_DIRECT=true"
  132. "CCACHE_FILE_CLONE=true"
  133. "CCACHE_INODE_CACHE=true"
  134. "CCACHE_IS_KERNEL_COMPILING=true"
  135. "CCACHE_UMASK=002"
  136. "KBUILD_BUILD_TIMESTAMP=2026-01-01"
  137. "CCACHE_SLOPPINESS=file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale,file_stat_matches"
  138. )
  139. for setting in "${SETTINGS[@]}"; do
  140. export "$setting"
  141. echo "$setting" >> $GITHUB_ENV
  142. done
  143. if ccache --help 2>&1 | grep -q 'depend_mode'; then
  144. export CCACHE_DEPEND=true
  145. echo "CCACHE_DEPEND=true" >> "$GITHUB_ENV"
  146. fi
  147. - name: restore ccache
  148. if: inputs.cache == 'true' && inputs.build_type == 'make'
  149. uses: actions/cache@v4
  150. with:
  151. path: ${{ env.CCACHE_DIR }}
  152. key: ccache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.BASE_BRANCH }}
  153. restore-keys: |
  154. ccache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.BASE_BRANCH }}
  155. ccache-${{ runner.os }}-${{ inputs.build_type }}-
  156. - name: Ensure ccache is used
  157. if: inputs.cache == 'true' && inputs.build_type == 'make'
  158. run: |
  159. echo "/usr/lib/ccache" >> $GITHUB_PATH
  160. echo "CC='ccache clang'" >> $GITHUB_ENV
  161. echo "CXX='ccache clang++'" >> $GITHUB_ENV
  162. - name: Set CONFIG Environment Variable
  163. run: |
  164. # Set CONFIG dynamically based on inputs values
  165. CONFIG="${{ inputs.branch }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  166. # Set CONFIG as an environment variable for future steps
  167. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  168. - name: dependencies
  169. uses: ./.github/actions/dependencies
  170. with:
  171. zeromount: ${{ inputs.zeromount }}
  172. nomount: ${{ inputs.nomount }}
  173. susfs: ${{ inputs.susfs }}
  174. android_version: ${{ inputs.android_version }}
  175. kernel_version: ${{ inputs.kernel_version }}
  176. - name: Download Kernel
  177. uses: ./.github/actions/clone-kernel
  178. with:
  179. branch: ${{ inputs.branch }}
  180. - name: Set Path Environment Variables
  181. uses: ./.github/actions/env-variables
  182. with:
  183. branch: ${{ inputs.branch }}
  184. susfs: ${{ inputs.susfs }}
  185. zeromount: ${{ inputs.zeromount }}
  186. nomount: ${{ inputs.nomount }}
  187. - name: Extract all tar.xz files and delete them
  188. run: |
  189. cd "$CONFIG"
  190. find . -type f -name '*.tar.xz' -print0 | while IFS= read -r -d '' file; do
  191. echo "Extracting $file"
  192. tar -xf "$file"
  193. rm "$file"
  194. done
  195. - name: Add KernelSU-Next
  196. if: inputs.ksun == 'true'
  197. uses: ./.github/actions/ksun
  198. with:
  199. susfs: ${{ inputs.susfs }}
  200. - name: Apply SUSFS Patches
  201. if: inputs.susfs == 'true'
  202. uses: ./.github/actions/susfs-patches
  203. with:
  204. android_version: ${{ inputs.android_version }}
  205. kernel_version: ${{ inputs.kernel_version }}
  206. branch: ${{ inputs.branch }}
  207. nomount: ${{ inputs.nomount }}
  208. - name: Apply zeromount Patches
  209. if: inputs.susfs == 'true' && inputs.zeromount == 'true'
  210. uses: ./.github/actions/zeromount
  211. with:
  212. android_version: ${{ inputs.android_version }}
  213. kernel_version: ${{ inputs.kernel_version }}
  214. - name: add nomount
  215. if: inputs.nomount == 'true'
  216. uses: ./.github/actions/nomount
  217. with:
  218. kernel_version: ${{ inputs.kernel_version }}
  219. - name: Add BBG
  220. if: inputs.bbg == 'true'
  221. uses: ./.github/actions/bbg
  222. - name: Add unicodefix
  223. if: inputs.unicodefix == 'true'
  224. uses: ./.github/actions/unicode
  225. with:
  226. kernel_version: ${{ inputs.kernel_version }}
  227. - name: Add droidspace support
  228. if: inputs.droidspace == 'true'
  229. uses: ./.github/actions/droidspaces
  230. with:
  231. kernel_version: ${{ inputs.kernel_version }}
  232. - name: Add ubuntu-chroot support
  233. if: inputs.chroot == 'true'
  234. uses: ./.github/actions/chroot
  235. - name: Add ntsync
  236. if: inputs.ntsync == 'true'
  237. uses: ./.github/actions/ntsync
  238. with:
  239. android_version: ${{ inputs.android_version }}
  240. kernel_version: ${{ inputs.kernel_version }}
  241. - name: Add bbrv1
  242. if: inputs.bbrv1 == 'true'
  243. uses: ./.github/actions/bbrv1
  244. - name: Add bbrv3
  245. if: inputs.bbrv3 == 'true'
  246. uses: ./.github/actions/bbrv3
  247. with:
  248. android_version: ${{ inputs.android_version }}
  249. kernel_version: ${{ inputs.kernel_version }}
  250. - name: Add IP-SET and IPv6_NAT support
  251. if: inputs.ipv6_nat == 'true'
  252. uses: ./.github/actions/IPv6_NAT
  253. - name: Add TTL support
  254. if: inputs.ttl == 'true'
  255. uses: ./.github/actions/TTL
  256. - name: add optimization patches
  257. if: inputs.optimization == 'true'
  258. uses: ./.github/actions/optimization
  259. with:
  260. kernel_version: ${{ inputs.kernel_version }}
  261. branch: ${{ inputs.branch }}
  262. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  263. if: inputs.kernel_version == '6.6'
  264. uses: ./.github/actions/6.6-fix
  265. with:
  266. branch: ${{ inputs.branch }}
  267. - name: temp fix for m55 bootloop maybe
  268. if: inputs.branch == 'SM-M556B-Oneui8'
  269. uses: ./.github/actions/m55-fix
  270. - name: Set Kernel Configuration Variables
  271. if: inputs.ksun == 'true'
  272. uses: ./.github/actions/configs
  273. with:
  274. branch: ${{ inputs.branch }}
  275. - name: Change Kernel Name and clean dirty
  276. uses: ./.github/actions/kernel-name
  277. - name: remove protected exports
  278. uses: ./.github/actions/abi-export
  279. - name: Set file name
  280. if: inputs.ksun == 'true'
  281. uses: ./.github/actions/file-name
  282. with:
  283. branch: ${{ inputs.branch }}
  284. ksun: ${{ inputs.ksun }}
  285. susfs: ${{ inputs.susfs }}
  286. zeromount: ${{ inputs.zeromount }}
  287. bbg: ${{ inputs.bbg }}
  288. bbrv1: ${{ inputs.bbrv1 }}
  289. bbrv3: ${{ inputs.bbrv3 }}
  290. droidspaces: ${{ inputs.droidspace }}
  291. ntsync: ${{ inputs.ntsync }}
  292. ipv6_nat: ${{ inputs.ipv6_nat }}
  293. ttl: ${{ inputs.ttl }}
  294. unicodefix: ${{ inputs.unicodefix }}
  295. # - name: ensure bazel cache is set to be used
  296. # if: inputs.build_type == 'Bazel' && inputs.cache == 'true'
  297. # uses: ./.github/actions/use-bazcache
  298. - name: change variables to ccache
  299. if: inputs.cache == 'true' && inputs.build_type == 'make'
  300. uses: ./.github/actions/use-ccache
  301. - name: Build
  302. uses: ./.github/actions/build
  303. with:
  304. branch: ${{ inputs.branch }}
  305. build_type: ${{ inputs.build_type }}
  306. kernel_version: ${{ inputs.kernel_version }}
  307. - name: clean up ccache
  308. if: inputs.cache == 'true' && inputs.build_type == 'make'
  309. run: ccache -c
  310. - name: ccache stats
  311. if: inputs.cache == 'true' && inputs.build_type == 'make'
  312. run: ccache -s -v || ccache -s
  313. # - name: bazel cache stats
  314. # if: inputs.cache == 'true' && inputs.build_type == 'Bazel'
  315. # run: bazel analyze-profile profile.json
  316. - name: Prepare AnyKernel3
  317. uses: ./.github/actions/ak3zip-prep
  318. with:
  319. branch: ${{ inputs.branch }}
  320. - name: Upload AnyKernel3 Artifacts
  321. id: upload_ak3
  322. uses: actions/upload-artifact@v6
  323. with:
  324. name: ${{ env.FILE_NAME }}-AnyKernel3
  325. path: |
  326. ./AnyKernel3/**
  327. compression-level: 9
  328. - name: Scan and collect patch rejects
  329. if: ${{ always() }}
  330. run: |
  331. set -e
  332. CONFIG_DIR="$CONFIG"
  333. REJECTS_DIR="$GITHUB_WORKSPACE/patch-rejects"
  334. mkdir -p "$REJECTS_DIR"
  335. # Find all .rej files under the configuration directory
  336. mapfile -t REJS < <(find "$CONFIG_DIR" -type f -name '*.rej')
  337. REJ_COUNT=${#REJS[@]}
  338. echo "Found $REJ_COUNT .rej files under $CONFIG_DIR"
  339. echo "REJ_COUNT=$REJ_COUNT" >> $GITHUB_ENV
  340. if [ "$REJ_COUNT" -gt 0 ]; then
  341. for REJ in "${REJS[@]}"; do
  342. # Relative path from $CONFIG
  343. REL="${REJ#"$CONFIG_DIR"/}"
  344. DEST="$REJECTS_DIR/$REL"
  345. mkdir -p "$(dirname "$DEST")"
  346. cp "$REJ" "$DEST"
  347. # Copy the associated original file alongside the .rej
  348. ORIG="${REJ%.rej}"
  349. if [ -f "$ORIG" ]; then
  350. ORIG_DEST="$REJECTS_DIR/${REL%.rej}"
  351. mkdir -p "$(dirname "$ORIG_DEST")"
  352. cp "$ORIG" "$ORIG_DEST"
  353. fi
  354. echo "$REL" >> "$REJECTS_DIR/index.txt"
  355. done
  356. fi
  357. - name: Generate Build Summary
  358. if: ${{ always() }}
  359. run: |
  360. # Create build summary file for inclusion in Misc artifact
  361. echo "# Kernel Build Summary" > build_summary.md
  362. # Add build variant header
  363. echo "## ${{ env.FILE_NAME }}" >> build_summary.md
  364. # Add build info
  365. echo "## Build Information" >> build_summary.md
  366. echo "- **Android Version**: ${{ inputs.android_version }}" >> build_summary.md
  367. echo "- **Kernel Version**: ${{ inputs.kernel_version }}.${{ inputs.sub_level }}" >> build_summary.md
  368. echo "- **BBG**: Installed" >> build_summary.md
  369. echo "" >> build_summary.md
  370. # Get KernelSU-Next commit
  371. if [ -d "$CONFIG/KernelSU-Next" ]; then
  372. cd "$CONFIG/KernelSU-Next"
  373. KSUN_COMMIT=$(git rev-parse HEAD)
  374. KSUN_URL="https://github.com/WildKernels/KernelSU-Next/commit/$KSUN_COMMIT"
  375. echo "- **KernelSU-Next**: [$KSUN_COMMIT]($KSUN_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  376. cd "$GITHUB_WORKSPACE"
  377. else
  378. echo "- **KernelSU-Next**: not present" >> build_summary.md
  379. fi
  380. # Get Baseband-guard commit
  381. if [ -d "$CONFIG/Baseband-guard" ]; then
  382. cd "$CONFIG/Baseband-guard"
  383. BBG_COMMIT=$(git rev-parse HEAD)
  384. BBG_URL="https://github.com/vc-teahouse/Baseband-guard/commit/$BBG_COMMIT"
  385. echo "- **Baseband-guard**: [$BBG_COMMIT]($BBG_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  386. cd "$GITHUB_WORKSPACE"
  387. else
  388. echo "- **Baseband-guard**: not present" >> build_summary.md
  389. fi
  390. # Get SUSFS4KSU commit
  391. if [ -d "$GITHUB_WORKSPACE/susfs4ksu" ]; then
  392. cd "$GITHUB_WORKSPACE/susfs4ksu"
  393. SUSFS_COMMIT=$(git rev-parse HEAD)
  394. SUSFS_URL="https://gitlab.com/simonpunk/susfs4ksu/-/commit/$SUSFS_COMMIT"
  395. echo "- **SUSFS4KSU (v2.1.0)**: [$SUSFS_COMMIT]($SUSFS_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  396. cd "$GITHUB_WORKSPACE"
  397. else
  398. echo "- **SUSFS4KSU (v2.1.0)**: not present" >> build_summary.md
  399. fi
  400. echo "" >> build_summary.md
  401. # Add artifact summary with presence verification
  402. echo "## Build Artifacts" >> build_summary.md
  403. # Verify AnyKernel3 contents - check if kernel Image was actually copied (indicates successful build)
  404. if [ -d "AnyKernel3" ] && [ -f "AnyKernel3/Image" ]; then
  405. AK3_STATUS="✅"
  406. else
  407. AK3_STATUS="❌"
  408. fi
  409. echo "- **AnyKernel3**: $AK3_STATUS ${{ env.FILE_NAME }}-AnyKernel3" >> build_summary.md
  410. echo "### Misc (uploaded files)" >> build_summary.md
  411. FILES_PRESENT=0
  412. for f in "${{ env.FILE_NAME }}-Image" "${{ env.FILE_NAME }}-Image.gz" "${{ env.FILE_NAME }}-Image.lz4" "${{ env.FILE_NAME }}-boot.img" "${{ env.FILE_NAME }}-boot-gz.img" "${{ env.FILE_NAME }}-boot-lz4.img"; do
  413. if [ -f "$f" ]; then FILES_PRESENT=$((FILES_PRESENT+1)); fi
  414. done
  415. if [ "$FILES_PRESENT" -gt 0 ]; then
  416. MISC_STATUS="✅"
  417. else
  418. MISC_STATUS="❌"
  419. fi
  420. echo "- **Set**: $MISC_STATUS ${{ env.FILE_NAME }}-Misc" >> build_summary.md
  421. if [ "$MISC_STATUS" = "✅" ]; then
  422. echo " Included:" >> build_summary.md
  423. for f in "${{ env.FILE_NAME }}-Image" "${{ env.FILE_NAME }}-Image.gz" "${{ env.FILE_NAME }}-Image.lz4" "${{ env.FILE_NAME }}-boot.img" "${{ env.FILE_NAME }}-boot-gz.img" "${{ env.FILE_NAME }}-boot-lz4.img"; do
  424. if [ -f "$f" ]; then
  425. echo " - $f" >> build_summary.md
  426. fi
  427. done
  428. fi
  429. echo "### Diagnostics" >> build_summary.md
  430. echo "- **Rejected Patches**: ${{ env.FILE_NAME }}-Rejected-Patches" >> build_summary.md
  431. if [ -f patch-rejects/index.txt ]; then
  432. if [ -s patch-rejects/index.txt ]; then
  433. echo " Rejected files:" >> build_summary.md
  434. while IFS= read -r line; do
  435. echo " - $line" >> build_summary.md
  436. done < patch-rejects/index.txt
  437. else
  438. echo " Rejected file list is empty." >> build_summary.md
  439. fi
  440. else
  441. echo " No rejected patches found." >> build_summary.md
  442. fi