build.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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: true
  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. ccache:
  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: Install ccache
  77. run: sudo apt-get update && sudo apt-get install -y ccache
  78. - name: Parse branch for hierarchical cache keys
  79. run: |
  80. FULL_BRANCH="${{ inputs.branch }}"
  81. echo "FULL_BRANCH=$FULL_BRANCH" >> $GITHUB_ENV
  82. BASE_BRANCH=$(echo "$FULL_BRANCH" | sed -E 's/(-bit[0-9]+.*$)|(-bit.*$)//i')
  83. echo "BASE_BRANCH=$BASE_BRANCH" >> $GITHUB_ENV
  84. - name: Export ccache + determinism
  85. run: |
  86. CACHE_DIR="${{ github.workspace }}/.ccache"
  87. mkdir -p "$CACHE_DIR"
  88. SETTINGS=(
  89. "CCACHE_DIR=$CACHE_DIR"
  90. "CCACHE_MAXSIZE=12G"
  91. "CCACHE_COMPILERCHECK=content"
  92. "CCACHE_BASEDIR=${GITHUB_WORKSPACE}"
  93. "CCACHE_NOHASHDIR=true"
  94. "CCACHE_IGNOREOPTIONS=-sysroot*"
  95. "CCACHE_COMPRESS=true"
  96. "CCACHE_COMPRESSLEVEL=9"
  97. "CCACHE_BASEDIR=${GITHUB_WORKSPACE}"
  98. "CCACHE_DIRECT=true"
  99. "CCACHE_FILE_CLONE=true"
  100. "CCACHE_INODE_CACHE=true"
  101. "CCACHE_UMASK=002"
  102. "CCACHE_SLOPPINESS=file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
  103. )
  104. for setting in "${SETTINGS[@]}"; do
  105. export "$setting"
  106. echo "$setting" >> $GITHUB_ENV
  107. done
  108. - name: restore ccache
  109. uses: actions/cache@v4
  110. with:
  111. path: ${{ env.CCACHE_DIR }}
  112. key: ccache-${{ runner.os }}-${{ env.BASE_BRANCH }}
  113. restore-keys: |
  114. ccache-${{ runner.os }}-${{ env.BASE_BRANCH }}
  115. ccache-${{ runner.os }}-
  116. - name: Ensure ccache is used
  117. run: |
  118. echo "/usr/lib/ccache" >> $GITHUB_PATH
  119. echo "CC='ccache clang'" >> $GITHUB_ENV
  120. echo "CXX='ccache clang++'" >> $GITHUB_ENV
  121. - name: Set CONFIG Environment Variable
  122. run: |
  123. # Set CONFIG dynamically based on inputs values
  124. CONFIG="${{ inputs.branch }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  125. # Set CONFIG as an environment variable for future steps
  126. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  127. - name: dependencies
  128. uses: ./.github/actions/dependencies
  129. with:
  130. zeromount: ${{ inputs.zeromount }}
  131. susfs: ${{ inputs.susfs }}
  132. android_version: ${{ inputs.android_version }}
  133. kernel_version: ${{ inputs.kernel_version }}
  134. - name: Download Kernel
  135. uses: ./.github/actions/clone-kernel
  136. with:
  137. branch: ${{ inputs.branch }}
  138. - name: Set Path Environment Variables
  139. uses: ./.github/actions/env-variables
  140. with:
  141. branch: ${{ inputs.branch }}
  142. susfs: ${{ inputs.susfs }}
  143. zeromount: ${{ inputs.zeromount }}
  144. - name: Extract all tar.xz files and delete them
  145. run: |
  146. cd "$CONFIG"
  147. find . -type f -name '*.tar.xz' -print0 | while IFS= read -r -d '' file; do
  148. echo "Extracting $file"
  149. tar -xf "$file"
  150. rm "$file"
  151. done
  152. - name: Add KernelSU-Next
  153. if: inputs.ksun == 'true'
  154. uses: ./.github/actions/ksun
  155. - name: Apply SUSFS Patches
  156. if: inputs.susfs == 'true'
  157. uses: ./.github/actions/susfs-patches
  158. with:
  159. android_version: ${{ inputs.android_version }}
  160. kernel_version: ${{ inputs.kernel_version }}
  161. branch: ${{ inputs.branch }}
  162. - name: Apply zeromount Patches
  163. if: inputs.susfs == 'true' && inputs.zeromount == 'true'
  164. uses: ./.github/actions/zeromount
  165. with:
  166. android_version: ${{ inputs.android_version }}
  167. kernel_version: ${{ inputs.kernel_version }}
  168. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  169. if: inputs.kernel_version == '6.6'
  170. uses: ./.github/actions/6.6-fix
  171. with:
  172. branch: ${{ inputs.branch }}
  173. - name: Add bbrv1
  174. if: inputs.bbr == 'true'
  175. uses: ./.github/actions/bbr
  176. - name: Add BBG
  177. if: inputs.bbg == 'true'
  178. uses: ./.github/actions/bbg
  179. - name: temp fix for m55 bootloop maybe
  180. if: inputs.branch == 'SM-M556B-Oneui8'
  181. uses: ./.github/actions/m55-fix
  182. - name: Add unicodefix
  183. if: inputs.unicodefix == 'true'
  184. uses: ./.github/actions/unicode
  185. with:
  186. kernel_version: ${{ inputs.kernel_version }}
  187. - name: Add droidspace support
  188. if: inputs.droidspace == 'true'
  189. uses: ./.github/actions/droidspaces
  190. with:
  191. kernel_version: ${{ inputs.kernel_version }}
  192. - name: Add ntsync
  193. if: inputs.ntsync == 'true'
  194. uses: ./.github/actions/ntsync
  195. with:
  196. android_version: ${{ inputs.android_version }}
  197. kernel_version: ${{ inputs.kernel_version }}
  198. - name: Set Kernel Configuration Variables
  199. if: inputs.ksun == 'true'
  200. uses: ./.github/actions/configs
  201. with:
  202. branch: ${{ inputs.branch }}
  203. - name: Change Kernel Name and clean dirty
  204. uses: ./.github/actions/kernel-name
  205. - name: remove protected exports
  206. uses: ./.github/actions/abi-export
  207. - name: Set file name
  208. if: inputs.ksun == 'true'
  209. uses: ./.github/actions/file-name
  210. with:
  211. branch: ${{ inputs.branch }}
  212. android_version: ${{ inputs.android_version }}
  213. kernel_version: ${{ inputs.kernel_version }}
  214. - name: Build
  215. uses: ./.github/actions/build
  216. with:
  217. branch: ${{ inputs.branch }}
  218. ccache: ${{ inputs.ccache }}
  219. - name: ccache stats
  220. if: always()
  221. run: ccache -s -v || ccache -s
  222. - name: Prepare AnyKernel3
  223. uses: ./.github/actions/ak3zip-prep
  224. with:
  225. branch: ${{ inputs.branch }}
  226. - name: Upload AnyKernel3 Artifacts
  227. id: upload_ak3
  228. uses: actions/upload-artifact@v6
  229. with:
  230. name: ${{ env.FILE_NAME }}-AnyKernel3
  231. path: |
  232. ./AnyKernel3/**
  233. compression-level: 9
  234. - name: Scan and collect patch rejects
  235. if: ${{ always() }}
  236. run: |
  237. set -e
  238. CONFIG_DIR="$CONFIG"
  239. REJECTS_DIR="$GITHUB_WORKSPACE/patch-rejects"
  240. mkdir -p "$REJECTS_DIR"
  241. # Find all .rej files under the configuration directory
  242. mapfile -t REJS < <(find "$CONFIG_DIR" -type f -name '*.rej')
  243. REJ_COUNT=${#REJS[@]}
  244. echo "Found $REJ_COUNT .rej files under $CONFIG_DIR"
  245. echo "REJ_COUNT=$REJ_COUNT" >> $GITHUB_ENV
  246. if [ "$REJ_COUNT" -gt 0 ]; then
  247. for REJ in "${REJS[@]}"; do
  248. # Relative path from $CONFIG
  249. REL="${REJ#"$CONFIG_DIR"/}"
  250. DEST="$REJECTS_DIR/$REL"
  251. mkdir -p "$(dirname "$DEST")"
  252. cp "$REJ" "$DEST"
  253. # Copy the associated original file alongside the .rej
  254. ORIG="${REJ%.rej}"
  255. if [ -f "$ORIG" ]; then
  256. ORIG_DEST="$REJECTS_DIR/${REL%.rej}"
  257. mkdir -p "$(dirname "$ORIG_DEST")"
  258. cp "$ORIG" "$ORIG_DEST"
  259. fi
  260. echo "$REL" >> "$REJECTS_DIR/index.txt"
  261. done
  262. fi
  263. - name: Generate Build Summary
  264. if: ${{ always() }}
  265. run: |
  266. # Create build summary file for inclusion in Misc artifact
  267. echo "# Kernel Build Summary" > build_summary.md
  268. # Add build variant header
  269. echo "## ${{ env.FILE_NAME }}" >> build_summary.md
  270. # Add build info
  271. echo "## Build Information" >> build_summary.md
  272. echo "- **Android Version**: ${{ inputs.android_version }}" >> build_summary.md
  273. echo "- **Kernel Version**: ${{ inputs.kernel_version }}.${{ inputs.sub_level }}" >> build_summary.md
  274. echo "- **BBG**: Installed" >> build_summary.md
  275. echo "" >> build_summary.md
  276. # Get KernelSU-Next commit
  277. if [ -d "$CONFIG/KernelSU-Next" ]; then
  278. cd "$CONFIG/KernelSU-Next"
  279. KSUN_COMMIT=$(git rev-parse HEAD)
  280. KSUN_URL="https://github.com/WildKernels/KernelSU-Next/commit/$KSUN_COMMIT"
  281. echo "- **KernelSU-Next**: [$KSUN_COMMIT]($KSUN_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  282. cd "$GITHUB_WORKSPACE"
  283. else
  284. echo "- **KernelSU-Next**: not present" >> build_summary.md
  285. fi
  286. # Get Baseband-guard commit
  287. if [ -d "$CONFIG/Baseband-guard" ]; then
  288. cd "$CONFIG/Baseband-guard"
  289. BBG_COMMIT=$(git rev-parse HEAD)
  290. BBG_URL="https://github.com/vc-teahouse/Baseband-guard/commit/$BBG_COMMIT"
  291. echo "- **Baseband-guard**: [$BBG_COMMIT]($BBG_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  292. cd "$GITHUB_WORKSPACE"
  293. else
  294. echo "- **Baseband-guard**: not present" >> build_summary.md
  295. fi
  296. # Get SUSFS4KSU commit
  297. if [ -d "$GITHUB_WORKSPACE/susfs4ksu" ]; then
  298. cd "$GITHUB_WORKSPACE/susfs4ksu"
  299. SUSFS_COMMIT=$(git rev-parse HEAD)
  300. SUSFS_URL="https://gitlab.com/simonpunk/susfs4ksu/-/commit/$SUSFS_COMMIT"
  301. echo "- **SUSFS4KSU (v2.1.0)**: [$SUSFS_COMMIT]($SUSFS_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  302. cd "$GITHUB_WORKSPACE"
  303. else
  304. echo "- **SUSFS4KSU (v2.1.0)**: not present" >> build_summary.md
  305. fi
  306. echo "" >> build_summary.md
  307. # Add artifact summary with presence verification
  308. echo "## Build Artifacts" >> build_summary.md
  309. # Verify AnyKernel3 contents - check if kernel Image was actually copied (indicates successful build)
  310. if [ -d "AnyKernel3" ] && [ -f "AnyKernel3/Image" ]; then
  311. AK3_STATUS="✅"
  312. else
  313. AK3_STATUS="❌"
  314. fi
  315. echo "- **AnyKernel3**: $AK3_STATUS ${{ env.FILE_NAME }}-AnyKernel3" >> build_summary.md
  316. echo "### Misc (uploaded files)" >> build_summary.md
  317. FILES_PRESENT=0
  318. 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
  319. if [ -f "$f" ]; then FILES_PRESENT=$((FILES_PRESENT+1)); fi
  320. done
  321. if [ "$FILES_PRESENT" -gt 0 ]; then
  322. MISC_STATUS="✅"
  323. else
  324. MISC_STATUS="❌"
  325. fi
  326. echo "- **Set**: $MISC_STATUS ${{ env.FILE_NAME }}-Misc" >> build_summary.md
  327. if [ "$MISC_STATUS" = "✅" ]; then
  328. echo " Included:" >> build_summary.md
  329. 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
  330. if [ -f "$f" ]; then
  331. echo " - $f" >> build_summary.md
  332. fi
  333. done
  334. fi
  335. echo "### Diagnostics" >> build_summary.md
  336. echo "- **Rejected Patches**: ${{ env.FILE_NAME }}-Rejected-Patches" >> build_summary.md
  337. if [ -f patch-rejects/index.txt ]; then
  338. if [ -s patch-rejects/index.txt ]; then
  339. echo " Rejected files:" >> build_summary.md
  340. while IFS= read -r line; do
  341. echo " - $line" >> build_summary.md
  342. done < patch-rejects/index.txt
  343. else
  344. echo " Rejected file list is empty." >> build_summary.md
  345. fi
  346. else
  347. echo " No rejected patches found." >> build_summary.md
  348. fi