action.yml 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. name: Setup Wild KSU
  2. description: Download and configure Wild KSU with version tracking
  3. inputs:
  4. ksu_branch:
  5. description: 'KernelSU branch or commit (empty = latest dev-susfs branch tip)'
  6. required: false
  7. default: ""
  8. runs:
  9. using: composite
  10. steps:
  11. - name: Download Wild KSU
  12. shell: bash
  13. working-directory: ${{ github.workspace }}/kernel
  14. run: |
  15. set -euo pipefail
  16. # Retry transient network errors (up to 5 attempts, 5s backoff).
  17. # Diagnostics go to stderr so pipes to grep are not polluted.
  18. retry() {
  19. local n=0
  20. until [ "$n" -ge 5 ]; do
  21. "$@" && return 0
  22. n=$((n+1))
  23. echo "retry $n/5 failed for: $*" >&2
  24. sleep 5
  25. done
  26. return 1
  27. }
  28. KSU_REPO="https://github.com/pershoot/KernelSU-Next.git"
  29. KSU_INPUT="${{ inputs.ksu_branch }}"
  30. if [ -z "$KSU_INPUT" ]; then
  31. KSU_INPUT="dev-susfs"
  32. fi
  33. # Try as branch first, fall back to commit
  34. if retry git ls-remote --heads "$KSU_REPO" "$KSU_INPUT" | grep -q .; then
  35. echo "Using KernelSU-Next branch: $KSU_INPUT"
  36. curl -LSs --retry 5 --retry-delay 5 --retry-all-errors "https://raw.githubusercontent.com/pershoot/KernelSU-Next/dev-susfs/kernel/setup.sh" | bash -s dev-susfs
  37. retry git -C KernelSU-Next/kernel fetch --depth=50 origin "$KSU_INPUT"
  38. git -C KernelSU-Next/kernel checkout "origin/$KSU_INPUT"
  39. else
  40. echo "Using KernelSU-Next commit: $KSU_INPUT"
  41. curl -LSs --retry 5 --retry-delay 5 --retry-all-errors "https://raw.githubusercontent.com/pershoot/KernelSU-Next/dev-susfs/kernel/setup.sh" | bash -s dev-susfs
  42. retry git -C KernelSU-Next/kernel fetch --depth=50 origin "$KSU_INPUT"
  43. git -C KernelSU-Next/kernel checkout "$KSU_INPUT"
  44. fi
  45. cd KernelSU-Next/kernel
  46. # Anchor the version to the upstream sync point (merge-base with
  47. # origin/<base-branch>) exactly like the official manager's
  48. # versionCode and pershoot's Kbuild (c0a2c5fd), so the kernel's
  49. # KSU_VERSION_FALLBACK matches the manager version the kernel
  50. # reports at runtime. Fall back to origin/main, then HEAD.
  51. BASE_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's:-.*::' 2>/dev/null)
  52. BASE_COMMIT=$(git merge-base HEAD refs/remotes/origin/$BASE_BRANCH 2>/dev/null || git merge-base HEAD refs/remotes/origin/main 2>/dev/null || echo HEAD)
  53. COMMITS_COUNT=$(/usr/bin/git rev-list --count $BASE_COMMIT)
  54. BASE_VERSION=30000
  55. KSU_VERSION=$(expr $COMMITS_COUNT "+" $BASE_VERSION)
  56. sed -i "s/^KSU_VERSION_FALLBACK := 1$/KSU_VERSION_FALLBACK := ${KSU_VERSION}/" Kbuild
  57. KSU_GIT_TAG="$(git describe --tags --abbrev=0 $BASE_COMMIT 2>/dev/null || echo "v0.0.1")"
  58. sed -i "s/^KSU_VERSION_TAG_FALLBACK := v0.0.1$/KSU_VERSION_TAG_FALLBACK := ${KSU_GIT_TAG}/" Kbuild
  59. - name: Extract KSU Version Info
  60. id: ksu-version
  61. shell: bash
  62. working-directory: ${{ github.workspace }}/kernel/KernelSU-Next
  63. run: |
  64. # Get the base branch name by stripping suffixes (e.g., dev-susfs -> dev)
  65. BASE_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's:-.*::' 2>/dev/null)
  66. # Find the merge-base with the official origin branch to exclude local commits
  67. BASE_COMMIT=$(git merge-base HEAD refs/remotes/origin/$BASE_BRANCH 2>/dev/null || git merge-base HEAD refs/remotes/origin/main 2>/dev/null || echo HEAD)
  68. KSU_GIT_VERSION=$(git rev-list --count $BASE_COMMIT 2>/dev/null)
  69. KSU_GIT_TAG=$(git describe --tags --abbrev=0 $BASE_COMMIT 2>/dev/null || echo "")
  70. KSU_COMMIT=$(git rev-parse --short HEAD 2>/dev/null)
  71. KSU_VERSION=$((30000 + KSU_GIT_VERSION))
  72. echo "KSU_GIT_TAG=$KSU_GIT_TAG" >> $GITHUB_ENV
  73. echo "KSU_VERSION=$KSU_VERSION" >> $GITHUB_ENV
  74. echo "KSU_COMMIT=$KSU_COMMIT" >> $GITHUB_ENV
  75. - name: 'Fix KernelSU-Next'
  76. shell: bash
  77. working-directory: ${{ github.workspace }}/kernel/KernelSU-Next
  78. run: |
  79. set -euo pipefail
  80. cp ${{ github.action_path }}/patches/static.patch "${{ github.workspace }}/kernel/KernelSU-Next/static.patch"
  81. patch -p1 < static.patch
  82. - name: Enable Kernel Configs
  83. uses: ./.github/actions/set-kernel-config
  84. with:
  85. config_list: |
  86. CONFIG_KSU=y