action.yml 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 per-APK zips 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. 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 "$NAME" "$URL"
  55. base="${NAME%.apk}"
  56. ( zip -qr "${OUT_ABS}/${REPO}_${base}.zip" "$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 $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 $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. base="${apk##*/}"
  82. ( cd "_${AID}" && zip -qr "${OUT_ABS}/${REPO}_${base%.apk}.zip" "${base}" )
  83. done
  84. rm -rf "_${AID}"
  85. done
  86. fi
  87. )
  88. rm -rf manager-dl
  89. - name: Print produced manager zips
  90. shell: bash
  91. run: |
  92. echo "Manager APK zips in ${{ inputs.output_dir }}:"
  93. find "${{ inputs.output_dir }}" -maxdepth 1 -type f -iname '*.zip' -printf '%f\n' | sort