build.yml 16 KB

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