action.yml 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. -H "Authorization: Bearer ***" \
  52. "https://api.github.com/repos/${OWNER}/${REPO}/releases/latest" > rel.json
  53. for URL in $(jq -r '.assets[] | select(.name | endswith(".apk")) | .browser_download_url' rel.json); do
  54. NAME="${URL##*/}"
  55. curl -fsSL --retry 5 --retry-delay 5 --retry-all-errors -o "/tmp/$NAME" "$URL"
  56. cp -f "/tmp/$NAME" "$OUT_ABS/$NAME"
  57. done
  58. else
  59. echo "Downloading $REPO manager from run $RUN_ID"
  60. ARTIFACTS_JSON=$(curl -fsSL --retry 5 --retry-delay 5 --retry-all-errors \
  61. -H "Authorization: Bearer $GH_TOKEN" \
  62. "https://api.github.com/repos/${OWNER}/${REPO}/actions/runs/${RUN_ID}/artifacts")
  63. if [ -z "$WANT" ]; then
  64. ARTIFACT_IDS=$(echo "$ARTIFACTS_JSON" | jq -r '.artifacts[].id')
  65. else
  66. ARTIFACT_IDS=$(echo "$ARTIFACTS_JSON" | jq -r --arg want "$WANT" '
  67. ($want | split(",")) as $wl |
  68. .artifacts[] | select(.name as $n | any($wl[]; $n == .)) | .id')
  69. fi
  70. echo "$ARTIFACT_IDS" | while read -r AID; do
  71. [ -n "$AID" ] || continue
  72. curl -fsSL --retry 5 --retry-delay 5 --retry-all-errors \
  73. -H "Authorization: Bearer $GH_TOKEN" \
  74. -o "_${AID}.zip" \
  75. "https://api.github.com/repos/${OWNER}/${REPO}/actions/artifacts/${AID}/zip"
  76. mkdir -p "_${AID}"
  77. unzip -o -q "_${AID}.zip" -d "_${AID}" || true
  78. rm -f "_${AID}.zip"
  79. for apk in _${AID}/*.apk; do
  80. [ -f "$apk" ] || continue
  81. cp -f "$apk" "$OUT_ABS/$(basename "$apk")"
  82. done
  83. rm -rf "_${AID}"
  84. done
  85. fi
  86. )
  87. rm -rf manager-dl
  88. - name: Print produced manager zips
  89. shell: bash
  90. run: |
  91. echo "Manager APK zips in ${{ inputs.output_dir }}:"
  92. find "${{ inputs.output_dir }}" -maxdepth 1 -type f -iname '*.zip' -printf '%f\n' | sort