name: Build Android 13 5.10 GKI Kernels on: workflow_call: # This allows this workflow to be called from another workflow jobs: build-kernel-a13-5-10-kernelsu-susfs: runs-on: ubuntu-22.04 strategy: matrix: include: - android_version: "android13" kernel_version: "5.10" sub_level: "189" os_patch_level: "2023-11" - android_version: "android13" kernel_version: "5.10" sub_level: "198" os_patch_level: "2024-01" - android_version: "android13" kernel_version: "5.10" sub_level: "205" os_patch_level: "2024-03" - android_version: "android13" kernel_version: "5.10" sub_level: "209" os_patch_level: "2024-05" - android_version: "android13" kernel_version: "5.10" sub_level: "210" os_patch_level: "2024-06" - android_version: "android13" kernel_version: "5.10" sub_level: "214" os_patch_level: "2024-07" - android_version: "android13" kernel_version: "5.10" sub_level: "218" os_patch_level: "2024-08" #- android_version: "android13" # kernel_version: "5.10" # sub_level: "X" # os_patch_level: "lts" steps: - name: Maximize build space uses: easimon/maximize-build-space@master with: root-reserve-mb: 8192 temp-reserve-mb: 2048 swap-size-mb: 8192 remove-dotnet: 'true' remove-android: 'true' remove-haskell: 'true' remove-codeql: 'true' - name: Set CONFIG Environment Variable run: | # Set CONFIG dynamically based on matrix values CONFIG="${{ matrix.android_version }}-${{ matrix.kernel_version }}-${{ matrix.sub_level }}" # Set CONFIG as an environment variable for future steps echo "CONFIG=$CONFIG" >> $GITHUB_ENV echo "CONFIG set to: $CONFIG" - name: Download prebuilt toolchain run: | AOSP_MIRROR=https://android.googlesource.com BRANCH=main-kernel-build-2024 git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV - name: Set boot sign key env: BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} run: | if [ ! -z "$BOOT_SIGN_KEY" ]; then echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV else echo "BOOT_SIGN_KEY is not set. Exiting..." exit 1 fi - name: Install Repo run: | # Install dependencies mkdir -p ./git-repo curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo chmod a+rx ./git-repo/repo echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV - name: Clone AnyKernel3 and Other Dependencies run: | echo "Cloning AnyKernel3 and other dependencies..." # Define the branch names using the matrix values ANYKERNEL_BRANCH="${{ matrix.android_version }}-${{ matrix.kernel_version }}" SUSFS_BRANCH="gki-${{ matrix.android_version }}-${{ matrix.kernel_version }}" # Debug print the branches echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH" echo "Using branch for SUSFS: $SUSFS_BRANCH" # Clone repositories using the branch names git clone https://github.com/TheWildJames/AnyKernel3.git -b "$ANYKERNEL_BRANCH" git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH" git clone https://github.com/TheWildJames/kernel_patches.git - name: Initialize and Sync Kernel Source run: | echo "Creating folder for configuration: $CONFIG..." mkdir -p "$CONFIG" cd "$CONFIG" # Initialize and sync kernel source echo "Initializing and syncing kernel source..." FORMATTED_BRANCH="${{ matrix.android_version }}-${{ matrix.kernel_version }}-${{ matrix.os_patch_level }}" $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16 REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH}) DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml # Check if branch is deprecated if grep -q deprecated <<< $REMOTE_BRANCH; then echo "Found deprecated branch: $FORMATTED_BRANCH" sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH fi # Sync repo and apply patches $REPO --version $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast - name: Add KernelSU run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" echo "Adding KernelSU..." curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash - - name: Apply SUSFS Patches run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" echo "Applying SUSFS patches..." # Copy SUSFS patches cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./KernelSU-Next/ cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ matrix.android_version }}-${{ matrix.kernel_version }}.patch ./common/ cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/ cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/ cd ./KernelSU-Next # Apply SUSFS patch for KernelSU patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true # Change to common directory and apply SUSFS patch cd ../common patch -p1 < 50_add_susfs_in_gki-${{ matrix.android_version }}-${{ matrix.kernel_version }}.patch || true - name: Apply Next-SUSFS Patches run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" echo "Applying next SUSFS patches..." cp ../kernel_patches/apk_sign.c_fix.patch ./ patch -p1 -F 3 < apk_sign.c_fix.patch cp ../kernel_patches/core_hook.c_fix.patch ./ patch -p1 --fuzz=3 < core_hook.c_fix.patch cp ../kernel_patches/selinux.c_fix.patch ./ patch -p1 -F 3 < selinux.c_fix.patch - name: Apply Hide Stuff Patches run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG/common" # Apply additional patch cp ../../kernel_patches/69_hide_stuff.patch ./ patch -p1 -F 3 < 69_hide_stuff.patch || true - name: Add SUSFS Configuration Settings run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" echo "Adding configuration settings to gki_defconfig..." # Add SUSFS configuration settings echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig # Add additional tmpfs config setting echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig - name: Run sed and perl Commands run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" echo "Running sed commands..." # Run sed commands for modifications sed -i 's/check_defconfig//' ./common/build.config.gki sed -i 's/-dirty//' ./common/scripts/setlocalversion sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./common/scripts/setlocalversion # Run perl command to modify UTS_VERSION 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 - name: Build the Kernel run: | echo "Changing to configuration directory: $CONFIG..." cd "$CONFIG" echo "Building the kernel..." LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh - name: Create Bootimgs Folder and Copy Images run: | echo "Changing to configuration directory: $CONFIG..." mkdir bootimgs echo "Creating bootimgs folder and copying images..." cp ./$CONFIG/out/${{ matrix.android_version }}-${{ matrix.kernel_version }}/dist/Image ./bootimgs cp ./$CONFIG/out/${{ matrix.android_version }}-${{ matrix.kernel_version }}/dist/Image.lz4 ./bootimgs cp ./$CONFIG/out/${{ matrix.android_version }}-${{ matrix.kernel_version }}/dist/Image ./ cp ./$CONFIG/out/${{ matrix.android_version }}-${{ matrix.kernel_version }}/dist/Image.lz4 ./ # Create gzip of the Image file gzip -n -k -f -9 ./Image > ./Image.gz - name: Unpack boot.img and Build Kernels run: | cd bootimgs echo "Building Image.gz" gzip -n -k -f -9 ./Image > ./Image.gz echo "Building boot.img" $MKBOOTIMG --header_version 4 --kernel Image --output boot.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot.img ../${{ matrix.kernel_version }}.${{ matrix.sub_level }}-${{ matrix.android_version }}-${{ matrix.os_patch_level }}-boot.img echo "Building boot-gz.img" $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot-gz.img ../${{ matrix.kernel_version }}.${{ matrix.sub_level }}-${{ matrix.android_version }}-${{ matrix.os_patch_level }}-boot-gz.img echo "Building boot-lz4.img" $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot-lz4.img ../${{ matrix.kernel_version }}.${{ matrix.sub_level }}-${{ matrix.android_version }}-${{ matrix.os_patch_level }}-boot-lz4.img - name: Create ZIP Files for Different Formats run: | echo "Creating zip files for all formats..." cd ./AnyKernel3 # Create and upload zip for each format ZIP_NAME="${{ matrix.kernel_version }}.${{ matrix.sub_level }}-${{ matrix.android_version }}-${{ matrix.os_patch_level }}-AnyKernel3.zip" echo "Creating zip file: $ZIP_NAME..." mv ../Image ./Image zip -r "../$ZIP_NAME" ./* rm ./Image ZIP_NAME="${{ matrix.kernel_version }}.${{ matrix.sub_level }}-${{ matrix.android_version }}-${{ matrix.os_patch_level }}-AnyKernel3-lz4.zip" echo "Creating zip file: $ZIP_NAME..." mv ../Image.lz4 ./Image.lz4 zip -r "../$ZIP_NAME" ./* rm ./Image.lz4 ZIP_NAME="${{ matrix.kernel_version }}.${{ matrix.sub_level }}-${{ matrix.android_version }}-${{ matrix.os_patch_level }}-AnyKernel3-gz.zip" echo "Creating zip file: $ZIP_NAME..." mv ../Image.gz ./Image.gz zip -r "../$ZIP_NAME" ./* rm ./Image.gz - name: Upload Build Artifacts uses: actions/upload-artifact@v4 with: name: kernel-${{ env.CONFIG }} path: | *.zip *.img