build.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. susfs:
  18. required: true
  19. type: string
  20. bbg:
  21. required: true
  22. type: string
  23. unicodefix:
  24. required: true
  25. type: string
  26. zeromount:
  27. required: true
  28. type: string
  29. wksu:
  30. required: true
  31. type: string
  32. droidspace:
  33. required: true
  34. type: string
  35. ntsync:
  36. required: true
  37. type: string
  38. optimizations:
  39. required: true
  40. type: string
  41. jobs:
  42. build-samsung-gki:
  43. name: "${{ inputs.branch }}-${{ inputs.kernel_version }}-${{ inputs.android_version }}"
  44. runs-on: ubuntu-latest
  45. strategy:
  46. fail-fast: false
  47. steps:
  48. - name: Free Disk Space
  49. if: true
  50. uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable
  51. with:
  52. remove_android: true
  53. remove_dotnet: true
  54. remove_haskell: true
  55. remove_tool_cache: true
  56. remove_swap: true
  57. remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*"
  58. remove_packages_one_command: true
  59. 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"
  60. rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm')
  61. rmz_version: "3.1.1" # Required when rm_cmd is 'rmz'
  62. testing: false
  63. - name: Setup more Swap (for LTO)
  64. uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space
  65. with:
  66. swap-size-gb: 25 # 10-24 GB is common for heavy LTO
  67. # swap-space-path: /mnt/swapfile # optional
  68. - name: Set CONFIG Environment Variable
  69. run: |
  70. # Set CONFIG dynamically based on inputs values
  71. CONFIG="${{ inputs.branch }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  72. # Set CONFIG as an environment variable for future steps
  73. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  74. - name: dependencies
  75. uses: ./.github/actions/dependencies
  76. with:
  77. zeromount: ${{ inputs.zeromount }}
  78. susfs: ${{ inputs.susfs }}
  79. android_version: ${{ inputs.android_version }}
  80. kernel_version: ${{ inputs.kernel_version }}
  81. - name: Download Kernel
  82. uses: ./.github/actions/clone-kernel
  83. with:
  84. branch: ${{ inputs.branch }}
  85. - name: Set Path Environment Variables
  86. run: |
  87. ROOT="$GITHUB_WORKSPACE"
  88. if [[ ${{ inputs.susfs }} == 'true' ]]; then
  89. SUSFS4KSU="$ROOT/susfs4ksu"
  90. KERNEL_PATCHES="$ROOT/kernel_patches"
  91. echo "SUSFS4KSU=$SUSFS4KSU" >> $GITHUB_ENV
  92. echo "KERNEL_PATCHES=$KERNEL_PATCHES" >> $GITHUB_ENV
  93. fi
  94. ANYKERNEL3="$ROOT/AnyKernel3"
  95. if [[ ${{ inputs.zeromount }} == 'true' ]]; then
  96. ZEROMOUNT="$ROOT/Super-Builders"
  97. echo "ZEROMOUNT=$ZEROMOUNT" >> $GITHUB_ENV
  98. fi
  99. if [[ ${{ inputs.branch }} == SM-A546* || "${{ inputs.branch }}" == "SM-M146B-Oneui7-ADYJ2" || "${{ inputs.branch }}" == "SM-S908B-Oneui8-bitK" ]]; then
  100. COMMON="$CONFIG"
  101. elif [[ "${{ inputs.branch }}" == "SM-A566B" || ${{ inputs.branch }} == SM-A055* ]]; then
  102. COMMON="$CONFIG/kernel-6.6"
  103. elif [[ "${{ inputs.branch }}" == "SM-S926B-Oneui8" || ${{ inputs.branch }} == SM-A556* ]]; then
  104. COMMON="$CONFIG/kernel"
  105. else
  106. COMMON="$CONFIG/kernel_platform/common"
  107. fi
  108. if [[ "${{ inputs.branch }}" == "SM-A546B-Oneui7" || "${{ inputs.branch }}" == "SM-A546B-Oneui8" ]]; then
  109. GKI_DEFCONFIG="$COMMON/arch/arm64/configs/s5e8835-a54xnaxx_defconfig"
  110. elif [[ "${{ inputs.branch }}" == "SM-A546E-Oneui7" || "${{ inputs.branch }}" == "SM-A546E-Oneui8" ]]; then
  111. GKI_DEFCONFIG="$COMMON/arch/arm64/configs/s5e8835-a54xnsxx_defconfig"
  112. elif [[ "${{ inputs.branch }}" == "SM-M146B-Oneui7-ADYJ2" ]]; then
  113. GKI_DEFCONFIG="$COMMON/arch/arm64/configs/s5e8535-m14xnsxx_defconfig"
  114. elif [[ "${{ inputs.branch }}" == "SM-S908B-Oneui8-bitK" ]]; then
  115. GKI_DEFCONFIG="$COMMON/arch/arm64/configs/s5e9925-b0sxxx_defconfig"
  116. else
  117. GKI_DEFCONFIG="$COMMON/arch/arm64/configs/gki_defconfig"
  118. fi
  119. echo "ROOT=$ROOT" >> $GITHUB_ENV
  120. echo "ANYKERNEL3=$ANYKERNEL3" >> $GITHUB_ENV
  121. echo "COMMON=$COMMON" >> $GITHUB_ENV
  122. echo "GKI_DEFCONFIG=$GKI_DEFCONFIG" >> $GITHUB_ENV
  123. - name: Extract all tar.xz files and delete them
  124. run: |
  125. cd "$CONFIG"
  126. find . -type f -name '*.tar.xz' -print0 | while IFS= read -r -d '' file; do
  127. echo "Extracting $file"
  128. tar -xf "$file"
  129. rm "$file"
  130. done
  131. - name: Add KernelSU-Next
  132. if: inputs.wksu == 'true'
  133. uses: ./.github/actions/ksun
  134. # - name: Getting KernelSU-Next Version
  135. # if: inputs.wksu == 'true'
  136. # run: |
  137. # cd "$COMMON/KernelSU-Next/kernel"
  138. #
  139. # KSU_DIR=$(pwd)
  140. # KBUILD="Kbuild"
  141. # BASE_VERSION=30000
  142. #if [ -d "$KSU_DIR/.git" ]; then
  143. # echo "✔ Git repo detected"
  144. # # Unshallow if needed
  145. # if [ -f "$KSU_DIR/.git/shallow" ]; then
  146. # git -C "$KSU_DIR" fetch --unshallow || true
  147. # fi
  148. # Get commit count
  149. # KSU_GIT_VERSION=$(git -C "$KSU_DIR" rev-list --count HEAD)
  150. # Calculate version
  151. # KSU_VERSION=$((BASE_VERSION + KSU_GIT_VERSION))
  152. # Get latest tag (safe)
  153. # KSU_GIT_TAG=$(git -C "$KSU_DIR" describe --tags --abbrev=0 2>/dev/null || echo "v0.0.1")
  154. # else
  155. # echo "⚠ Not a git repo, using defaults"
  156. # KSU_VERSION=33129
  157. # KSU_GIT_TAG="v3.2.0"
  158. # fi
  159. # echo "Computed version: $KSU_VERSION"
  160. # echo "Computed tag: $KSU_GIT_TAG"
  161. # Export for CI (optional)
  162. # echo "KSU_VERSION=$KSU_VERSION" >> $GITHUB_ENV
  163. # echo "KSU_VERSION_TAG=$KSU_GIT_TAG" >> $GITHUB_ENV
  164. # --- Update Kbuild fallback values ---
  165. # Update numeric fallback
  166. # sed -i "s/KSU_VERSION_FALLBACK := [0-9]\+/KSU_VERSION_FALLBACK := ${KSU_VERSION}/" "$KBUILD"
  167. # Update tag fallback
  168. # sed -i "s/KSU_VERSION_TAG_FALLBACK := .*/KSU_VERSION_TAG_FALLBACK := ${KSU_GIT_TAG}/" "$KBUILD"
  169. # echo "✅ Updated fallback values in $KBUILD"
  170. - name: Apply SUSFS Patches
  171. if: inputs.susfs == 'true'
  172. uses: ./.github/actions/susfs-patches
  173. with:
  174. android_version: ${{ inputs.android_version }}
  175. kernel_version: ${{ inputs.kernel_version }}
  176. - name: Apply zeromount Patches
  177. if: inputs.susfs == 'true' && inputs.zeromount == 'true'
  178. uses: ./.github/actions/zeromount
  179. with:
  180. android_version: ${{ inputs.android_version }}
  181. kernel_version: ${{ inputs.kernel_version }}
  182. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  183. if: inputs.kernel_version == '6.6'
  184. uses: ./.github/actions/6.6-fix
  185. with:
  186. kernel_version: ${{ inputs.kernel_version }}
  187. - name: Add BBG
  188. if: inputs.bbg == 'true'
  189. uses: ./.github/actions/bbg
  190. - name: temp fix for m55 bootloop maybe
  191. if: inputs.branch == 'SM-M556B-Oneui8'
  192. uses: ./.github/actions/m55-fix
  193. - name: Add unicodefix
  194. if: inputs.unicodefix == 'true'
  195. uses: ./.github/actions/unicode
  196. with:
  197. kernel_version: ${{ inputs.kernel_version }}
  198. - name: Add droidspace support
  199. if: inputs.droidspace == 'true'
  200. uses: ./.github/actions/droidspaces
  201. - name: Set Kernel Configuration Variables
  202. if: inputs.wksu == 'true'
  203. uses: ./.github/actions/configs
  204. - name: Add ntsync
  205. if: inputs.ntsync == 'true'
  206. uses: ./.github/actions/ntsync
  207. with:
  208. android_version: ${{ inputs.android_version }}
  209. kernel_version: ${{ inputs.kernel_version }}
  210. - name: Change Kernel Name and clean dirty
  211. uses: ./.github/actions/kernel-name
  212. - name: remove protected exports
  213. uses: ./.github/actions/abi-export
  214. - name: Set file name
  215. if: inputs.wksu == 'true'
  216. uses: ./.github/actions/file-name
  217. with:
  218. branch: ${{ inputs.branch }}
  219. android_version: ${{ inputs.android_version }}
  220. kernel_version: ${{ inputs.kernel_version }}
  221. - name: Build
  222. uses: ./.github/actions/build
  223. with:
  224. branch: ${{ inputs.branch }}
  225. - name: Prepare AnyKernel3
  226. uses: ./.github/actions/ak3zip-prep
  227. with:
  228. branch: ${{ inputs.branch }}
  229. - name: Upload AnyKernel3 Artifacts
  230. id: upload_ak3
  231. uses: actions/upload-artifact@v6
  232. with:
  233. name: ${{ env.FILE_NAME }}-AnyKernel3
  234. path: |
  235. ./AnyKernel3/**
  236. compression-level: 9
  237. - name: Scan and collect patch rejects
  238. if: ${{ always() }}
  239. run: |
  240. set -e
  241. CONFIG_DIR="$CONFIG"
  242. REJECTS_DIR="$GITHUB_WORKSPACE/patch-rejects"
  243. mkdir -p "$REJECTS_DIR"
  244. # Find all .rej files under the configuration directory
  245. mapfile -t REJS < <(find "$CONFIG_DIR" -type f -name '*.rej')
  246. REJ_COUNT=${#REJS[@]}
  247. echo "Found $REJ_COUNT .rej files under $CONFIG_DIR"
  248. echo "REJ_COUNT=$REJ_COUNT" >> $GITHUB_ENV
  249. if [ "$REJ_COUNT" -gt 0 ]; then
  250. for REJ in "${REJS[@]}"; do
  251. # Relative path from $CONFIG
  252. REL="${REJ#"$CONFIG_DIR"/}"
  253. DEST="$REJECTS_DIR/$REL"
  254. mkdir -p "$(dirname "$DEST")"
  255. cp "$REJ" "$DEST"
  256. # Copy the associated original file alongside the .rej
  257. ORIG="${REJ%.rej}"
  258. if [ -f "$ORIG" ]; then
  259. ORIG_DEST="$REJECTS_DIR/${REL%.rej}"
  260. mkdir -p "$(dirname "$ORIG_DEST")"
  261. cp "$ORIG" "$ORIG_DEST"
  262. fi
  263. echo "$REL" >> "$REJECTS_DIR/index.txt"
  264. done
  265. fi
  266. - name: Generate Build Summary
  267. if: ${{ always() }}
  268. run: |
  269. # Create build summary file for inclusion in Misc artifact
  270. echo "# Kernel Build Summary" > build_summary.md
  271. # Add build variant header
  272. echo "## ${{ env.FILE_NAME }}" >> build_summary.md
  273. # Add build info
  274. echo "## Build Information" >> build_summary.md
  275. echo "- **Android Version**: ${{ inputs.android_version }}" >> build_summary.md
  276. echo "- **Kernel Version**: ${{ inputs.kernel_version }}.${{ inputs.sub_level }}" >> build_summary.md
  277. echo "- **BBG**: Installed" >> build_summary.md
  278. echo "" >> build_summary.md
  279. # Get KernelSU-Next commit
  280. if [ -d "$CONFIG/KernelSU-Next" ]; then
  281. cd "$CONFIG/KernelSU-Next"
  282. KSUN_COMMIT=$(git rev-parse HEAD)
  283. KSUN_URL="https://github.com/WildKernels/KernelSU-Next/commit/$KSUN_COMMIT"
  284. echo "- **KernelSU-Next**: [$KSUN_COMMIT]($KSUN_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  285. cd "$GITHUB_WORKSPACE"
  286. else
  287. echo "- **KernelSU-Next**: not present" >> build_summary.md
  288. fi
  289. # Get Baseband-guard commit
  290. if [ -d "$CONFIG/Baseband-guard" ]; then
  291. cd "$CONFIG/Baseband-guard"
  292. BBG_COMMIT=$(git rev-parse HEAD)
  293. BBG_URL="https://github.com/vc-teahouse/Baseband-guard/commit/$BBG_COMMIT"
  294. echo "- **Baseband-guard**: [$BBG_COMMIT]($BBG_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  295. cd "$GITHUB_WORKSPACE"
  296. else
  297. echo "- **Baseband-guard**: not present" >> build_summary.md
  298. fi
  299. # Get SUSFS4KSU commit
  300. if [ -d "$GITHUB_WORKSPACE/susfs4ksu" ]; then
  301. cd "$GITHUB_WORKSPACE/susfs4ksu"
  302. SUSFS_COMMIT=$(git rev-parse HEAD)
  303. SUSFS_URL="https://gitlab.com/simonpunk/susfs4ksu/-/commit/$SUSFS_COMMIT"
  304. echo "- **SUSFS4KSU (v2.1.0)**: [$SUSFS_COMMIT]($SUSFS_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  305. cd "$GITHUB_WORKSPACE"
  306. else
  307. echo "- **SUSFS4KSU (v2.1.0)**: not present" >> build_summary.md
  308. fi
  309. echo "" >> build_summary.md
  310. # Add artifact summary with presence verification
  311. echo "## Build Artifacts" >> build_summary.md
  312. # Verify AnyKernel3 contents - check if kernel Image was actually copied (indicates successful build)
  313. if [ -d "AnyKernel3" ] && [ -f "AnyKernel3/Image" ]; then
  314. AK3_STATUS="✅"
  315. else
  316. AK3_STATUS="❌"
  317. fi
  318. echo "- **AnyKernel3**: $AK3_STATUS ${{ env.FILE_NAME }}-AnyKernel3" >> build_summary.md
  319. echo "### Misc (uploaded files)" >> build_summary.md
  320. FILES_PRESENT=0
  321. 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
  322. if [ -f "$f" ]; then FILES_PRESENT=$((FILES_PRESENT+1)); fi
  323. done
  324. if [ "$FILES_PRESENT" -gt 0 ]; then
  325. MISC_STATUS="✅"
  326. else
  327. MISC_STATUS="❌"
  328. fi
  329. echo "- **Set**: $MISC_STATUS ${{ env.FILE_NAME }}-Misc" >> build_summary.md
  330. if [ "$MISC_STATUS" = "✅" ]; then
  331. echo " Included:" >> build_summary.md
  332. 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
  333. if [ -f "$f" ]; then
  334. echo " - $f" >> build_summary.md
  335. fi
  336. done
  337. fi
  338. echo "### Diagnostics" >> build_summary.md
  339. echo "- **Rejected Patches**: ${{ env.FILE_NAME }}-Rejected-Patches" >> build_summary.md
  340. if [ -f patch-rejects/index.txt ]; then
  341. if [ -s patch-rejects/index.txt ]; then
  342. echo " Rejected files:" >> build_summary.md
  343. while IFS= read -r line; do
  344. echo " - $line" >> build_summary.md
  345. done < patch-rejects/index.txt
  346. else
  347. echo " Rejected file list is empty." >> build_summary.md
  348. fi
  349. else
  350. echo " No rejected patches found." >> build_summary.md
  351. fi