fetch-latest-commits.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. name: fetch-latest-commits
  2. permissions:
  3. contents: write
  4. "on":
  5. workflow_dispatch:
  6. inputs:
  7. apply_changes:
  8. description: "Write updated commits to .github/config/commits.json and push"
  9. type: boolean
  10. default: false
  11. target_branch:
  12. description: "Branch to push changes to (only used when apply_changes=true)"
  13. type: string
  14. default: "main"
  15. jobs:
  16. gather-commits:
  17. runs-on: ubuntu-latest
  18. steps:
  19. - name: Checkout repository
  20. uses: actions/checkout@v5
  21. with:
  22. ref: ${{ inputs.target_branch }}
  23. - name: Gather latest commit pins
  24. id: gather
  25. shell: bash
  26. run: |
  27. set -euo pipefail
  28. COMMITS_FILE=".github/config/commits.json"
  29. KSU_REPO="https://github.com/KernelSU-Next/KernelSU-Next.git"
  30. SUSFS_REPO="https://gitlab.com/simonpunk/susfs4ksu.git"
  31. if [[ ! -f "$COMMITS_FILE" ]]; then
  32. echo "Missing commits file: $COMMITS_FILE"
  33. exit 1
  34. fi
  35. # Validate JSON early so we fail loudly on malformed edits.
  36. jq -e . "$COMMITS_FILE" >/dev/null
  37. KSU_BRANCH="dev"
  38. KSU_LATEST=$(git ls-remote "$KSU_REPO" "refs/heads/$KSU_BRANCH" | awk '{print $1}')
  39. if [[ -z "${KSU_LATEST:-}" ]]; then
  40. echo "Failed to resolve KernelSU branch: $KSU_BRANCH"
  41. exit 1
  42. fi
  43. TMP_FILE=$(mktemp)
  44. jq --arg commit "$KSU_LATEST" '.kernelsu.dev = $commit' "$COMMITS_FILE" > "$TMP_FILE"
  45. mv "$TMP_FILE" "$COMMITS_FILE"
  46. echo "KernelSU dev -> $KSU_LATEST"
  47. # Iterate current SUSFS keys (e.g. gki-android14-6.1) and fetch latest heads.
  48. while IFS= read -r branch; do
  49. [[ -n "$branch" ]] || continue
  50. latest=$(git ls-remote "$SUSFS_REPO" "refs/heads/$branch" | awk '{print $1}')
  51. if [[ -z "${latest:-}" ]]; then
  52. echo "Warning: could not resolve SUSFS branch: $branch"
  53. continue
  54. fi
  55. tmp=$(mktemp)
  56. jq --arg branch "$branch" --arg commit "$latest" '.susfs[$branch] = $commit' "$COMMITS_FILE" > "$tmp"
  57. mv "$tmp" "$COMMITS_FILE"
  58. echo "SUSFS $branch -> $latest"
  59. done < <(jq -r '.susfs | keys[]' "$COMMITS_FILE")
  60. echo "diff_present=false" >> "$GITHUB_OUTPUT"
  61. if ! git diff --quiet -- "$COMMITS_FILE"; then
  62. echo "diff_present=true" >> "$GITHUB_OUTPUT"
  63. fi
  64. - name: Show changes
  65. shell: bash
  66. run: |
  67. set -euo pipefail
  68. if git diff --quiet -- .github/config/commits.json; then
  69. echo "No updates found."
  70. else
  71. echo "Updated commit pins:"
  72. git --no-pager diff -- .github/config/commits.json
  73. fi
  74. - name: Commit and push changes
  75. if: inputs.apply_changes == true && steps.gather.outputs.diff_present == 'true'
  76. shell: bash
  77. run: |
  78. set -euo pipefail
  79. git config user.name "github-actions[bot]"
  80. git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
  81. git add .github/config/commits.json
  82. git commit -m "chore(ci): refresh KernelSU and SUSFS commit pins"
  83. git push origin "HEAD:${{ inputs.target_branch }}"
  84. - name: Summary
  85. if: always()
  86. shell: bash
  87. run: |
  88. {
  89. echo "## Commit Pin Refresh"
  90. echo "- apply_changes: ${{ inputs.apply_changes }}"
  91. echo "- target_branch: ${{ inputs.target_branch }}"
  92. if git diff --quiet -- .github/config/commits.json; then
  93. echo "- result: no changes"
  94. else
  95. echo "- result: commits file updated"
  96. fi
  97. } >> "$GITHUB_STEP_SUMMARY"