build.yml 14 KB

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