action.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 -e
  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 --partial-clone
  33. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  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
  44. MAX_RETRIES=3
  45. RETRY_DELAY_SHORT=15
  46. SYNC_TIMEOUT="10m"
  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. echo "repo sync succeeded on attempt $attempt."
  52. break
  53. fi
  54. rc=$?
  55. if [ $rc -eq 124 ]; then
  56. echo "repo sync timed out after $SYNC_TIMEOUT."
  57. else
  58. echo "repo sync failed with exit code $rc."
  59. fi
  60. if [ $attempt -lt $MAX_RETRIES ]; then
  61. echo "Cleaning workspace and retrying after ${RETRY_DELAY_SHORT}s..."
  62. rm -rf .repo || true
  63. sleep $RETRY_DELAY_SHORT
  64. init_repo
  65. else
  66. echo "All $MAX_RETRIES attempts failed." >&2
  67. exit $rc
  68. fi
  69. attempt=$((attempt+1))
  70. done
  71. - name: Download manifest.xml for branch (with deprecated fallback)
  72. shell: bash
  73. if: ${{ inputs.use_repo != 'true' }}
  74. working-directory: ${{ github.workspace }}/kernel
  75. run: |
  76. set -e
  77. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  78. MAIN_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  79. DEPRECATED_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/deprecated/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  80. echo "Trying to fetch manifest from $MAIN_MANIFEST_URL"
  81. if curl -fsSL "$MAIN_MANIFEST_URL" | base64 -d > manifest.xml; then
  82. echo "Fetched manifest from $MAIN_MANIFEST_URL"
  83. else
  84. echo "Main manifest fetch failed, trying deprecated branch."
  85. echo "⚠ Note: Branch common-${FORMATTED_BRANCH} is considered deprecated."
  86. if curl -fsSL "$DEPRECATED_MANIFEST_URL" | base64 -d > manifest.xml; then
  87. echo "Fetched manifest from $DEPRECATED_MANIFEST_URL"
  88. else
  89. echo "ERROR: Neither main nor deprecated branch exists for $FORMATTED_BRANCH" >&2
  90. exit 22
  91. fi
  92. fi
  93. - name: Debug Show manifest.xml
  94. shell: bash
  95. if: ${{ inputs.use_repo != 'true' }}
  96. working-directory: ${{ github.workspace }}/kernel
  97. run: cat manifest.xml
  98. - name: Fast Parallel Archive Download
  99. shell: bash
  100. if: ${{ inputs.use_repo != 'true' }}
  101. working-directory: ${{ github.workspace }}/kernel
  102. run: |
  103. python "${{ github.workspace }}/.github/actions/download-kernel/fast_parallel_download.py"