action.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. name: Fetch Root Manager APKs
  2. description: >-
  3. Download the manager APK artifacts for one root implementation from its
  4. upstream CI/build, extract the .apk files, and re-zip each APK into a clean
  5. per-manager folder. The caller uploads that folder as a single artifact.
  6. inputs:
  7. owner:
  8. description: Owner of the upstream repo (e.g. KernelSU-Next, tiann, ReSukiSU)
  9. required: true
  10. repo:
  11. description: Upstream repo name
  12. required: true
  13. source:
  14. description: Manager APK source ('run' = CI artifacts, 'release' = latest GitHub release)
  15. required: true
  16. default: run
  17. run_id:
  18. description: Upstream Actions run ID (source='run')
  19. required: false
  20. default: ''
  21. want:
  22. description: Comma-separated artifact names to download (blank = all). Filters out LKM/ksud noise.
  23. required: false
  24. default: ''
  25. token:
  26. description: PAT with read access to the upstream repo (for private/artifact downloads)
  27. required: true
  28. output_dir:
  29. description: Absolute path of the folder to write each extracted .apk file into
  30. required: true
  31. runs:
  32. using: composite
  33. steps:
  34. - name: Download and zip manager APKs
  35. shell: bash
  36. run: |
  37. set -euo pipefail
  38. OWNER="${{ inputs.owner }}"
  39. REPO="${{ inputs.repo }}"
  40. SRC="${{ inputs.source }}"
  41. RUN_ID="${{ inputs.run_id }}"
  42. WANT="${{ inputs.want }}"
  43. OUT_ABS="${{ inputs.output_dir }}"
  44. GH_TOKEN="${{ inputs.token }}"
  45. mkdir -p "$OUT_ABS" manager-dl
  46. (
  47. cd manager-dl
  48. if [ "$SRC" = "release" ]; then
  49. echo "Downloading all $REPO manager APKs from latest release"
  50. curl -fsSL --retry 5 --retry-delay 5 --retry-all-errors \
  51. "https://api.github.com/repos/${OWNER}/${REPO}/releases/latest" > rel.json
  52. for URL in $(jq -r '.assets[] | select(.name | endswith(".apk")) | .browser_download_url' rel.json); do
  53. NAME="${URL##*/}"
  54. curl -fsSL --retry 5 --retry-delay 5 --retry-all-errors -o "/tmp/$NAME" "$URL"
  55. cp -f "/tmp/$NAME" "$OUT_ABS/$NAME"
  56. done
  57. else
  58. echo "Downloading $REPO manager from run $RUN_ID"
  59. ARTIFACTS_JSON=$(curl -fsSL --retry 5 --retry-delay 5 --retry-all-errors \
  60. -H "Authorization: Bearer $GH_TOKEN" \
  61. "https://api.github.com/repos/${OWNER}/${REPO}/actions/runs/${RUN_ID}/artifacts")
  62. if [ -z "$WANT" ]; then
  63. ARTIFACT_IDS=$(echo "$ARTIFACTS_JSON" | jq -r '.artifacts[].id')
  64. else
  65. ARTIFACT_IDS=$(echo "$ARTIFACTS_JSON" | jq -r --arg want "$WANT" '
  66. ($want | split(",")) as $wl |
  67. .artifacts[] | select(.name as $n | any($wl[]; $n == .)) | .id')
  68. fi
  69. echo "$ARTIFACT_IDS" | while read -r AID; do
  70. [ -n "$AID" ] || continue
  71. curl -fsSL --retry 5 --retry-delay 5 --retry-all-errors \
  72. -H "Authorization: Bearer $GH_TOKEN" \
  73. -o "_${AID}.zip" \
  74. "https://api.github.com/repos/${OWNER}/${REPO}/actions/artifacts/${AID}/zip"
  75. mkdir -p "_${AID}"
  76. unzip -o -q "_${AID}.zip" -d "_${AID}" || true
  77. rm -f "_${AID}.zip"
  78. for apk in _${AID}/*.apk; do
  79. [ -f "$apk" ] || continue
  80. cp -f "$apk" "$OUT_ABS/$(basename "$apk")"
  81. done
  82. rm -rf "_${AID}"
  83. done
  84. fi
  85. )
  86. rm -rf manager-dl
  87. - name: Print produced manager zips
  88. shell: bash
  89. run: |
  90. echo "Manager APK zips in ${{ inputs.output_dir }}:"
  91. find "${{ inputs.output_dir }}" -maxdepth 1 -type f -iname '*.zip' -printf '%f\n' | sort