build.yml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. name: Build Script
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. android_version:
  9. required: true
  10. type: string
  11. kernel_version:
  12. required: true
  13. type: string
  14. sub_level:
  15. required: true
  16. type: string
  17. os_patch_level:
  18. required: true
  19. type: string
  20. kernelsu_variant:
  21. required: true
  22. type: string
  23. kernelsu_branch:
  24. required: true
  25. type: string
  26. kernelsu_branch_other:
  27. required: false
  28. type: string
  29. revision:
  30. required: false
  31. type: string
  32. jobs:
  33. build-gki:
  34. runs-on: ubuntu-latest
  35. timeout-minutes: 120
  36. env:
  37. CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
  38. CCACHE_NOHASHDIR: "true"
  39. CCACHE_HARDLINK: "true"
  40. steps:
  41. - name: Maximize Build Space
  42. uses: AdityaGarg8/remove-unwanted-software@v5
  43. with:
  44. remove-dotnet: 'true' # Frees ~2 GB
  45. remove-android: 'true' # Frees ~9 GB
  46. remove-haskell: 'true' # Frees ~5.2 GB
  47. remove-codeql: 'true' # Frees ~5.4 GB
  48. remove-docker-images: 'true' # Frees ~3.2 GB
  49. remove-large-packages: 'true' # Frees ~3.1 GB
  50. remove-swapfile: 'true' # Frees ~4 GB
  51. remove-cached-tools: 'false' # Avoid unless confirmed safe
  52. verbose: 'true' # Enable detailed logging
  53. - name: Set CONFIG Environment Variable
  54. run: |
  55. # Set CONFIG dynamically based on inputs values
  56. CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
  57. # Set CONFIG as an environment variable for future steps
  58. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  59. echo "CONFIG set to: $CONFIG"
  60. - name: Install ccache
  61. run: sudo apt update && sudo apt install -y ccache
  62. - name: Set up ccache
  63. run: |
  64. mkdir -p ~/.cache/bazel
  65. ccache --version
  66. ccache --max-size=2G
  67. ccache --set-config=compression=true
  68. echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
  69. - name: Restore ccache from cache
  70. uses: actions/cache@v4
  71. with:
  72. path: ~/.ccache
  73. key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}-ccache-${{ github.sha }}
  74. restore-keys: |
  75. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}-ccache-
  76. - name: Cache toolchain
  77. id: cache-toolchain
  78. uses: actions/cache@v4
  79. with:
  80. path: |
  81. kernel-build-tools
  82. mkbootimg
  83. key: toolchain-${{ runner.os }}-v1
  84. - name: Download toolchain (if cache not found)
  85. if: steps.cache-toolchain.outputs.cache-hit != 'true'
  86. run: |
  87. AOSP_MIRROR=https://android.googlesource.com
  88. BRANCH=main-kernel-build-2024
  89. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools
  90. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg
  91. - name: Set environment variables
  92. run: |
  93. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  94. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  95. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  96. - name: Set boot sign key
  97. env:
  98. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  99. run: |
  100. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  101. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  102. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  103. else
  104. echo "BOOT_SIGN_KEY is not set. Using AOSP sign key..."
  105. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  106. fi
  107. - name: Install Repo
  108. run: |
  109. mkdir -p ./git-repo
  110. echo "Downloading repo tool..."
  111. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  112. chmod a+rx ./git-repo/repo
  113. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  114. - name: Clone AnyKernel3 and Other Dependencies
  115. run: |
  116. echo "Cloning AnyKernel3 and other dependencies..."
  117. ANYKERNEL_BRANCH="gki-2.0"
  118. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  119. echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH"
  120. echo "Using branch for SUSFS: $SUSFS_BRANCH"
  121. git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  122. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  123. git clone https://github.com/WildPlusKernel/kernel_patches.git
  124. - name: Check Disk Space Before Sync
  125. run: |
  126. echo "Disk space before kernel source sync:"
  127. df -h
  128. - name: Initialize and Sync Kernel Source
  129. run: |
  130. echo "Creating folder for configuration: $CONFIG..."
  131. mkdir -p "$CONFIG"
  132. cd "$CONFIG"
  133. echo "Initializing and syncing kernel source..."
  134. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  135. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  136. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  137. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  138. if grep -q deprecated <<< $REMOTE_BRANCH; then
  139. echo "Found deprecated branch: $FORMATTED_BRANCH"
  140. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  141. fi
  142. $REPO --version
  143. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  144. - name: Determine the branch for KernelSU
  145. run: |
  146. case "${{ inputs.kernelsu_branch }}" in
  147. "Stable")
  148. echo "BRANCH=-" >> $GITHUB_ENV
  149. ;;
  150. "Dev")
  151. if [[ "${{ inputs.kernelsu_variant }}" =~ ^(KSU|MKSU)$ ]]; then
  152. echo "BRANCH=-s main" >> $GITHUB_ENV
  153. elif [[ "${{ inputs.kernelsu_variant }}" == "NEXT" ]]; then
  154. echo "BRANCH=-s next" >> $GITHUB_ENV
  155. elif [[ "${{ inputs.kernelsu_variant }}" == "WILD" ]]; then
  156. echo "BRANCH=-s wild" >> $GITHUB_ENV
  157. fi
  158. ;;
  159. "Other")
  160. if [[ -n "${{ inputs.kernelsu_branch_other }}" ]]; then
  161. echo "BRANCH=-s ${{ inputs.kernelsu_branch_other }}" >> $GITHUB_ENV
  162. else
  163. echo "Error: Custom branch not provided for 'Other'" >&2
  164. exit 1
  165. fi
  166. ;;
  167. esac
  168. - name: Add KernelSU
  169. run: |
  170. echo "Changing to configuration directory: $CONFIG..."
  171. cd "$CONFIG"
  172. case "${{ inputs.kernelsu_variant }}" in
  173. "WILD")
  174. echo "Adding Wild KSU..."
  175. curl -LSs "https://raw.githubusercontent.com/WildKernels/Wild_KSU/wild/kernel/setup.sh" | bash ${{ env.BRANCH }}
  176. ;;
  177. "KSU")
  178. echo "Adding KernelSU Official..."
  179. curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  180. ;;
  181. "NEXT")
  182. echo "Adding KernelSU Next..."
  183. curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash ${{ env.BRANCH }}
  184. ;;
  185. "MKSU")
  186. echo "Adding KernelSU MKSU..."
  187. curl -LSs "https://raw.githubusercontent.com/5ec1cff/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  188. ;;
  189. esac
  190. - name: Apply SUSFS Patches for KernelSU Variants
  191. run: |
  192. echo "Changing to configuration directory: $CONFIG..."
  193. cd "$CONFIG"
  194. echo "Applying SUSFS patches..."
  195. # Copy SUSFS patches
  196. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
  197. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  198. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  199. case "${{ inputs.kernelsu_variant }}" in
  200. "WILD")
  201. echo "Applying SUSFS patches for Official KernelSU..."
  202. cd ./Wild_KSU
  203. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  204. patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch || true
  205. cp ../../kernel_patches/wild/fix.corehook.c.patch ./
  206. patch -p1 --forward --fuzz=3 < fix.corehook.c.patch
  207. cp ../../kernel_patches/wild/fix.selinux.c.patch ./
  208. patch -p1 --forward --fuzz=3 < fix.selinux.c.patch
  209. cp ../../kernel_patches/wild/fix.ksud.c.patch ./
  210. patch -p1 --forward --fuzz=3 < fix.ksud.c.patch
  211. #cp ../../kernel_patches/wild/fix.sucompat.c.patch ./
  212. #patch -p1 --forward --fuzz=3 < fix.sucompat.c.patch
  213. sed -i '/bool ksu_devpts_hook = false;/d' ./kernel/sucompat.c
  214. ;;
  215. "KSU")
  216. echo "Applying SUSFS patches for Official KernelSU..."
  217. cd ./KernelSU
  218. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  219. patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch
  220. ;;
  221. "NEXT")
  222. echo "Applying SUSFS patches for KernelSU Next..."
  223. cd ./KernelSU-Next
  224. cp ../../kernel_patches/next/kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch ./
  225. patch -p1 --forward --fuzz=3 < kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch
  226. ;;
  227. "MKSU")
  228. echo "Applying SUSFS patches for MKSU..."
  229. cd ./KernelSU
  230. cp ../../kernel_patches/next/kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch ./
  231. patch -p1 --forward --fuzz=3 < kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch
  232. ;;
  233. esac
  234. cd ../common
  235. patch -p1 --fuzz=3 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
  236. - name: Apply Hooks Patches
  237. run: |
  238. echo "Changing to configuration directory: $CONFIG..."
  239. cd "$CONFIG/common"
  240. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ]; then
  241. echo "Applying hooks for KernelSU-Next..."
  242. cp ../../kernel_patches/next/syscall_hooks.patch ./
  243. patch -p1 -F 3 < syscall_hooks.patch
  244. elif [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  245. echo "Applying hooks for Wild KSU..."
  246. cp ../../kernel_patches/wild/syscall_hooks.patch ./
  247. patch -p1 -F 3 < syscall_hooks.patch
  248. fi
  249. - name: Apply Hide Stuff Patches
  250. run: |
  251. echo "Changing to configuration directory: $CONFIG..."
  252. cd "$CONFIG/common"
  253. cp ../../kernel_patches/69_hide_stuff.patch ./
  254. patch -p1 -F 3 < 69_hide_stuff.patch
  255. - name: Add All Managers
  256. run: |
  257. cd "$CONFIG"
  258. case "${{ inputs.kernelsu_variant }}" in
  259. "KSU" | "WILD")
  260. echo "Applying Manager patch for Official KernelSU..."
  261. cd KernelSU
  262. cp ../../kernel_patches/wild/manager.patch ./
  263. ;;
  264. "NEXT")
  265. echo "Applying Manager patch for KernelSU Next..."
  266. cd KernelSU-Next
  267. cp ../../kernel_patches/next/manager.patch ./
  268. ;;
  269. "MKSU")
  270. echo "Applying Manager patch for MKSU..."
  271. #cp ../kernel_patches/mksu/manager.patch .//
  272. ;;
  273. esac
  274. patch -p1 --fuzz=3 < manager.patch || echo "No Manager Patch"
  275. - name: Add Configuration Settings
  276. run: |
  277. echo "Changing to configuration directory: $CONFIG..."
  278. cd "$CONFIG"
  279. echo "Adding configuration settings to gki_defconfig..."
  280. # Add KSU configuration settings
  281. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  282. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ] || [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  283. echo "CONFIG_KSU_WITH_KPROBES=n" >> ./common/arch/arm64/configs/gki_defconfig
  284. fi
  285. # Add additional tmpfs config setting
  286. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  287. echo "CONFIG_TMPFS_POSIX_ACL=y" >> ./common/arch/arm64/configs/gki_defconfig
  288. # Add additional config setting
  289. echo "CONFIG_IP_NF_TARGET_TTL=y" >> ./common/arch/arm64/configs/gki_defconfig
  290. echo "CONFIG_IP6_NF_TARGET_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  291. echo "CONFIG_IP6_NF_MATCH_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  292. # Add BBR Config
  293. echo "CONFIG_TCP_CONG_ADVANCED=y" >> ./common/arch/arm64/configs/gki_defconfig
  294. echo "CONFIG_TCP_CONG_BBR=y" >> ./common/arch/arm64/configs/gki_defconfig
  295. echo "CONFIG_NET_SCH_FQ=y" >> ./common/arch/arm64/configs/gki_defconfig
  296. echo "CONFIG_TCP_CONG_BIC=n" >> ./common/arch/arm64/configs/gki_defconfig
  297. echo "CONFIG_TCP_CONG_WESTWOOD=n" >> ./common/arch/arm64/configs/gki_defconfig
  298. echo "CONFIG_TCP_CONG_HTCP=n" >> ./common/arch/arm64/configs/gki_defconfig
  299. # Remove check_defconfig
  300. sed -i 's/check_defconfig//' ./common/build.config.gki
  301. - name: Add SUSFS Configuration Settings
  302. run: |
  303. echo "Changing to configuration directory: $CONFIG..."
  304. cd "$CONFIG"
  305. # Add SUSFS configuration settings
  306. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  307. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  308. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  309. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  310. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  311. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  312. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  313. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> ./common/arch/arm64/configs/gki_defconfig
  314. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  315. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  316. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  317. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  318. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  319. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  320. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  321. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ] || [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  322. echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
  323. else
  324. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  325. fi
  326. - name: Change Kernel Name
  327. run: |
  328. cd "$CONFIG"
  329. # modify UTS_VERSION
  330. perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT Sat Apr 20 04:20:00 UTC 2024"}' ./common/scripts/mkcompile_h
  331. sed -i '$s|echo "\$res"|echo "\$res-Wild"|' ./common/scripts/setlocalversion
  332. if [ -f "build/build.sh" ]; then
  333. sed -i 's/-dirty//' ./common/scripts/setlocalversion
  334. else
  335. sed -i '/^[[:space:]]*"protected_exports_list"[[:space:]]*:[[:space:]]*"android\/abi_gki_protected_exports_aarch64",$/d' ./common/BUILD.bazel
  336. rm -rf ./common/android/abi_gki_protected_exports_*
  337. sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl
  338. sed -E -i '/^CONFIG_LOCALVERSION=/ s/(.*)"$/\1-Wild"/' ./common/arch/arm64/configs/gki_defconfig
  339. fi
  340. - name: Build
  341. run : |
  342. set -e
  343. set -x
  344. cd "$CONFIG"
  345. echo "Building the kernel..."
  346. if [ -f "build/build.sh" ]; then
  347. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh CC="/usr/bin/ccache clang" || exit 1
  348. else
  349. tools/bazel build --disk_cache=/home/runner/.cache/bazel --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
  350. fi
  351. ccache --show-stats
  352. - name: Create Bootimgs Folder and Copy Images for Android 12/13
  353. if: ${{ inputs.android_version == 'android12' || inputs.android_version == 'android13' }}
  354. run: |
  355. mkdir bootimgs
  356. echo "Creating bootimgs folder and copying images..."
  357. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./bootimgs
  358. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./bootimgs
  359. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./
  360. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./
  361. # Create gzip of the Image file
  362. gzip -n -k -f -9 ./Image > ./Image.gz
  363. - name: Create Bootimgs Folder and Copy Images for Android 14/15
  364. if: ${{ inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  365. run: |
  366. mkdir bootimgs
  367. echo "Creating bootimgs folder and copying images..."
  368. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
  369. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  370. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./
  371. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./
  372. # Create gzip of the Image file
  373. gzip -n -k -f -9 ./Image > ./Image.gz
  374. - name: Create ZIP Files for Different Formats
  375. run: |
  376. echo "Creating zip files for all formats..."
  377. cd ./AnyKernel3
  378. # Create and upload zip for each format
  379. ZIP_NAME="${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3.zip"
  380. echo "Creating zip file: $ZIP_NAME..."
  381. mv ../Image ./Image
  382. zip -r "../$ZIP_NAME" ./*
  383. rm ./Image
  384. ZIP_NAME="${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-lz4.zip"
  385. echo "Creating zip file: $ZIP_NAME..."
  386. mv ../Image.lz4 ./Image.lz4
  387. zip -r "../$ZIP_NAME" ./*
  388. rm ./Image.lz4
  389. ZIP_NAME="${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-gz.zip"
  390. echo "Creating zip file: $ZIP_NAME..."
  391. mv ../Image.gz ./Image.gz
  392. zip -r "../$ZIP_NAME" ./*
  393. rm ./Image.gz
  394. - name: Android 12 boot image build script
  395. if: ${{ inputs.android_version == 'android12' }}
  396. run: |
  397. echo "Changing to configuration directory: $CONFIG..."
  398. cd bootimgs
  399. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_"${{ inputs.revision }}".zip
  400. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  401. # Check if the GKI URL is available
  402. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  403. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  404. if [ "$status" = "200" ]; then
  405. echo "[+] Downloading from GKI_URL"
  406. curl -Lo gki-kernel.zip "$GKI_URL"
  407. else
  408. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  409. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  410. fi
  411. # Unzip the downloaded kernel and remove the zip
  412. echo "Unzipping the downloaded kernel..."
  413. unzip gki-kernel.zip && rm gki-kernel.zip
  414. echo "Unpacking boot.img..."
  415. FULL_PATH=$(pwd)/boot-5.10.img
  416. echo "Unpacking using: $FULL_PATH"
  417. echo "Running unpack_bootimg.py..."
  418. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  419. # Create gzip of the Image file
  420. gzip -n -k -f -9 ./Image > ./Image.gz
  421. echo "Building boot.img"
  422. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  423. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  424. cp ./boot.img ../${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  425. echo "Building boot-gz.img"
  426. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  427. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  428. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  429. echo "Building boot-lz4.img"
  430. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  431. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  432. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  433. - name: Android 13/14/15 boot image build script
  434. if: ${{ inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  435. run: |
  436. cd bootimgs
  437. # Create gzip of the Image file
  438. gzip -n -k -f -9 ./Image > ./Image.gz
  439. echo "Building boot.img"
  440. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  441. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  442. cp ./boot.img ../${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  443. echo "Building boot-gz.img"
  444. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  445. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  446. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  447. echo "Building boot-lz4.img"
  448. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  449. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  450. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  451. - name: Compress all img files with gzip
  452. run: |
  453. for image in *.img; do
  454. gzip -vnf9 "$image"
  455. done
  456. - name: Upload Build Artifacts
  457. uses: actions/upload-artifact@v4
  458. with:
  459. name: ${{ inputs.kernelsu_variant }}-kernel-${{ env.CONFIG }}
  460. path: |
  461. *.zip
  462. *.img.gz
  463. *Image*