build.yml 16 KB

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