action.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. name: 'Download Kernel Repository'
  2. description: 'Initialize and sync Android kernel source repository'
  3. inputs:
  4. android_version:
  5. description: 'Android version (e.g., android14)'
  6. required: true
  7. kernel_version:
  8. description: 'Kernel version (e.g., 5.15, 6.1)'
  9. required: true
  10. os_patch_level:
  11. description: 'OS patch level (e.g., 2024-01)'
  12. required: true
  13. use_repo:
  14. description: 'Use repo for downloading kernel source'
  15. required: false
  16. outputs:
  17. deprecated_branch:
  18. description: 'Whether the branch is deprecated'
  19. value: ${{ steps.sync.outputs.deprecated }}
  20. runs:
  21. using: composite
  22. steps:
  23. - name: Initialize and Sync Kernel Repository
  24. if: ${{ inputs.use_repo == 'true' }}
  25. id: sync
  26. shell: bash
  27. working-directory: ${{ github.workspace }}/kernel
  28. run: |
  29. set -euo pipefail
  30. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  31. init_repo() {
  32. repo init -u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --depth=1 || { echo "ERROR: repo init failed" >&2; return 1; }
  33. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH}) || { echo "ERROR: git ls-remote failed" >&2; return 1; }
  34. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  35. DEPRECATED=false
  36. if grep -q deprecated <<< "$REMOTE_BRANCH"; then
  37. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" "$DEFAULT_MANIFEST_PATH"
  38. echo "⚠ Note: Branch ${FORMATTED_BRANCH} is considered deprecated."
  39. DEPRECATED=true
  40. fi
  41. echo "deprecated=$DEPRECATED" >> $GITHUB_OUTPUT
  42. }
  43. init_repo || { echo "ERROR: init_repo failed" >&2; exit 1; }
  44. MAX_RETRIES=3
  45. RETRY_DELAY_SHORT=15
  46. SYNC_TIMEOUT="15m"
  47. attempt=1
  48. while [ $attempt -le $MAX_RETRIES ]; do
  49. echo "Attempt $attempt/$MAX_RETRIES: repo sync (timeout $SYNC_TIMEOUT)..."
  50. #if timeout $SYNC_TIMEOUT repo sync -c -j16 --fail-fast --no-tags --force-sync --no-clone-bundle --optimized-fetch --retry-fetches=3; then
  51. if timeout $SYNC_TIMEOUT repo sync -c --no-tags --no-clone-bundle --optimized-fetch --retry-fetches=3; then
  52. echo "repo sync succeeded on attempt $attempt."
  53. break
  54. fi
  55. rc=$?
  56. if [ $rc -eq 124 ]; then
  57. echo "repo sync timed out after $SYNC_TIMEOUT."
  58. else
  59. echo "repo sync failed with exit code $rc."
  60. fi
  61. if [ $attempt -lt $MAX_RETRIES ]; then
  62. echo "Cleaning workspace and retrying after ${RETRY_DELAY_SHORT}s..."
  63. rm -rf .repo || true
  64. sleep $RETRY_DELAY_SHORT
  65. init_repo
  66. else
  67. echo "All $MAX_RETRIES attempts failed." >&2
  68. exit $rc
  69. fi
  70. attempt=$((attempt+1))
  71. done
  72. - name: Download manifest.xml for branch (with deprecated fallback)
  73. shell: bash
  74. if: ${{ inputs.use_repo != 'true' }}
  75. working-directory: ${{ github.workspace }}/kernel
  76. run: |
  77. set -euo pipefail
  78. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  79. MAIN_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  80. DEPRECATED_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/deprecated/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  81. echo "Trying to fetch manifest from $MAIN_MANIFEST_URL"
  82. if curl -fsSL "$MAIN_MANIFEST_URL" | base64 -d > manifest.xml; then
  83. echo "Fetched manifest from $MAIN_MANIFEST_URL"
  84. else
  85. echo "Main manifest fetch failed, trying deprecated branch."
  86. echo "⚠ Note: Branch common-${FORMATTED_BRANCH} is considered deprecated."
  87. if curl -fsSL "$DEPRECATED_MANIFEST_URL" | base64 -d > manifest.xml; then
  88. echo "Fetched manifest from $DEPRECATED_MANIFEST_URL"
  89. else
  90. echo "ERROR: Neither main nor deprecated branch exists for $FORMATTED_BRANCH" >&2
  91. exit 22
  92. fi
  93. fi
  94. - name: Debug Show manifest.xml
  95. shell: bash
  96. if: ${{ inputs.use_repo != 'true' }}
  97. working-directory: ${{ github.workspace }}/kernel
  98. run: cat manifest.xml
  99. - name: Fast Parallel Archive Download
  100. shell: bash
  101. if: ${{ inputs.use_repo != 'true' }}
  102. working-directory: ${{ github.workspace }}/kernel
  103. run: |
  104. python "${{ github.workspace }}/.github/actions/download-kernel/fast_parallel_download.py"