build.yml 17 KB

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