build.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. build_type:
  12. required: false
  13. type: string
  14. susfs:
  15. required: true
  16. type: string
  17. bbg:
  18. required: true
  19. type: string
  20. unicodefix:
  21. required: true
  22. type: string
  23. zeromount:
  24. required: true
  25. type: string
  26. nomount:
  27. required: true
  28. type: string
  29. ksun:
  30. required: true
  31. type: string
  32. droidspace:
  33. required: true
  34. type: string
  35. ntsync:
  36. required: true
  37. type: string
  38. bbrv3:
  39. required: true
  40. type: string
  41. cache:
  42. required: true
  43. type: string
  44. ipv6_nat:
  45. required: true
  46. type: string
  47. optimization:
  48. required: true
  49. type: string
  50. ttl:
  51. required: true
  52. type: string
  53. lto:
  54. required: true
  55. type: string
  56. jobs:
  57. build-samsung-gki:
  58. name: "${{ inputs.branch }}"
  59. runs-on: ubuntu-latest
  60. strategy:
  61. fail-fast: false
  62. steps:
  63. - name: Checkout Repository
  64. uses: actions/checkout@v5
  65. - name: Store branch as env variable
  66. run: BRANCH=${{ inputs.branch }} && echo "BRANCH=$BRANCH" >> $GITHUB_ENV
  67. - name: get kernel version before cloning
  68. uses: ./.github/actions/kernel-info
  69. - name: Store LTO as env variable
  70. run: |
  71. if [[ $KERNEL_VER != 6.6 ]]; then
  72. BUILD_LTO=${{ inputs.lto }} && echo "BUILD_LTO=$BUILD_LTO" >> $GITHUB_ENV
  73. else
  74. BUILD_LTO="default" && echo "BUILD_LTO=$BUILD_LTO" >> $GITHUB_ENV
  75. fi
  76. - name: Free Disk Space
  77. if: true
  78. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  79. with:
  80. remove_android: true
  81. remove_dotnet: true
  82. remove_haskell: true
  83. remove_tool_cache: true
  84. remove_swap: true
  85. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  86. remove_packages_one_command: true
  87. 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"
  88. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  89. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  90. testing: false
  91. - name: Setup more Swap (for LTO)
  92. uses: pierotofy/set-swap-space@master # or thejerrybao/setup-swap-space@v1
  93. with:
  94. swap-size-gb: 25 # 10-24 GB is common for heavy LTO
  95. # swap-space-path: /mnt/swapfile # optional
  96. - name: Parse branch for cache keys
  97. if: inputs.cache == 'true' && inputs.build_type == 'make'
  98. uses: ./.github/actions/parse-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@v6
  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@v6
  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="$BRANCH-$ANDROID_VERSION_$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. - name: Download Kernel
  171. uses: ./.github/actions/clone-kernel
  172. - name: Set Path Environment Variables
  173. uses: ./.github/actions/env-variables
  174. - name: Extract all tar.xz files and delete them
  175. run: |
  176. cd "$CONFIG"
  177. find . -type f -name '*.tar.xz' -print0 | while IFS= read -r -d '' file; do
  178. echo "Extracting $file"
  179. tar -xf "$file"
  180. rm "$file"
  181. done
  182. - name: Add KernelSU-Next
  183. if: inputs.ksun == 'true'
  184. uses: ./.github/actions/ksun
  185. with:
  186. susfs: ${{ inputs.susfs }}
  187. - name: Add SUSFS
  188. if: inputs.susfs == 'true'
  189. uses: ./.github/actions/susfs-patches
  190. with:
  191. nomount: ${{ inputs.nomount }}
  192. - name: Add Zeromount
  193. if: inputs.susfs == 'true' && inputs.zeromount == 'true'
  194. uses: ./.github/actions/zeromount
  195. - name: add nomount
  196. if: inputs.nomount == 'true'
  197. uses: ./.github/actions/nomount
  198. - name: Add BBG
  199. if: inputs.bbg == 'true'
  200. uses: ./.github/actions/bbg
  201. - name: Add unicodefix
  202. if: inputs.unicodefix == 'true'
  203. uses: ./.github/actions/unicode
  204. - name: Add droidspace support
  205. if: inputs.droidspace == 'true'
  206. uses: ./.github/actions/droidspaces
  207. - name: Add ntsync
  208. if: inputs.ntsync == 'true'
  209. uses: ./.github/actions/ntsync
  210. - name: Add bbrv3
  211. if: inputs.bbrv3 == 'true'
  212. uses: ./.github/actions/bbrv3
  213. - name: Add IP-SET and IPv6_NAT support
  214. if: inputs.ipv6_nat == 'true'
  215. uses: ./.github/actions/IPv6_NAT
  216. - name: Add TTL support
  217. if: inputs.ttl == 'true'
  218. uses: ./.github/actions/TTL
  219. - name: add optimization patches
  220. if: inputs.optimization == 'true' && !startsWith(env.BRANCH, 'SM-S711')
  221. uses: ./.github/actions/optimization
  222. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  223. if: ${{ env.KERNEL_VER == '6.6' }}
  224. uses: ./.github/actions/6.6-fix
  225. - name: temp fix for m55 bootloop maybe
  226. if: inputs.branch == 'SM-M556B-Oneui8'
  227. uses: ./.github/actions/m55-fix
  228. - name: Set Kernel Configuration Variables
  229. if: inputs.ksun == 'true'
  230. uses: ./.github/actions/configs
  231. - name: Change Kernel Name and clean dirty
  232. uses: ./.github/actions/kernel-name
  233. - name: remove protected exports
  234. uses: ./.github/actions/abi-export
  235. - name: Set file name
  236. if: inputs.ksun == 'true'
  237. uses: ./.github/actions/file-name
  238. with:
  239. ksun: ${{ inputs.ksun }}
  240. susfs: ${{ inputs.susfs }}
  241. zeromount: ${{ inputs.zeromount }}
  242. nomount: ${{ inputs.nomount }}
  243. bbg: ${{ inputs.bbg }}
  244. bbrv3: ${{ inputs.bbrv3 }}
  245. droidspaces: ${{ inputs.droidspace }}
  246. ntsync: ${{ inputs.ntsync }}
  247. ipv6_nat: ${{ inputs.ipv6_nat }}
  248. ttl: ${{ inputs.ttl }}
  249. unicodefix: ${{ inputs.unicodefix }}
  250. # - name: ensure bazel cache is set to be used
  251. # if: inputs.build_type == 'Bazel' && inputs.cache == 'true'
  252. # uses: ./.github/actions/use-bazcache
  253. - name: change variables to ccache
  254. if: inputs.cache == 'true' && inputs.build_type == 'make'
  255. uses: ./.github/actions/use-ccache
  256. - name: configure LTO
  257. uses: ./.github/actions/lto
  258. - name: Build
  259. uses: ./.github/actions/build
  260. with:
  261. build_type: ${{ inputs.build_type }}
  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. - name: Upload AnyKernel3 Artifacts
  274. id: upload_ak3
  275. uses: actions/upload-artifact@v6
  276. with:
  277. name: ${{ env.FILE_NAME }}-AnyKernel3
  278. path: |
  279. ./AnyKernel3/**
  280. compression-level: 9
  281. - name: Scan and collect patch rejects
  282. if: ${{ always() }}
  283. run: |
  284. set -e
  285. CONFIG_DIR="$CONFIG"
  286. REJECTS_DIR="$GITHUB_WORKSPACE/patch-rejects"
  287. mkdir -p "$REJECTS_DIR"
  288. # Find all .rej files under the configuration directory
  289. mapfile -t REJS < <(find "$CONFIG_DIR" -type f -name '*.rej')
  290. REJ_COUNT=${#REJS[@]}
  291. echo "Found $REJ_COUNT .rej files under $CONFIG_DIR"
  292. echo "REJ_COUNT=$REJ_COUNT" >> $GITHUB_ENV
  293. if [ "$REJ_COUNT" -gt 0 ]; then
  294. for REJ in "${REJS[@]}"; do
  295. # Relative path from $CONFIG
  296. REL="${REJ#"$CONFIG_DIR"/}"
  297. DEST="$REJECTS_DIR/$REL"
  298. mkdir -p "$(dirname "$DEST")"
  299. cp "$REJ" "$DEST"
  300. # Copy the associated original file alongside the .rej
  301. ORIG="${REJ%.rej}"
  302. if [ -f "$ORIG" ]; then
  303. ORIG_DEST="$REJECTS_DIR/${REL%.rej}"
  304. mkdir -p "$(dirname "$ORIG_DEST")"
  305. cp "$ORIG" "$ORIG_DEST"
  306. fi
  307. echo "$REL" >> "$REJECTS_DIR/index.txt"
  308. done
  309. fi
  310. - name: Generate Build Summary
  311. if: ${{ always() }}
  312. run: |
  313. # Create build summary file for inclusion in Misc artifact
  314. echo "# Kernel Build Summary" > build_summary.md
  315. # Add build variant header
  316. echo "## ${{ env.FILE_NAME }}" >> build_summary.md
  317. # Add build info
  318. echo "## Build Information" >> build_summary.md
  319. echo "- **Android Version**: ${{ inputs.android_version }}" >> build_summary.md
  320. echo "- **Kernel Version**: ${{ inputs.kernel_version }}.${{ inputs.sub_level }}" >> build_summary.md
  321. echo "- **BBG**: Installed" >> build_summary.md
  322. echo "" >> build_summary.md
  323. # Get KernelSU-Next commit
  324. if [ -d "$CONFIG/KernelSU-Next" ]; then
  325. cd "$CONFIG/KernelSU-Next"
  326. KSUN_COMMIT=$(git rev-parse HEAD)
  327. KSUN_URL="https://github.com/WildKernels/KernelSU-Next/commit/$KSUN_COMMIT"
  328. echo "- **KernelSU-Next**: [$KSUN_COMMIT]($KSUN_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  329. cd "$GITHUB_WORKSPACE"
  330. else
  331. echo "- **KernelSU-Next**: not present" >> build_summary.md
  332. fi
  333. # Get Baseband-guard commit
  334. if [ -d "$CONFIG/Baseband-guard" ]; then
  335. cd "$CONFIG/Baseband-guard"
  336. BBG_COMMIT=$(git rev-parse HEAD)
  337. BBG_URL="https://github.com/vc-teahouse/Baseband-guard/commit/$BBG_COMMIT"
  338. echo "- **Baseband-guard**: [$BBG_COMMIT]($BBG_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  339. cd "$GITHUB_WORKSPACE"
  340. else
  341. echo "- **Baseband-guard**: not present" >> build_summary.md
  342. fi
  343. # Get SUSFS4KSU commit
  344. if [ -d "$GITHUB_WORKSPACE/susfs4ksu" ]; then
  345. cd "$GITHUB_WORKSPACE/susfs4ksu"
  346. SUSFS_COMMIT=$(git rev-parse HEAD)
  347. SUSFS_URL="https://gitlab.com/simonpunk/susfs4ksu/-/commit/$SUSFS_COMMIT"
  348. echo "- **SUSFS4KSU (v2.1.0)**: [$SUSFS_COMMIT]($SUSFS_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  349. cd "$GITHUB_WORKSPACE"
  350. else
  351. echo "- **SUSFS4KSU (v2.1.0)**: not present" >> build_summary.md
  352. fi
  353. echo "" >> build_summary.md
  354. # Add artifact summary with presence verification
  355. echo "## Build Artifacts" >> build_summary.md
  356. # Verify AnyKernel3 contents - check if kernel Image was actually copied (indicates successful build)
  357. if [ -d "AnyKernel3" ] && [ -f "AnyKernel3/Image" ]; then
  358. AK3_STATUS="✅"
  359. else
  360. AK3_STATUS="❌"
  361. fi
  362. echo "- **AnyKernel3**: $AK3_STATUS ${{ env.FILE_NAME }}-AnyKernel3" >> build_summary.md
  363. echo "### Misc (uploaded files)" >> build_summary.md
  364. FILES_PRESENT=0
  365. 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
  366. if [ -f "$f" ]; then FILES_PRESENT=$((FILES_PRESENT+1)); fi
  367. done
  368. if [ "$FILES_PRESENT" -gt 0 ]; then
  369. MISC_STATUS="✅"
  370. else
  371. MISC_STATUS="❌"
  372. fi
  373. echo "- **Set**: $MISC_STATUS ${{ env.FILE_NAME }}-Misc" >> build_summary.md
  374. if [ "$MISC_STATUS" = "✅" ]; then
  375. echo " Included:" >> build_summary.md
  376. 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
  377. if [ -f "$f" ]; then
  378. echo " - $f" >> build_summary.md
  379. fi
  380. done
  381. fi
  382. echo "### Diagnostics" >> build_summary.md
  383. echo "- **Rejected Patches**: ${{ env.FILE_NAME }}-Rejected-Patches" >> build_summary.md
  384. if [ -f patch-rejects/index.txt ]; then
  385. if [ -s patch-rejects/index.txt ]; then
  386. echo " Rejected files:" >> build_summary.md
  387. while IFS= read -r line; do
  388. echo " - $line" >> build_summary.md
  389. done < patch-rejects/index.txt
  390. else
  391. echo " Rejected file list is empty." >> build_summary.md
  392. fi
  393. else
  394. echo " No rejected patches found." >> build_summary.md
  395. fi