action.yml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. name: Setup pinned root implementation
  2. description: 'Clone exactly one supported root implementation at a verified commit for Samsung'
  3. inputs:
  4. flavor:
  5. description: 'kernelsu, next, or resukisu'
  6. required: true
  7. commit:
  8. description: 'Full immutable commit SHA'
  9. required: true
  10. runs:
  11. using: composite
  12. steps:
  13. - name: Clone and integrate selected root
  14. shell: bash
  15. run: |
  16. set -euo pipefail
  17. flavor="${{ inputs.flavor }}"
  18. expected_commit="${{ inputs.commit }}"
  19. case "$flavor" in
  20. kernelsu)
  21. repo="https://github.com/tiann/KernelSU.git"
  22. directory="KernelSU"
  23. manager="KernelSU Manager"
  24. repobranch="main"
  25. ;;
  26. next)
  27. repo="https://github.com/KernelSU-Next/KernelSU-Next.git"
  28. directory="KernelSU-Next"
  29. manager="KernelSU Next Manager"
  30. repobranch="dev"
  31. ;;
  32. resukisu)
  33. repo="https://github.com/ReSukiSU/ReSukiSU.git"
  34. directory="ReSukiSU"
  35. manager="ReSukiSU Manager"
  36. repobranch="main"
  37. ;;
  38. *)
  39. echo "Unsupported root flavor: $flavor" >&2
  40. exit 2
  41. ;;
  42. esac
  43. if ! [[ "$expected_commit" =~ ^[0-9a-f]{40}$ ]]; then
  44. echo "Root commit must be a full 40-character SHA." >&2
  45. exit 2
  46. fi
  47. if [ -n "${COMMON:-}" ] && [ -d "$COMMON" ]; then
  48. KROOT="$COMMON"
  49. CLONE_BASE="$CONFIG"
  50. elif [ -n "${CONFIG:-}" ] && [ -d "$CONFIG" ]; then
  51. if [ -d "$CONFIG/kernel_platform/common" ]; then KROOT="$CONFIG/kernel_platform/common"
  52. elif [ -d "$CONFIG/common" ]; then KROOT="$CONFIG/common"
  53. elif [ -d "$CONFIG/kernel-6.6" ]; then KROOT="$CONFIG/kernel-6.6"
  54. elif [ -d "$CONFIG/kernel-6.1" ]; then KROOT="$CONFIG/kernel-6.1"
  55. elif [ -d "$CONFIG/kernel-5.10" ]; then KROOT="$CONFIG/kernel-5.10"
  56. elif [ -d "$CONFIG/kernel" ]; then KROOT="$CONFIG/kernel"
  57. else KROOT="$CONFIG"
  58. fi
  59. CLONE_BASE="$CONFIG"
  60. else
  61. echo "Cannot resolve kernel root (COMMON/CONFIG not set)." >&2
  62. exit 1
  63. fi
  64. echo "KROOT=$KROOT CLONE_BASE=$CLONE_BASE flavor=$flavor"
  65. for candidate in KernelSU KernelSU-Next ReSukiSU; do
  66. if [ "$candidate" != "$directory" ] && [ -e "$CLONE_BASE/$candidate" ]; then
  67. echo "Refusing mixed root implementations: found $candidate." >&2
  68. exit 1
  69. fi
  70. done
  71. drivers_dir="$KROOT/drivers"
  72. if [ ! -d "$drivers_dir" ]; then
  73. echo "Kernel drivers directory not found at $drivers_dir" >&2
  74. exit 1
  75. fi
  76. if [ -e "$drivers_dir/kernelsu" ] || [ -L "$drivers_dir/kernelsu" ]; then
  77. echo "Refusing to replace an existing kernelsu integration." >&2
  78. exit 1
  79. fi
  80. if [ -e "$CLONE_BASE/$directory" ]; then
  81. echo "Refusing to reuse an existing root checkout: $directory." >&2
  82. exit 1
  83. fi
  84. git clone --no-checkout "$repo" "$CLONE_BASE/$directory"
  85. git -C "$CLONE_BASE/$directory" fetch --depth=1 origin "$expected_commit"
  86. git -C "$CLONE_BASE/$directory" checkout --detach "$expected_commit"
  87. actual_commit="$(git -C "$CLONE_BASE/$directory" rev-parse HEAD)"
  88. if [ "$actual_commit" != "$expected_commit" ]; then
  89. echo "Root commit mismatch: expected $expected_commit, got $actual_commit." >&2
  90. exit 1
  91. fi
  92. if [ ! -f "$CLONE_BASE/$directory/kernel/Kconfig" ] || [ ! -f "$CLONE_BASE/$directory/kernel/Makefile" ]; then
  93. echo "Selected root checkout does not contain a kernel integration." >&2
  94. exit 1
  95. fi
  96. # ReSukiSU+Bazel sandbox fix: bypass .git submodule check (sandbox has no .git)
  97. if [ "$flavor" = "resukisu" ]; then
  98. kbuild="$CLONE_BASE/$directory/kernel/Kbuild"
  99. if grep -q "LOCAL_GIT_EXISTS" "$kbuild"; then
  100. sed -i 's/^LOCAL_GIT_EXISTS.*/LOCAL_GIT_EXISTS := 1/' "$kbuild"
  101. echo "Patched ReSukiSU Kbuild for Bazel sandbox (LOCAL_GIT_EXISTS=1)"
  102. fi
  103. fi
  104. root_version="$(git -C "$CLONE_BASE/$directory" describe --tags --always --dirty)"
  105. relative_kernel="$(realpath --relative-to="$drivers_dir" "$CLONE_BASE/$directory/kernel" 2>/dev/null || echo "$CLONE_BASE/$directory/kernel")"
  106. ln -s "$relative_kernel" "$drivers_dir/kernelsu"
  107. grep -q 'obj-$(CONFIG_KSU) += kernelsu/' "$drivers_dir/Makefile" || printf '\nobj-$(CONFIG_KSU) += kernelsu/\n' >> "$drivers_dir/Makefile"
  108. grep -q 'source "drivers/kernelsu/Kconfig"' "$drivers_dir/Kconfig" || sed -i '/endmenu/i source "drivers/kernelsu/Kconfig"' "$drivers_dir/Kconfig"
  109. ln -sf "$CLONE_BASE/$directory" "$COMMON/KernelSU-Next" 2>/dev/null || true
  110. echo "ROOT_IMPLEMENTATION=$flavor" >> "$GITHUB_ENV"
  111. echo "ROOT_MANAGER=$manager" >> "$GITHUB_ENV"
  112. echo "ROOT_VERSION=$root_version" >> "$GITHUB_ENV"
  113. echo "ROOT_COMMIT=$actual_commit" >> "$GITHUB_ENV"
  114. echo "ROOT_DIR=$CLONE_BASE/$directory" >> "$GITHUB_ENV"
  115. cd "$CLONE_BASE/$directory"
  116. # Explicitly fetch the branch tracking ref and all tags into the clone
  117. git fetch origin "$repobranch":refs/remotes/origin/"$repobranch" --tags --unshallow 2>/dev/null || \
  118. git fetch origin "$repobranch":refs/remotes/origin/"$repobranch" --tags 2>/dev/null || true
  119. # Extract and export KSU version info for the PINNED commit, not the
  120. # branch tip: the pin is what we build, and the tip may have moved on.
  121. KSU_GIT_VERSION=$(git rev-list --count "$expected_commit" 2>/dev/null || echo "0")
  122. KSU_GIT_TAG=$(git describe --tags --abbrev=0 "$expected_commit" 2>/dev/null || echo "v0.0.1")
  123. KSU_SHORT=$(git rev-parse --short=8 "$expected_commit")
  124. KSU_VERSION=$((30000 + KSU_GIT_VERSION))
  125. cd kernel
  126. # Dynamically target the right version and tag variable patterns
  127. if [ "$flavor" = "resukisu" ]; then
  128. # Add the 700 offset specifically required by ReSukiSU's version logic
  129. KSU_VERSION=$((KSU_VERSION + 700))
  130. # ReSukiSU targets KSU_VERSION and KSU_TAG_NAME explicitly
  131. sed -i "s|^KSU_VERSION :=.*|KSU_VERSION := ${KSU_VERSION}|" Kbuild
  132. sed -i "s|^KSU_TAG_NAME.*:=.*|KSU_TAG_NAME := ${KSU_GIT_TAG}|" Kbuild
  133. # Bake the short SHA too (both the probe and the -dirty append
  134. # match, so both become the literal and the suffix is gone), plus
  135. # the branch the pin was taken from.
  136. sed -i "s|^KSU_COMMIT_SHA :=.*|KSU_COMMIT_SHA := ${KSU_SHORT}|" Kbuild
  137. sed -i "s|^KSU_BRANCH_NAME :=.*|KSU_BRANCH_NAME := ${repobranch}|" Kbuild
  138. elif [ "$flavor" = "next" ]; then
  139. #KernelSU-Next uses fallback pattern
  140. sed -i "s/^KSU_VERSION_FALLBACK := 1$/KSU_VERSION_FALLBACK := ${KSU_VERSION}/" Kbuild
  141. sed -i "s|^KSU_VERSION_TAG_FALLBACK := v0.0.1$|KSU_VERSION_TAG_FALLBACK := ${KSU_GIT_TAG}|" Kbuild
  142. else
  143. # 1. Overwrite the dynamic Git count query with your calculated raw count
  144. sed -i "s|^KSU_GIT_VERSION :=.*|KSU_GIT_VERSION := ${KSU_GIT_VERSION}|" Kbuild
  145. # 2. Hardcode the validation check true state flag
  146. sed -i "s|^KSU_GIT_VERSION_VALID :=.*|KSU_GIT_VERSION_VALID := 1|" Kbuild
  147. # 3. Direct replacement of the eval block using your final computed final total
  148. sed -i "s|^\\$(eval KSU_VERSION=\\$(shell expr 30000 + \\$(KSU_GIT_VERSION)))|\\$(eval KSU_VERSION=${KSU_VERSION})|" Kbuild
  149. fi
  150. echo "KSU_GIT_TAG=$KSU_GIT_TAG" >> "$GITHUB_ENV"
  151. echo "KSU_VERSION=$KSU_VERSION" >> "$GITHUB_ENV"
  152. - name: Enable root configuration
  153. shell: bash
  154. run: |
  155. "$COMMON/scripts/config" --file "$GKI_DEFCONFIG" --enable CONFIG_KSU