| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- name: Setup pinned root implementation
- description: 'Clone exactly one supported root implementation at a verified commit for Samsung'
- inputs:
- flavor:
- description: 'kernelsu, next, or resukisu'
- required: true
- commit:
- description: 'Full immutable commit SHA'
- required: true
- runs:
- using: composite
- steps:
- - name: Clone and integrate selected root
- shell: bash
- run: |
- set -euo pipefail
- flavor="${{ inputs.flavor }}"
- expected_commit="${{ inputs.commit }}"
- case "$flavor" in
- kernelsu)
- repo="https://github.com/tiann/KernelSU.git"
- directory="KernelSU"
- manager="KernelSU Manager"
- repobranch="main"
- ;;
- next)
- repo="https://github.com/KernelSU-Next/KernelSU-Next.git"
- directory="KernelSU-Next"
- manager="KernelSU Next Manager"
- repobranch="dev"
- ;;
- resukisu)
- repo="https://github.com/ReSukiSU/ReSukiSU.git"
- directory="ReSukiSU"
- manager="ReSukiSU Manager"
- repobranch="main"
- ;;
- *)
- echo "Unsupported root flavor: $flavor" >&2
- exit 2
- ;;
- esac
- if ! [[ "$expected_commit" =~ ^[0-9a-f]{40}$ ]]; then
- echo "Root commit must be a full 40-character SHA." >&2
- exit 2
- fi
- if [ -n "${COMMON:-}" ] && [ -d "$COMMON" ]; then
- KROOT="$COMMON"
- CLONE_BASE="$CONFIG"
- elif [ -n "${CONFIG:-}" ] && [ -d "$CONFIG" ]; then
- if [ -d "$CONFIG/kernel_platform/common" ]; then KROOT="$CONFIG/kernel_platform/common"
- elif [ -d "$CONFIG/common" ]; then KROOT="$CONFIG/common"
- elif [ -d "$CONFIG/kernel-6.6" ]; then KROOT="$CONFIG/kernel-6.6"
- elif [ -d "$CONFIG/kernel-6.1" ]; then KROOT="$CONFIG/kernel-6.1"
- elif [ -d "$CONFIG/kernel-5.10" ]; then KROOT="$CONFIG/kernel-5.10"
- elif [ -d "$CONFIG/kernel" ]; then KROOT="$CONFIG/kernel"
- else KROOT="$CONFIG"
- fi
- CLONE_BASE="$CONFIG"
- else
- echo "Cannot resolve kernel root (COMMON/CONFIG not set)." >&2
- exit 1
- fi
- echo "KROOT=$KROOT CLONE_BASE=$CLONE_BASE flavor=$flavor"
- for candidate in KernelSU KernelSU-Next ReSukiSU; do
- if [ "$candidate" != "$directory" ] && [ -e "$CLONE_BASE/$candidate" ]; then
- echo "Refusing mixed root implementations: found $candidate." >&2
- exit 1
- fi
- done
- drivers_dir="$KROOT/drivers"
- if [ ! -d "$drivers_dir" ]; then
- echo "Kernel drivers directory not found at $drivers_dir" >&2
- exit 1
- fi
- if [ -e "$drivers_dir/kernelsu" ] || [ -L "$drivers_dir/kernelsu" ]; then
- echo "Refusing to replace an existing kernelsu integration." >&2
- exit 1
- fi
- if [ -e "$CLONE_BASE/$directory" ]; then
- echo "Refusing to reuse an existing root checkout: $directory." >&2
- exit 1
- fi
- git clone --no-checkout "$repo" "$CLONE_BASE/$directory"
- git -C "$CLONE_BASE/$directory" fetch --depth=1 origin "$expected_commit"
- git -C "$CLONE_BASE/$directory" checkout --detach "$expected_commit"
- actual_commit="$(git -C "$CLONE_BASE/$directory" rev-parse HEAD)"
- if [ "$actual_commit" != "$expected_commit" ]; then
- echo "Root commit mismatch: expected $expected_commit, got $actual_commit." >&2
- exit 1
- fi
- if [ ! -f "$CLONE_BASE/$directory/kernel/Kconfig" ] || [ ! -f "$CLONE_BASE/$directory/kernel/Makefile" ]; then
- echo "Selected root checkout does not contain a kernel integration." >&2
- exit 1
- fi
- # ReSukiSU+Bazel sandbox fix: bypass .git submodule check (sandbox has no .git)
- if [ "$flavor" = "resukisu" ]; then
- kbuild="$CLONE_BASE/$directory/kernel/Kbuild"
- if grep -q "LOCAL_GIT_EXISTS" "$kbuild"; then
- sed -i 's/^LOCAL_GIT_EXISTS.*/LOCAL_GIT_EXISTS := 1/' "$kbuild"
- echo "Patched ReSukiSU Kbuild for Bazel sandbox (LOCAL_GIT_EXISTS=1)"
- fi
- fi
- root_version="$(git -C "$CLONE_BASE/$directory" describe --tags --always --dirty)"
- relative_kernel="$(realpath --relative-to="$drivers_dir" "$CLONE_BASE/$directory/kernel" 2>/dev/null || echo "$CLONE_BASE/$directory/kernel")"
- ln -s "$relative_kernel" "$drivers_dir/kernelsu"
- grep -q 'obj-$(CONFIG_KSU) += kernelsu/' "$drivers_dir/Makefile" || printf '\nobj-$(CONFIG_KSU) += kernelsu/\n' >> "$drivers_dir/Makefile"
- grep -q 'source "drivers/kernelsu/Kconfig"' "$drivers_dir/Kconfig" || sed -i '/endmenu/i source "drivers/kernelsu/Kconfig"' "$drivers_dir/Kconfig"
- ln -sf "$CLONE_BASE/$directory" "$COMMON/KernelSU-Next" 2>/dev/null || true
- echo "ROOT_IMPLEMENTATION=$flavor" >> "$GITHUB_ENV"
- echo "ROOT_MANAGER=$manager" >> "$GITHUB_ENV"
- echo "ROOT_VERSION=$root_version" >> "$GITHUB_ENV"
- echo "ROOT_COMMIT=$actual_commit" >> "$GITHUB_ENV"
- echo "ROOT_DIR=$CLONE_BASE/$directory" >> "$GITHUB_ENV"
- cd "$CLONE_BASE/$directory"
-
- # Explicitly fetch the branch tracking ref and all tags into the clone
- git fetch origin "$repobranch":refs/remotes/origin/"$repobranch" --tags --unshallow 2>/dev/null || \
- git fetch origin "$repobranch":refs/remotes/origin/"$repobranch" --tags 2>/dev/null || true
-
- # Extract and export KSU version info for the PINNED commit, not the
- # branch tip: the pin is what we build, and the tip may have moved on.
- KSU_GIT_VERSION=$(git rev-list --count "$expected_commit" 2>/dev/null || echo "0")
- KSU_GIT_TAG=$(git describe --tags --abbrev=0 "$expected_commit" 2>/dev/null || echo "v0.0.1")
- KSU_SHORT=$(git rev-parse --short=8 "$expected_commit")
- KSU_VERSION=$((30000 + KSU_GIT_VERSION))
- cd kernel
-
- # Dynamically target the right version and tag variable patterns
- if [ "$flavor" = "resukisu" ]; then
- # Add the 700 offset specifically required by ReSukiSU's version logic
- KSU_VERSION=$((KSU_VERSION + 700))
-
- # ReSukiSU targets KSU_VERSION and KSU_TAG_NAME explicitly
- sed -i "s|^KSU_VERSION :=.*|KSU_VERSION := ${KSU_VERSION}|" Kbuild
- sed -i "s|^KSU_TAG_NAME.*:=.*|KSU_TAG_NAME := ${KSU_GIT_TAG}|" Kbuild
- # Bake the short SHA too (both the probe and the -dirty append
- # match, so both become the literal and the suffix is gone), plus
- # the branch the pin was taken from.
- sed -i "s|^KSU_COMMIT_SHA :=.*|KSU_COMMIT_SHA := ${KSU_SHORT}|" Kbuild
- sed -i "s|^KSU_BRANCH_NAME :=.*|KSU_BRANCH_NAME := ${repobranch}|" Kbuild
- elif [ "$flavor" = "next" ]; then
- #KernelSU-Next uses fallback pattern
- sed -i "s/^KSU_VERSION_FALLBACK := 1$/KSU_VERSION_FALLBACK := ${KSU_VERSION}/" Kbuild
- sed -i "s|^KSU_VERSION_TAG_FALLBACK := v0.0.1$|KSU_VERSION_TAG_FALLBACK := ${KSU_GIT_TAG}|" Kbuild
- else
- # 1. Overwrite the dynamic Git count query with your calculated raw count
- sed -i "s|^KSU_GIT_VERSION :=.*|KSU_GIT_VERSION := ${KSU_GIT_VERSION}|" Kbuild
-
- # 2. Hardcode the validation check true state flag
- sed -i "s|^KSU_GIT_VERSION_VALID :=.*|KSU_GIT_VERSION_VALID := 1|" Kbuild
-
- # 3. Direct replacement of the eval block using your final computed final total
- sed -i "s|^\\$(eval KSU_VERSION=\\$(shell expr 30000 + \\$(KSU_GIT_VERSION)))|\\$(eval KSU_VERSION=${KSU_VERSION})|" Kbuild
- fi
-
- echo "KSU_GIT_TAG=$KSU_GIT_TAG" >> "$GITHUB_ENV"
- echo "KSU_VERSION=$KSU_VERSION" >> "$GITHUB_ENV"
- - name: Enable root configuration
- shell: bash
- run: |
- "$COMMON/scripts/config" --file "$GKI_DEFCONFIG" --enable CONFIG_KSU
|