Skip to content

Commit b22f555

Browse files
committed
Add Support for multiple Root solution builds
1 parent 23fe1cf commit b22f555

File tree

2 files changed

+268
-63
lines changed

2 files changed

+268
-63
lines changed

.github/actions/action.yml

Lines changed: 140 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ inputs:
55
description: 'JSON string containing full device config'
66
required: true
77
type: string
8-
ksun_branch:
9-
description: 'KernelSU Next branch to use'
8+
ksu_type:
9+
description: 'Select KSU Type'
1010
required: true
11+
type: choice
12+
options:
13+
- KSUN
14+
- KSU
15+
ksu_branch_or_hash:
16+
description: 'KSU branch or commit hash (empty = auto-detect by ksu_type)'
17+
required: false
1118
type: string
12-
default: stable
19+
default: ""
1320
susfs_commit_hash_or_branch:
1421
description: 'SUSFS branch or commit hash (empty = auto-detect by kernel version)'
1522
required: false
1623
type: string
17-
default: ""
24+
default: ""
1825
optimize_level:
1926
description: 'Compiler optimization level (O2 or O3)'
2027
required: false
@@ -33,6 +40,9 @@ outputs:
3340
ksu_version:
3441
description: 'KernelSU Next version number'
3542
value: ${{ steps.save_metadata.outputs.ksu_version }}
43+
ksu_type:
44+
description: 'KernelSU Next version number'
45+
value: ${{ steps.save_metadata.outputs.ksu_type }}
3646
susfs_version:
3747
description: 'SUSFS version string'
3848
value: ${{ steps.save_metadata.outputs.susfs_version }}
@@ -599,15 +609,16 @@ runs:
599609
600610
- name: Add KernelSU Next
601611
shell: bash
612+
if: ${{ inputs.ksu_type == 'KSUN' }}
602613
run: |
603614
set -euo pipefail
604615
echo "::group::Add KernelSU Next"
605616
cd "$CONFIG/kernel_platform"
606617
echo "Adding KernelSU Next..."
607-
if [ "${{ inputs.ksun_branch }}" = "stable" ]; then
618+
if [ "${{ inputs.ksu_branch_or_hash }}" = "" ]; then
608619
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -
609620
else
610-
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -s "${{ inputs.ksun_branch }}"
621+
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -s "${{ inputs.ksu_branch_or_hash }}"
611622
fi
612623
git submodule update --init --recursive
613624
cd KernelSU-Next/kernel
@@ -616,12 +627,40 @@ runs:
616627
sed -i "s/DKSU_VERSION=11998/DKSU_VERSION=${KSU_VERSION}/" Makefile
617628
618629
cd ..
619-
KSUN_COMMIT_SHA=$(git rev-parse HEAD)
620-
echo "KSUN_COMMIT_SHA=$KSUN_COMMIT_SHA" >> $GITHUB_ENV
630+
KSU_COMMIT_SHA=$(git rev-parse HEAD)
631+
echo "KSU_COMMIT_SHA=$KSU_COMMIT_SHA" >> $GITHUB_ENV
621632
622633
echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
623634
echo "KernelSU Next Version: $KSU_VERSION"
624-
echo "✅ KernelSU Next added (commit: ${KSUN_COMMIT_SHA:0:8})"
635+
echo "✅ KernelSU Next added (commit: ${KSU_COMMIT_SHA:0:8})"
636+
echo "::endgroup::"
637+
638+
- name: Add KernelSU
639+
shell: bash
640+
if: ${{ inputs.ksu_type == 'KSU' }}
641+
run: |
642+
set -euo pipefail
643+
echo "::group::Add KernelSU"
644+
cd "$CONFIG/kernel_platform"
645+
echo "Adding KernelSU..."
646+
if [ "${{ inputs.ksu_branch_or_hash }}" = "" ]; then
647+
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -
648+
else
649+
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s "${{ inputs.ksu_branch_or_hash }}"
650+
fi
651+
git submodule update --init --recursive
652+
cd KernelSU/kernel
653+
BASE_VERSION=20000
654+
KSU_VERSION=$(expr $(/usr/bin/git rev-list --count HEAD) "+" $BASE_VERSION)
655+
sed -i "s/DKSU_VERSION=16/DKSU_VERSION=${KSU_VERSION}/" Makefile
656+
657+
cd ..
658+
KSU_COMMIT_SHA=$(git rev-parse HEAD)
659+
echo "KSU_COMMIT_SHA=$KSU_COMMIT_SHA" >> $GITHUB_ENV
660+
661+
echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
662+
echo "KernelSU Version: $KSU_VERSION"
663+
echo "✅ KernelSU added (commit: ${KSU_COMMIT_SHA:0:8})"
625664
echo "::endgroup::"
626665
627666
- name: Apply SUSFS Patches
@@ -635,41 +674,77 @@ runs:
635674
cp ../../susfs4ksu/kernel_patches/50_add_susfs_in_${{ env.SUSFS_KERNEL_BRANCH }}.patch ./common/
636675
cp ../../susfs4ksu/kernel_patches/fs/* ./common/fs/
637676
cp ../../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
638-
cd ./KernelSU-Next
639-
susfs_version=$(grep '#define SUSFS_VERSION' ../common/include/linux/susfs.h | awk -F'"' '{print $2}')
677+
678+
susfs_version=$(grep '#define SUSFS_VERSION' ./common/include/linux/susfs.h | awk -F'"' '{print $2}')
640679
echo "SUSVER=$susfs_version" >> $GITHUB_ENV
641680
echo "SusFS Version: $susfs_version"
681+
682+
# Function to compare semantic versions
683+
version_lte() {
684+
[ "$(printf '%s\n' "$2" "$1" | sort -V | head -n1)" = "$1" ]
685+
}
686+
687+
if version_lte "${susfs_version:1}" "1.5.12"; then
688+
echo "NEED_HOOKS=true" >> $GITHUB_ENV
689+
else
690+
echo "NEED_HOOKS=false" >> $GITHUB_ENV
691+
fi
692+
642693
case "$susfs_version" in
643694
"v1.5.5"|"v1.5.6"|"v1.5.7")
644-
cp "../../../kernel_patches/next/0001-kernel-implement-susfs-v1.5.5-v1.5.7-KSUN-v1.0.8.patch" "./ksun_susfs_latest.patch"
695+
if [ "${{ inputs.ksu_type }}" = "KSUN" ]; then
696+
cd ./KernelSU-Next
697+
patch -p1 --forward < "../../../kernel_patches/next/0001-kernel-implement-susfs-v1.5.5-v1.5.7-KSUN-v1.0.8.patch" || true
698+
else
699+
echo "Not Implemented!"
700+
exit 1
701+
fi
645702
;;
646703
"v1.5.8")
704+
if [ "${{ inputs.ksu_type }}" = "KSUN" ]; then
705+
cd ./KernelSU-Next
706+
else
707+
cd ./KernelSU
708+
fi
647709
cp ../../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
648-
patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch || true
649-
cp "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_apk_sign.c.patch" ./
650-
patch -p1 --forward --fuzz=3 < fix_apk_sign.c.patch
651-
cp "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_core_hook.c.patch" ./
652-
patch -p1 --forward --fuzz=3 < fix_core_hook.c.patch
653-
cp "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_selinux.c.patch" ./
654-
patch -p1 --forward --fuzz=3 < fix_selinux.c.patch
655-
cp "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_ksud.c.patch" ./
656-
patch -p1 --forward --fuzz=3 < fix_ksud.c.patch
710+
if [ "${{ inputs.ksu_type }}" = "KSUN" ]; then
711+
patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch || true
712+
cp "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_apk_sign.c.patch" ./
713+
patch -p1 --forward --fuzz=3 < fix_apk_sign.c.patch
714+
cp "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_core_hook.c.patch" ./
715+
patch -p1 --forward --fuzz=3 < fix_core_hook.c.patch
716+
cp "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_selinux.c.patch" ./
717+
patch -p1 --forward --fuzz=3 < fix_selinux.c.patch
718+
cp "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_ksud.c.patch" ./
719+
patch -p1 --forward --fuzz=3 < fix_ksud.c.patch
720+
else
721+
patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch
722+
fi
657723
;;
658-
"v1.5.9"|"v1.5.10"|"v1.5.11"|"v1.5.12")
724+
"v1.5.9"|"v1.5.10"|"v1.5.11"|"v1.5.12"|"v2.0.0")
725+
if [ "${{ inputs.ksu_type }}" = "KSUN" ]; then
726+
cd ./KernelSU-Next
727+
else
728+
cd ./KernelSU
729+
fi
659730
cp ../../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
660-
patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
661-
for file in $(find ./kernel -maxdepth 2 -name "*.rej" -printf "%f\n" | cut -d'.' -f1); do
662-
echo "Patching file: $file.c with fix_$file.c.patch"
663-
patch -p1 --forward < "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_$file.c.patch"
664-
done
665-
patch -p1 --forward < "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_kernel_compat.c.patch"
731+
if [ "${{ inputs.ksu_type }}" = "KSUN" ]; then
732+
patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
733+
for file in $(find ./kernel -maxdepth 2 -name "*.rej" -printf "%f\n" | cut -d'.' -f1); do
734+
echo "Patching file: $file.c with fix_$file.c.patch"
735+
patch -p1 --forward < "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_$file.c.patch"
736+
done
737+
patch -p1 --forward < "../../../kernel_patches/next/susfs_fix_patches/$susfs_version/fix_kernel_compat.c.patch"
738+
else
739+
patch -p1 --forward < 10_enable_susfs_for_ksu.patch
740+
fi
666741
;;
667742
*)
668743
echo "::error::Unsupported SUSFS version: $susfs_version"
669744
exit 1
670745
;;
671746
esac
672-
patch -p1 --forward < ksun_susfs_latest.patch || true
747+
673748
cd ../common
674749
if [ "${{ env.ANDROID_VER }}" = "android15" ] && [ "${{ env.KERNEL_VER }}" = "6.6" ]; then
675750
if ! grep -qxF '#include <trace/hooks/fs.h>' ./fs/namespace.c; then
@@ -771,20 +846,22 @@ runs:
771846
echo "✅ Other patches applied"
772847
echo "::endgroup::"
773848
774-
- name: Apply KSUN Hooks
849+
- name: Apply KSU Hooks
775850
shell: bash
851+
if: ${{ env.NEED_HOOKS == 'true' }}
776852
run: |
777853
set -euo pipefail
778-
echo "::group::Apply KSUN hooks"
854+
echo "::group::Apply KSU hooks"
779855
cd "$CONFIG/kernel_platform/common"
780856
patch -p1 < ../../../kernel_patches/next/scope_min_manual_hooks_v1.4.patch
781-
echo "✅ KSUN hooks applied"
857+
echo "✅ KSU hooks applied"
782858
echo "::endgroup::"
783859
784-
- name: Add KernelSU-Next and SUSFS Configuration Settings
860+
- name: Add KSU / KSUN and SUSFS Configuration Settings
785861
shell: bash
786862
run: |
787863
set -euo pipefail
864+
echo "::group::Add KSU / KSUN and SUSFS Configuration Settings"
788865
cd "$CONFIG/kernel_platform"
789866
cat >> common/arch/arm64/configs/gki_defconfig <<EOF
790867
CONFIG_KSU=y
@@ -811,11 +888,12 @@ runs:
811888
EOF
812889
echo "::endgroup::"
813890
814-
- name: Add Oneplus BBR
891+
- name: Add BBR
815892
if: ${{ env.OP_BBR == 'true' }}
816893
shell: bash
817894
run: |
818895
set -euo pipefail
896+
echo "::group::Add BBR"
819897
cd "$CONFIG/kernel_platform"
820898
cat >> common/arch/arm64/configs/gki_defconfig <<EOF
821899
CONFIG_TCP_CONG_ADVANCED=y
@@ -830,6 +908,7 @@ runs:
830908
shell: bash
831909
run: |
832910
set -euo pipefail
911+
echo "::group::Add TTL Target Support"
833912
cd "$CONFIG/kernel_platform"
834913
cat >> common/arch/arm64/configs/gki_defconfig <<EOF
835914
CONFIG_IP_NF_TARGET_TTL=y
@@ -843,6 +922,7 @@ runs:
843922
shell: bash
844923
run: |
845924
set -euo pipefail
925+
echo "::group::Add IP SET Support"
846926
cd "$CONFIG/kernel_platform"
847927
cat >> common/arch/arm64/configs/gki_defconfig <<EOF
848928
CONFIG_IP_SET=y
@@ -870,6 +950,7 @@ runs:
870950
shell: bash
871951
run: |
872952
set -euo pipefail
953+
echo "::group::Add Build based configs"
873954
cd "$CONFIG/kernel_platform"
874955
cat >> common/arch/arm64/configs/gki_defconfig <<EOF
875956
CONFIG_LTO_CLANG_THIN=y
@@ -885,11 +966,13 @@ runs:
885966
shell: bash
886967
run: |
887968
set -euo pipefail
969+
echo "::group::Save Build Metadata"
888970
CONFIG_DIR="$GITHUB_WORKSPACE/$CONFIG"
889971
ARTIFACTS_DIR="$CONFIG_DIR/artifacts"
890972
cd "$ARTIFACTS_DIR"
891973
echo "kernel_version=${{ env.KERNEL_FULL_VER }}" >> "$GITHUB_OUTPUT"
892974
echo "ksu_version=${KSUVER:-unknown}" >> "$GITHUB_OUTPUT"
975+
echo "ksu_type=${{ inputs.ksu_type }}" >> "$GITHUB_OUTPUT"
893976
if [ "${{ env.OP_SUSFS }}" = true ]; then
894977
echo "susfs_version=${SUSVER:-unknown}" >> "$GITHUB_OUTPUT"
895978
fi
@@ -899,6 +982,7 @@ runs:
899982
shell: bash
900983
run: |
901984
set -euo pipefail
985+
echo "::group::Customize Kernel Branding"
902986
KERNEL_PATH="$GITHUB_WORKSPACE/$CONFIG/kernel_platform"
903987
cd "$KERNEL_PATH/common"
904988
mkdir -p out
@@ -1210,7 +1294,7 @@ runs:
12101294
cp "$IMAGE_PATH" "$GITHUB_WORKSPACE/AnyKernel3/Image"
12111295
cd "$GITHUB_WORKSPACE/AnyKernel3"
12121296
1213-
ZIP_NAME="AK3_${OP_MODEL}_${OP_OS_VERSION}_${KERNEL_FULL_VER}_Next_${KSUVER}_${SUSVER}.zip"
1297+
ZIP_NAME="AK3_${OP_MODEL}_${OP_OS_VERSION}_${KERNEL_FULL_VER}_${{ inputs.ksu_type }}_${KSUVER}_${SUSVER}.zip"
12141298
ARTIFACTS_DIR="$CONFIG_DIR/artifacts"
12151299
mkdir -p "$ARTIFACTS_DIR"
12161300
@@ -1247,7 +1331,7 @@ runs:
12471331
set -euo pipefail
12481332
12491333
# Get commit SHAs with fallback
1250-
KSUN_SHA="${KSUN_COMMIT_SHA:-unknown}"
1334+
KSU_SHA="${KSU_COMMIT_SHA:-unknown}"
12511335
SUSFS_SHA="${SUSFS_COMMIT_SHA:-unknown}"
12521336
12531337
{
@@ -1259,8 +1343,13 @@ runs:
12591343
echo "Kernel Uname: ${{ env.KERNEL_UNAME }}"
12601344
echo "Build User: ${{ env.BUILD_USER }}"
12611345
echo "Build Host: ${{ env.BUILD_HOST }}"
1262-
echo "KSUN Version: ${KSUVER:-unknown}"
1263-
echo "KSUN commit SHA: $KSUN_SHA"
1346+
if [ "${{ inputs.ksu_type }}" = "KSUN" ]; then
1347+
echo "KSUN Version: ${KSUVER:-unknown}"
1348+
echo "KSUN commit SHA: $KSU_SHA"
1349+
else
1350+
echo "KSU Version: ${KSUVER:-unknown}"
1351+
echo "KSU commit SHA: $KSU_SHA"
1352+
fi
12641353
if [ "${{ env.OP_SUSFS }}" = true ]; then
12651354
echo "SUSFS Version: ${SUSVER:-unknown}"
12661355
echo "SUSFS Branch: ${{ env.SUSFS_BRANCH_NAME }}"
@@ -1299,12 +1388,20 @@ runs:
12991388
echo "| **Kernel Uname** | \`${{ env.KERNEL_UNAME }}\` |"
13001389
echo "| **Build User** | ${{ env.BUILD_USER }} |"
13011390
echo "| **Build Host** | ${{ env.BUILD_HOST }} |"
1302-
echo "| **KSUN Version** | ${KSUVER:-unknown} |"
1391+
if [ "${{ inputs.ksu_type }}" = "KSUN" ]; then
1392+
echo "| **KSUN Version** | ${KSUVER:-unknown} |"
1393+
else
1394+
echo "| **KSU Version** | ${KSUVER:-unknown} |"
1395+
fi
13031396
1304-
if [ "$KSUN_SHA" != "unknown" ]; then
1305-
echo "| **KSUN Commit** | [\`${KSUN_SHA:0:8}\`](https://github.com/KernelSU-Next/KernelSU-Next/commit/$KSUN_SHA) |"
1397+
if [ "$KSU_SHA" != "unknown" ]; then
1398+
if [ "${{ inputs.ksu_type }}" = "KSUN" ]; then
1399+
echo "| **KSUN Commit** | [\`${KSU_SHA:0:8}\`](https://github.com/KernelSU-Next/KernelSU-Next/commit/$KSU_SHA) |"
1400+
else
1401+
echo "| **KSU Commit** | [\`${KSU_SHA:0:8}\`](https://github.com/tiann/KernelSU/commit/$KSU_SHA) |"
1402+
fi
13061403
else
1307-
echo "| **KSUN Commit** | unknown |"
1404+
echo "| **KSU Commit** | unknown |"
13081405
fi
13091406
13101407
if [ "${{ env.OP_SUSFS }}" = true ]; then
@@ -1352,7 +1449,7 @@ runs:
13521449
if: success() && steps.create_zip.conclusion == 'success'
13531450
uses: actions/upload-artifact@v4
13541451
with:
1355-
name: kernel-${{ env.CONFIG }}_${{ env.OP_OS_VERSION }}
1452+
name: kernel-${{ inputs.ksu_type }}-${{ env.CONFIG }}_${{ env.OP_OS_VERSION }}
13561453
path: ${{ env.CONFIG }}/artifacts/
13571454
compression-level: 0
13581455
retention-days: 20

0 commit comments

Comments
 (0)