action.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. COMMITS_COUNT=$(/usr/bin/git rev-list --count HEAD)
  47. BASE_VERSION=30000
  48. KSU_VERSION=$(expr $COMMITS_COUNT "+" $BASE_VERSION)
  49. sed -i "s/^KSU_VERSION_FALLBACK := 1$/KSU_VERSION_FALLBACK := ${KSU_VERSION}/" Kbuild
  50. KSU_GIT_TAG="$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.1")"
  51. sed -i "s/^KSU_VERSION_TAG_FALLBACK := v0.0.1$/KSU_VERSION_TAG_FALLBACK := ${KSU_GIT_TAG}/" Kbuild
  52. - name: Extract KSU Version Info
  53. id: ksu-version
  54. shell: bash
  55. working-directory: ${{ github.workspace }}/kernel/KernelSU-Next
  56. run: |
  57. # Get the base branch name by stripping suffixes (e.g., dev-susfs -> dev)
  58. BASE_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's:-.*::' 2>/dev/null)
  59. # Find the merge-base with the official origin branch to exclude local commits
  60. 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)
  61. KSU_GIT_VERSION=$(git rev-list --count $BASE_COMMIT 2>/dev/null)
  62. KSU_GIT_TAG=$(git describe --tags --abbrev=0 $BASE_COMMIT 2>/dev/null || echo "")
  63. KSU_COMMIT=$(git rev-parse --short HEAD 2>/dev/null)
  64. KSU_VERSION=$((30000 + KSU_GIT_VERSION))
  65. echo "KSU_GIT_TAG=$KSU_GIT_TAG" >> $GITHUB_ENV
  66. echo "KSU_VERSION=$KSU_VERSION" >> $GITHUB_ENV
  67. echo "KSU_COMMIT=$KSU_COMMIT" >> $GITHUB_ENV
  68. - name: 'Fix KernelSU-Next'
  69. shell: bash
  70. working-directory: ${{ github.workspace }}/kernel/KernelSU-Next
  71. run: |
  72. set -euo pipefail
  73. cp ${{ github.action_path }}/patches/static.patch "${{ github.workspace }}/kernel/KernelSU-Next/static.patch"
  74. patch -p1 < static.patch
  75. - name: Enable Kernel Configs
  76. uses: ./.github/actions/set-kernel-config
  77. with:
  78. config_list: |
  79. CONFIG_KSU=y