build.yml 17 KB

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