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