build.yml 15 KB

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