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. 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*"
  111. "CCACHE_COMPRESS=true"
  112. "CCACHE_COMPRESSLEVEL=12"
  113. "CCACHE_DIRECT=true"
  114. "CCACHE_FILE_CLONE=true"
  115. "CCACHE_INODE_CACHE=true"
  116. "CCACHE_UMASK=002"
  117. "KBUILD_BUILD_TIMESTAMP=2026-01-01"
  118. "CCACHE_SLOPPINESS=file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
  119. )
  120. for setting in "${SETTINGS[@]}"; do
  121. export "$setting"
  122. echo "$setting" >> $GITHUB_ENV
  123. done
  124. # ccache log file for debugging hit rate
  125. export "CCACHE_LOGFILE=$CCACHE_LOG"
  126. echo "CCACHE_LOGFILE=$CCACHE_LOG" >> $GITHUB_ENV
  127. - name: restore ccache
  128. if: inputs.cache == 'true' && inputs.build_type == 'make'
  129. uses: actions/cache@v4
  130. with:
  131. path: ${{ env.CCACHE_DIR }}
  132. key: ccache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.BASE_BRANCH }}
  133. restore-keys: |
  134. ccache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.BASE_BRANCH }}
  135. ccache-${{ runner.os }}-${{ inputs.build_type }}-
  136. - name: Ensure ccache is used
  137. if: inputs.cache == 'true' && inputs.build_type == 'make'
  138. run: |
  139. echo "/usr/lib/ccache" >> $GITHUB_PATH
  140. echo "CC='ccache clang'" >> $GITHUB_ENV
  141. echo "CXX='ccache clang++'" >> $GITHUB_ENV
  142. - name: Set CONFIG Environment Variable
  143. run: |
  144. # Set CONFIG dynamically based on inputs values
  145. CONFIG="${{ inputs.branch }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  146. # Set CONFIG as an environment variable for future steps
  147. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  148. - name: dependencies
  149. uses: ./.github/actions/dependencies
  150. with:
  151. zeromount: ${{ inputs.zeromount }}
  152. susfs: ${{ inputs.susfs }}
  153. android_version: ${{ inputs.android_version }}
  154. kernel_version: ${{ inputs.kernel_version }}
  155. - name: Download Kernel
  156. uses: ./.github/actions/clone-kernel
  157. with:
  158. branch: ${{ inputs.branch }}
  159. - name: Set Path Environment Variables
  160. uses: ./.github/actions/env-variables
  161. with:
  162. branch: ${{ inputs.branch }}
  163. susfs: ${{ inputs.susfs }}
  164. zeromount: ${{ inputs.zeromount }}
  165. - name: Extract all tar.xz files and delete them
  166. run: |
  167. cd "$CONFIG"
  168. find . -type f -name '*.tar.xz' -print0 | while IFS= read -r -d '' file; do
  169. echo "Extracting $file"
  170. tar -xf "$file"
  171. rm "$file"
  172. done
  173. - name: Add KernelSU-Next
  174. if: inputs.ksun == 'true'
  175. uses: ./.github/actions/ksun
  176. - name: Apply SUSFS Patches
  177. if: inputs.susfs == 'true'
  178. uses: ./.github/actions/susfs-patches
  179. with:
  180. android_version: ${{ inputs.android_version }}
  181. kernel_version: ${{ inputs.kernel_version }}
  182. branch: ${{ inputs.branch }}
  183. - name: Apply zeromount Patches
  184. if: inputs.susfs == 'true' && inputs.zeromount == 'true'
  185. uses: ./.github/actions/zeromount
  186. with:
  187. android_version: ${{ inputs.android_version }}
  188. kernel_version: ${{ inputs.kernel_version }}
  189. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  190. if: inputs.kernel_version == '6.6'
  191. uses: ./.github/actions/6.6-fix
  192. with:
  193. branch: ${{ inputs.branch }}
  194. - name: Add bbrv1
  195. if: inputs.bbr == 'true'
  196. uses: ./.github/actions/bbr
  197. - name: Add BBG
  198. if: inputs.bbg == 'true'
  199. uses: ./.github/actions/bbg
  200. - name: temp fix for m55 bootloop maybe
  201. if: inputs.branch == 'SM-M556B-Oneui8'
  202. uses: ./.github/actions/m55-fix
  203. - name: Add unicodefix
  204. if: inputs.unicodefix == 'true'
  205. uses: ./.github/actions/unicode
  206. with:
  207. kernel_version: ${{ inputs.kernel_version }}
  208. - name: Add droidspace support
  209. if: inputs.droidspace == 'true'
  210. uses: ./.github/actions/droidspaces
  211. with:
  212. kernel_version: ${{ inputs.kernel_version }}
  213. - name: Add ntsync
  214. if: inputs.ntsync == 'true'
  215. uses: ./.github/actions/ntsync
  216. with:
  217. android_version: ${{ inputs.android_version }}
  218. kernel_version: ${{ inputs.kernel_version }}
  219. - name: Set Kernel Configuration Variables
  220. if: inputs.ksun == 'true'
  221. uses: ./.github/actions/configs
  222. with:
  223. branch: ${{ inputs.branch }}
  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. branch: ${{ inputs.branch }}
  233. android_version: ${{ inputs.android_version }}
  234. kernel_version: ${{ inputs.kernel_version }}
  235. - name: ensure bazel cache is set to be used
  236. if: inputs.build_type == 'Bazel' && inputs.cache == 'true'
  237. uses: ./.github/actions/use-bazcache
  238. - name: change variables to ccache
  239. if: inputs.cache == 'true' && inputs.build_type == 'make'
  240. uses: ./.github/actions/use-ccache
  241. - name: Build
  242. uses: ./.github/actions/build
  243. with:
  244. branch: ${{ inputs.branch }}
  245. build_type: ${{ inputs.build_type }}
  246. - name: clean up ccache
  247. if: inputs.cache == 'true' && inputs.build_type == 'make'
  248. run: ccache -c
  249. - name: get ccache log
  250. if: inputs.cache == 'true' && inputs.build_type == 'make'
  251. run: |
  252. if [ -f "${{ env.CCACHE_LOGFILE }}" ]; then
  253. echo "Rename ccache log"
  254. LOG_DIR=$(dirname "${{ env.CCACHE_LOGFILE }}")
  255. NEW_LOG_NAME="${{ inputs.branch }}_ccache.log"
  256. mv "${{ env.CCACHE_LOGFILE }}" "$LOG_DIR/$NEW_LOG_NAME"
  257. echo "CCACHE_LOGFILE=$LOG_DIR/$NEW_LOG_NAME" >> $GITHUB_ENV
  258. else
  259. echo "⚠ ccache log not found, skipping rename."
  260. fi
  261. - name: ccache stats
  262. if: inputs.cache == 'true' && inputs.build_type == 'make'
  263. run: ccache -s -v || ccache -s
  264. # - name: bazel cache stats
  265. # if: inputs.cache == 'true' && inputs.build_type == 'Bazel'
  266. # run: bazel analyze-profile profile.json
  267. - name: Prepare AnyKernel3
  268. uses: ./.github/actions/ak3zip-prep
  269. with:
  270. branch: ${{ inputs.branch }}
  271. - name: Upload AnyKernel3 Artifacts
  272. id: upload_ak3
  273. uses: actions/upload-artifact@v6
  274. with:
  275. name: ${{ env.FILE_NAME }}-AnyKernel3
  276. path: |
  277. ./AnyKernel3/**
  278. compression-level: 9
  279. - name: Upload ccache log
  280. if: inputs.cache == 'true' && inputs.build_type == 'make'
  281. uses: actions/upload-artifact@v6
  282. with:
  283. name: "${{ inputs.branch }}_ccache.log"
  284. path: ${{ env.CCACHE_LOGFILE }}
  285. archive: false
  286. compression-level: 0
  287. retention-days: 90
  288. - name: Scan and collect patch rejects
  289. if: ${{ always() }}
  290. run: |
  291. set -e
  292. CONFIG_DIR="$CONFIG"
  293. REJECTS_DIR="$GITHUB_WORKSPACE/patch-rejects"
  294. mkdir -p "$REJECTS_DIR"
  295. # Find all .rej files under the configuration directory
  296. mapfile -t REJS < <(find "$CONFIG_DIR" -type f -name '*.rej')
  297. REJ_COUNT=${#REJS[@]}
  298. echo "Found $REJ_COUNT .rej files under $CONFIG_DIR"
  299. echo "REJ_COUNT=$REJ_COUNT" >> $GITHUB_ENV
  300. if [ "$REJ_COUNT" -gt 0 ]; then
  301. for REJ in "${REJS[@]}"; do
  302. # Relative path from $CONFIG
  303. REL="${REJ#"$CONFIG_DIR"/}"
  304. DEST="$REJECTS_DIR/$REL"
  305. mkdir -p "$(dirname "$DEST")"
  306. cp "$REJ" "$DEST"
  307. # Copy the associated original file alongside the .rej
  308. ORIG="${REJ%.rej}"
  309. if [ -f "$ORIG" ]; then
  310. ORIG_DEST="$REJECTS_DIR/${REL%.rej}"
  311. mkdir -p "$(dirname "$ORIG_DEST")"
  312. cp "$ORIG" "$ORIG_DEST"
  313. fi
  314. echo "$REL" >> "$REJECTS_DIR/index.txt"
  315. done
  316. fi
  317. - name: Generate Build Summary
  318. if: ${{ always() }}
  319. run: |
  320. # Create build summary file for inclusion in Misc artifact
  321. echo "# Kernel Build Summary" > build_summary.md
  322. # Add build variant header
  323. echo "## ${{ env.FILE_NAME }}" >> build_summary.md
  324. # Add build info
  325. echo "## Build Information" >> build_summary.md
  326. echo "- **Android Version**: ${{ inputs.android_version }}" >> build_summary.md
  327. echo "- **Kernel Version**: ${{ inputs.kernel_version }}.${{ inputs.sub_level }}" >> build_summary.md
  328. echo "- **BBG**: Installed" >> build_summary.md
  329. echo "" >> build_summary.md
  330. # Get KernelSU-Next commit
  331. if [ -d "$CONFIG/KernelSU-Next" ]; then
  332. cd "$CONFIG/KernelSU-Next"
  333. KSUN_COMMIT=$(git rev-parse HEAD)
  334. KSUN_URL="https://github.com/WildKernels/KernelSU-Next/commit/$KSUN_COMMIT"
  335. echo "- **KernelSU-Next**: [$KSUN_COMMIT]($KSUN_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  336. cd "$GITHUB_WORKSPACE"
  337. else
  338. echo "- **KernelSU-Next**: not present" >> build_summary.md
  339. fi
  340. # Get Baseband-guard commit
  341. if [ -d "$CONFIG/Baseband-guard" ]; then
  342. cd "$CONFIG/Baseband-guard"
  343. BBG_COMMIT=$(git rev-parse HEAD)
  344. BBG_URL="https://github.com/vc-teahouse/Baseband-guard/commit/$BBG_COMMIT"
  345. echo "- **Baseband-guard**: [$BBG_COMMIT]($BBG_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  346. cd "$GITHUB_WORKSPACE"
  347. else
  348. echo "- **Baseband-guard**: not present" >> build_summary.md
  349. fi
  350. # Get SUSFS4KSU commit
  351. if [ -d "$GITHUB_WORKSPACE/susfs4ksu" ]; then
  352. cd "$GITHUB_WORKSPACE/susfs4ksu"
  353. SUSFS_COMMIT=$(git rev-parse HEAD)
  354. SUSFS_URL="https://gitlab.com/simonpunk/susfs4ksu/-/commit/$SUSFS_COMMIT"
  355. echo "- **SUSFS4KSU (v2.1.0)**: [$SUSFS_COMMIT]($SUSFS_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  356. cd "$GITHUB_WORKSPACE"
  357. else
  358. echo "- **SUSFS4KSU (v2.1.0)**: not present" >> build_summary.md
  359. fi
  360. echo "" >> build_summary.md
  361. # Add artifact summary with presence verification
  362. echo "## Build Artifacts" >> build_summary.md
  363. # Verify AnyKernel3 contents - check if kernel Image was actually copied (indicates successful build)
  364. if [ -d "AnyKernel3" ] && [ -f "AnyKernel3/Image" ]; then
  365. AK3_STATUS="✅"
  366. else
  367. AK3_STATUS="❌"
  368. fi
  369. echo "- **AnyKernel3**: $AK3_STATUS ${{ env.FILE_NAME }}-AnyKernel3" >> build_summary.md
  370. echo "### Misc (uploaded files)" >> build_summary.md
  371. FILES_PRESENT=0
  372. 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
  373. if [ -f "$f" ]; then FILES_PRESENT=$((FILES_PRESENT+1)); fi
  374. done
  375. if [ "$FILES_PRESENT" -gt 0 ]; then
  376. MISC_STATUS="✅"
  377. else
  378. MISC_STATUS="❌"
  379. fi
  380. echo "- **Set**: $MISC_STATUS ${{ env.FILE_NAME }}-Misc" >> build_summary.md
  381. if [ "$MISC_STATUS" = "✅" ]; then
  382. echo " Included:" >> build_summary.md
  383. 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
  384. if [ -f "$f" ]; then
  385. echo " - $f" >> build_summary.md
  386. fi
  387. done
  388. fi
  389. echo "### Diagnostics" >> build_summary.md
  390. echo "- **Rejected Patches**: ${{ env.FILE_NAME }}-Rejected-Patches" >> build_summary.md
  391. if [ -f patch-rejects/index.txt ]; then
  392. if [ -s patch-rejects/index.txt ]; then
  393. echo " Rejected files:" >> build_summary.md
  394. while IFS= read -r line; do
  395. echo " - $line" >> build_summary.md
  396. done < patch-rejects/index.txt
  397. else
  398. echo " Rejected file list is empty." >> build_summary.md
  399. fi
  400. else
  401. echo " No rejected patches found." >> build_summary.md
  402. fi