| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- name: fetch-latest-commits
- permissions:
- contents: write
- "on":
- workflow_dispatch:
- inputs:
- apply_changes:
- description: "Write updated commits to .github/config/commits.json and push"
- type: boolean
- default: false
- target_branch:
- description: "Branch to push changes to (only used when apply_changes=true)"
- type: string
- default: "main"
- jobs:
- gather-commits:
- runs-on: ubuntu-latest
- steps:
- - name: Checkout repository
- uses: actions/checkout@v5
- with:
- ref: ${{ inputs.target_branch }}
- - name: Gather latest commit pins
- id: gather
- shell: bash
- run: |
- set -euo pipefail
- COMMITS_FILE=".github/config/commits.json"
- KSU_REPO="https://github.com/KernelSU-Next/KernelSU-Next.git"
- SUSFS_REPO="https://gitlab.com/simonpunk/susfs4ksu.git"
- if [[ ! -f "$COMMITS_FILE" ]]; then
- echo "Missing commits file: $COMMITS_FILE"
- exit 1
- fi
- # Validate JSON early so we fail loudly on malformed edits.
- jq -e . "$COMMITS_FILE" >/dev/null
- KSU_BRANCH="dev"
- KSU_LATEST=$(git ls-remote "$KSU_REPO" "refs/heads/$KSU_BRANCH" | awk '{print $1}')
- if [[ -z "${KSU_LATEST:-}" ]]; then
- echo "Failed to resolve KernelSU branch: $KSU_BRANCH"
- exit 1
- fi
- TMP_FILE=$(mktemp)
- jq --arg commit "$KSU_LATEST" '.kernelsu.dev = $commit' "$COMMITS_FILE" > "$TMP_FILE"
- mv "$TMP_FILE" "$COMMITS_FILE"
- echo "KernelSU dev -> $KSU_LATEST"
- # Iterate current SUSFS keys (e.g. gki-android14-6.1) and fetch latest heads.
- while IFS= read -r branch; do
- [[ -n "$branch" ]] || continue
- latest=$(git ls-remote "$SUSFS_REPO" "refs/heads/$branch" | awk '{print $1}')
- if [[ -z "${latest:-}" ]]; then
- echo "Warning: could not resolve SUSFS branch: $branch"
- continue
- fi
- tmp=$(mktemp)
- jq --arg branch "$branch" --arg commit "$latest" '.susfs[$branch] = $commit' "$COMMITS_FILE" > "$tmp"
- mv "$tmp" "$COMMITS_FILE"
- echo "SUSFS $branch -> $latest"
- done < <(jq -r '.susfs | keys[]' "$COMMITS_FILE")
- echo "diff_present=false" >> "$GITHUB_OUTPUT"
- if ! git diff --quiet -- "$COMMITS_FILE"; then
- echo "diff_present=true" >> "$GITHUB_OUTPUT"
- fi
- - name: Show changes
- shell: bash
- run: |
- set -euo pipefail
- if git diff --quiet -- .github/config/commits.json; then
- echo "No updates found."
- else
- echo "Updated commit pins:"
- git --no-pager diff -- .github/config/commits.json
- fi
- - name: Commit and push changes
- if: inputs.apply_changes == true && steps.gather.outputs.diff_present == 'true'
- shell: bash
- run: |
- set -euo pipefail
- git config user.name "github-actions[bot]"
- git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- git add .github/config/commits.json
- git commit -m "chore(ci): refresh KernelSU and SUSFS commit pins"
- git push origin "HEAD:${{ inputs.target_branch }}"
- - name: Summary
- if: always()
- shell: bash
- run: |
- {
- echo "## Commit Pin Refresh"
- echo "- apply_changes: ${{ inputs.apply_changes }}"
- echo "- target_branch: ${{ inputs.target_branch }}"
- if git diff --quiet -- .github/config/commits.json; then
- echo "- result: no changes"
- else
- echo "- result: commits file updated"
- fi
- } >> "$GITHUB_STEP_SUMMARY"
|