build.yml 16 KB

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