build.yml 17 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. jobs:
  18. build-samsung-gki:
  19. name: "${{ inputs.branch }}-${{ inputs.kernel_version }}-${{ inputs.android_version }}"
  20. runs-on: ubuntu-latest
  21. strategy:
  22. fail-fast: false
  23. steps:
  24. - name: Check Initial Disk Space
  25. run: |
  26. echo "===== Initial Total Disk Space in GB ====="
  27. df -BG
  28. - name: Download Apache Arrow's util_free_space.sh
  29. run: |
  30. curl -L -o util_free_space.sh https://raw.githubusercontent.com/apache/arrow/main/ci/scripts/util_free_space.sh
  31. chmod +x util_free_space.sh
  32. ./util_free_space.sh
  33. - name: Check Disk Space After Cleanup
  34. run: |
  35. echo "===== Total Disk Space After Cleanup in GB ====="
  36. df -BG
  37. - name: Set CONFIG Environment Variable
  38. run: |
  39. # Set CONFIG dynamically based on inputs values
  40. CONFIG="${{ inputs.branch }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  41. # Set CONFIG as an environment variable for future steps
  42. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  43. - name: Clone AnyKernel3 and Other Dependencies
  44. run: |
  45. ANYKERNEL_BRANCH="gki-2.0"
  46. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  47. git clone https://github.com/WildKernels/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  48. git clone https://github.com/WildKernels/kernel_patches.git
  49. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  50. cd susfs4ksu
  51. TARGET="${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  52. COMMIT=""
  53. case "$TARGET" in
  54. android12-5.10) COMMIT="8a76ba240d1f7315352b49d97d854a4b166e5b47" ;;
  55. android13-5.10) COMMIT="e5c9eabfc6dcfc677d11f46ce1d5ff786de60a92" ;;
  56. android13-5.15) COMMIT="babf6be195576f09aae79650d47abf6a76e8a21b" ;;
  57. android14-5.15) COMMIT="19f339e804ba9aebd9c6d735b965e2b9396c73ae" ;;
  58. android14-6.1) COMMIT="a162e2469d0b472545e5e46457eee171c0975fb0" ;;
  59. android15-6.6) COMMIT="f450ec00bf592d080f59b01ff6f9242456c9a427" ;;
  60. esac
  61. git checkout "$COMMIT"
  62. - name: Clone Kernel Source
  63. run: |
  64. git clone https://github.com/WildKernels/Samsung_Kernels.git -b ${{ inputs.branch }} $CONFIG
  65. - name: Extract all tar.xz files and delete them
  66. run: |
  67. cd "$CONFIG"
  68. find . -type f -name '*.tar.xz' -print0 | while IFS= read -r -d '' file; do
  69. echo "Extracting $file"
  70. tar -xf "$file"
  71. rm "$file"
  72. done
  73. - name: Check Directory Space Usage
  74. run: |
  75. echo "===== Total Disk Space After Kernel Download in GB ====="
  76. df -BG
  77. echo "===== Directory Space Usage in GB ====="
  78. du -BG -d 1 | sort -nr
  79. echo "===== $CONFIG Directory Space Usage in GB ====="
  80. cd "$CONFIG"
  81. du -BG -d 2 | sort -nr
  82. - name: Add KernelSU
  83. run: |
  84. cd "$CONFIG/kernel_platform/common"
  85. curl -LSs "https://raw.githubusercontent.com/WildKernels/Wild_KSU/wild/kernel/setup.sh" | bash -s wild
  86. - name: Getting KernelSU Version
  87. run: |
  88. cd "$CONFIG/kernel_platform/common/Wild_KSU/kernel"
  89. BASE_VERSION=10200
  90. COMMIT_COUNT=$(/usr/bin/git rev-list --count HEAD)
  91. KSU_VERSION=$(expr $COMMIT_COUNT "+" $BASE_VERSION)
  92. echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
  93. # change KSU version in makefile, scamsung things
  94. MAKEFILE="Makefile"
  95. sed -i "s/ccflags-y += -DKSU_VERSION=[0-9]\+/ccflags-y += -DKSU_VERSION=${KSU_VERSION}/" "$MAKEFILE"
  96. echo "✅ Updated KSU version to ${KSU_VERSION} in $MAKEFILE"
  97. - name: Apply SUSFS Patches for KernelSU Variants
  98. run: |
  99. cd "$CONFIG"
  100. # Apply compatibility fixes
  101. SUSFS_VERSION="1.5.12"
  102. cp ../susfs4ksu/kernel_patches/fs/* ./kernel_platform/common/fs/
  103. cp ../susfs4ksu/kernel_patches/include/linux/* ./kernel_platform/common/include/linux/
  104. # Apply core SUSFS patches
  105. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./kernel_platform/common/
  106. cd kernel_platform/common
  107. # Apply SUSFS core patch
  108. patch -p1 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
  109. # Fix SUSFS rejects
  110. if [[ "${{ inputs.branch }}" == "SM-S928B-Oneui7" || "${{ inputs.branch }}" == "SM-S928B-Oneui8" ]]; then
  111. cp ../../../kernel_patches/samsung/S24U/* ./
  112. patch -p1 < fix_namespace.patch
  113. patch -p1 < fix_base.patch
  114. elif [[ "${{ inputs.branch }}" == "SM-A366B" ]]; then
  115. cp ../../../kernel_patches/samsung/${{ inputs.branch }}/* ./
  116. patch -p1 < fix_namespace.patch
  117. patch -p1 < fix_base.patch
  118. patch -p1 < fix_taskmmu.patch
  119. elif [[ "${{ inputs.branch }}" == "SM-X916B" ]]; then
  120. cp ../../../kernel_patches/samsung/${{ inputs.branch }}/* ./
  121. patch -p1 < fix_namespace.patch
  122. patch -p1 < fix_base.patch
  123. elif [[ "${{ inputs.branch }}" == "SM-F946N" ]]; then
  124. cp ../../../kernel_patches/samsung/${{ inputs.branch }}/* ./
  125. patch -p1 < fix_namespace.patch
  126. patch -p1 < fix_base.patch
  127. fi
  128. # Apply KSU integration patches
  129. cd Wild_KSU
  130. cp ../../../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch .
  131. patch -p1 < 10_enable_susfs_for_ksu.patch || true
  132. cp ../../../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_core_hook.c.patch ./
  133. patch -p1 < fix_core_hook.c.patch
  134. cp ../../../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_sucompat.c.patch ./
  135. patch -p1 < fix_sucompat.c.patch
  136. cp ../../../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_kernel_compat.c.patch ./
  137. patch -p1 < fix_kernel_compat.c.patch
  138. - name: Apply Hooks Patches
  139. run: |
  140. cd "$CONFIG/kernel_platform/common"
  141. cp ../../../kernel_patches/wild/hooks/scope_min_manual_hooks_v1.4.patch ./
  142. if [[ "${{ inputs.branch }}" == "SM-A366B" ]]; then
  143. patch -p1 < scope_min_manual_hooks_v1.4.patch || true
  144. else
  145. patch -p1 < scope_min_manual_hooks_v1.4.patch || true
  146. patch -p1 < fix_exec.patch
  147. fi
  148. - name: Add BBG
  149. run: |
  150. cd "$CONFIG/kernel_platform/common"
  151. echo "Adding BBG..."
  152. wget -O- https://github.com/vc-teahouse/Baseband-guard/raw/main/setup.sh | bash
  153. sed -i '/^config LSM$/,/^help$/{ /^[[:space:]]*default/ { /baseband_guard/! s/lockdown/lockdown,baseband_guard/ } }' security/Kconfig
  154. - name: Set Kernel Configuration Variables
  155. run: |
  156. cd "$CONFIG/kernel_platform/common"
  157. echo "Initializing kernel configuration..."
  158. patch -p1 < config.patch
  159. # Remove check_defconfig
  160. sed -i 's/check_defconfig//' ./build.config.gki
  161. - name: Change Kernel Name
  162. run: |
  163. cd "$CONFIG/kernel_platform"
  164. #Add Wild to Kernel Version
  165. sed -i '$s|echo "\$res"|echo "\$res-Wild"|' ./common/scripts/setlocalversion
  166. #Set Kernel Timestamp
  167. perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT Sun Apr 20 04:20:00 UTC 2025"}' ./common/scripts/mkcompile_h
  168. if [ -f "build/build.sh" ]; then
  169. #Remove Dirty Flag
  170. sed -i 's/-dirty//' ./common/scripts/setlocalversion
  171. else
  172. #Remove Dirty Flag
  173. sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl
  174. #Remove Abi Exports and Error
  175. #rm -rf ./common/android/abi_gki_protected_exports_*
  176. #perl -pi -e 's/^\s*"protected_exports_list"\s*:\s*"android\/abi_gki_protected_exports_aarch64",\s*$//;' ./common/BUILD.bazel
  177. fi
  178. - name: Set file name
  179. run: |
  180. ARTIFACT_BASE="${{ inputs.branch }}-${{ inputs.kernel_version }}-${{ inputs.android_version }}"
  181. echo "ARTIFACT_BASE=$ARTIFACT_BASE" >> $GITHUB_ENV
  182. echo "FILE_NAME=$ARTIFACT_BASE" >> $GITHUB_ENV
  183. - name: Build
  184. run : |
  185. set -e
  186. set -x
  187. cd "$CONFIG"
  188. chmod +x build_kernel_GKI.sh
  189. echo "Building the kernel..."
  190. if [[ "${{ inputs.branch }}" == "SM-S928B-Oneui7" || "${{ inputs.branch }}" == "SM-S928B-Oneui8" ]]; then
  191. ./build_kernel_GKI.sh
  192. else
  193. #temporarily using this until i can figure out the other phones build script issues
  194. cd kernel_platform
  195. tools/bazel build --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
  196. fi
  197. - name: Prepare AnyKernel3
  198. run: |
  199. # Copy Image from normal build locations
  200. #if [ -f "./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image" ]; then
  201. # cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image AnyKernel3/Image
  202. #elif [ -f "./$CONFIG/bazel-bin/common/kernel_aarch64/Image" ]; then
  203. # cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image AnyKernel3/Image
  204. #else
  205. # echo "Error: Image file not found in any expected location"
  206. # exit 1
  207. #fi
  208. cd "$CONFIG"
  209. if [[ "${{ inputs.branch }}" == "SM-S928B-Oneui7" || "${{ inputs.branch }}" == "SM-S928B-Oneui8" ]]; then
  210. cp ./kernel_platform/sec/dist/Image ../AnyKernel3/Image
  211. elif [[ -f ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ]]; then
  212. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ../AnyKernel3/Image
  213. else
  214. echo "Error: Image file not found in any expected location"
  215. exit 1
  216. fi
  217. - name: Create Bootimgs Folder and Copy Images for Android 14/15
  218. if: ${{ inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  219. run: |
  220. #mkdir bootimgs
  221. #cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
  222. #cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  223. #cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./${{ env.FILE_NAME }}-Image
  224. #cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./${{ env.FILE_NAME }}-Image.lz4
  225. # Create gzip of the Image file
  226. #gzip -n -k -f -9 ./${{ env.FILE_NAME }}-Image > ./${{ env.FILE_NAME }}-Image.gz
  227. #gzip -n -k -f -9 ./bootimgs/Image > ./bootimgs/Image.gz
  228. #cp ./boot-lz4.img ../${{ env.FILE_NAME }}-boot-lz4.img
  229. - name: Upload AnyKernel3 Artifacts
  230. id: upload_ak3
  231. uses: actions/upload-artifact@v4
  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 "- **Bypass Mode**: ${{ matrix.apply_bypass }}" >> build_summary.md
  279. echo "" >> build_summary.md
  280. # Get Wild_KSU commit
  281. if [ -d "$CONFIG/Wild_KSU" ]; then
  282. cd "$CONFIG/Wild_KSU"
  283. WKSU_COMMIT=$(git rev-parse HEAD)
  284. WKSU_URL="https://github.com/WildKernels/Wild_KSU/commit/$WKSU_COMMIT"
  285. echo "- **Wild_KSU**: [$WKSU_COMMIT]($WKSU_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  286. cd "$GITHUB_WORKSPACE"
  287. else
  288. echo "- **Wild_KSU**: not present" >> build_summary.md
  289. fi
  290. # Get Baseband-guard commit
  291. if [ -d "$CONFIG/Baseband-guard" ]; then
  292. cd "$CONFIG/Baseband-guard"
  293. BBG_COMMIT=$(git rev-parse HEAD)
  294. BBG_URL="https://github.com/vc-teahouse/Baseband-guard/commit/$BBG_COMMIT"
  295. echo "- **Baseband-guard**: [$BBG_COMMIT]($BBG_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  296. cd "$GITHUB_WORKSPACE"
  297. else
  298. echo "- **Baseband-guard**: not present" >> build_summary.md
  299. fi
  300. # Get SUSFS4KSU commit
  301. if [ -d "$GITHUB_WORKSPACE/susfs4ksu" ]; then
  302. cd "$GITHUB_WORKSPACE/susfs4ksu"
  303. SUSFS_COMMIT=$(git rev-parse HEAD)
  304. SUSFS_URL="https://gitlab.com/simonpunk/susfs4ksu/-/commit/$SUSFS_COMMIT"
  305. echo "- **SUSFS4KSU (v1.5.12)**: [$SUSFS_COMMIT]($SUSFS_URL)" >> "$GITHUB_WORKSPACE/build_summary.md"
  306. cd "$GITHUB_WORKSPACE"
  307. else
  308. echo "- **SUSFS4KSU (v1.5.12)**: not present" >> build_summary.md
  309. fi
  310. echo "" >> build_summary.md
  311. # Add artifact summary with presence verification
  312. echo "## Build Artifacts" >> build_summary.md
  313. # Verify AnyKernel3 contents - check if kernel Image was actually copied (indicates successful build)
  314. if [ -d "AnyKernel3" ] && [ -f "AnyKernel3/Image" ]; then
  315. AK3_STATUS="✅"
  316. else
  317. AK3_STATUS="❌"
  318. fi
  319. echo "- **AnyKernel3**: $AK3_STATUS ${{ env.FILE_NAME }}-AnyKernel3" >> build_summary.md
  320. echo "### Misc (uploaded files)" >> build_summary.md
  321. FILES_PRESENT=0
  322. 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
  323. if [ -f "$f" ]; then FILES_PRESENT=$((FILES_PRESENT+1)); fi
  324. done
  325. if [ "$FILES_PRESENT" -gt 0 ]; then
  326. MISC_STATUS="✅"
  327. else
  328. MISC_STATUS="❌"
  329. fi
  330. echo "- **Set**: $MISC_STATUS ${{ env.FILE_NAME }}-Misc" >> build_summary.md
  331. if [ "$MISC_STATUS" = "✅" ]; then
  332. echo " Included:" >> build_summary.md
  333. 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
  334. if [ -f "$f" ]; then
  335. echo " - $f" >> build_summary.md
  336. fi
  337. done
  338. fi
  339. echo "### Diagnostics" >> build_summary.md
  340. echo "- **Rejected Patches**: ${{ env.FILE_NAME }}-Rejected-Patches" >> build_summary.md
  341. if [ -f patch-rejects/index.txt ]; then
  342. if [ -s patch-rejects/index.txt ]; then
  343. echo " Rejected files:" >> build_summary.md
  344. while IFS= read -r line; do
  345. echo " - $line" >> build_summary.md
  346. done < patch-rejects/index.txt
  347. else
  348. echo " Rejected file list is empty." >> build_summary.md
  349. fi
  350. else
  351. echo " No rejected patches found." >> build_summary.md
  352. fi