action.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. version:
  11. description: 'Combined version (e.g., android14-6.1)'
  12. required: true
  13. os_patch_level:
  14. description: 'OS patch level (e.g., 2024-01)'
  15. required: true
  16. use_repo:
  17. description: 'Use repo for downloading kernel source'
  18. required: false
  19. outputs:
  20. deprecated_branch:
  21. description: 'Whether the branch is deprecated'
  22. value: ${{ steps.sync.outputs.deprecated }}
  23. runs:
  24. using: composite
  25. steps:
  26. - name: Initialize and Sync Kernel Repository
  27. if: ${{ inputs.use_repo == 'true' }}
  28. id: sync
  29. shell: bash
  30. working-directory: ${{ github.workspace }}/kernel
  31. run: |
  32. set -euo pipefail
  33. # Derive android and kernel from combined version when available
  34. VERSION="${{ inputs.version }}"
  35. ANDROID_PART=$(echo "$VERSION" | cut -d- -f1)
  36. KERNEL_PART=$(echo "$VERSION" | cut -d- -f2)
  37. FORMATTED_BRANCH="${ANDROID_PART}-${KERNEL_PART}-${{ inputs.os_patch_level }}"
  38. init_repo() {
  39. repo init -u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --depth=1 || { echo "ERROR: repo init failed" >&2; return 1; }
  40. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH}) || { echo "ERROR: git ls-remote failed" >&2; return 1; }
  41. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  42. DEPRECATED=false
  43. if grep -q deprecated <<< "$REMOTE_BRANCH"; then
  44. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" "$DEFAULT_MANIFEST_PATH"
  45. echo "⚠ Note: Branch ${FORMATTED_BRANCH} is considered deprecated."
  46. DEPRECATED=true
  47. fi
  48. echo "deprecated=$DEPRECATED" >> $GITHUB_OUTPUT
  49. }
  50. init_repo || { echo "ERROR: init_repo failed" >&2; exit 1; }
  51. MAX_RETRIES=3
  52. RETRY_DELAY_SHORT=15
  53. SYNC_TIMEOUT="15m"
  54. attempt=1
  55. while [ $attempt -le $MAX_RETRIES ]; do
  56. echo "Attempt $attempt/$MAX_RETRIES: repo sync (timeout $SYNC_TIMEOUT)..."
  57. # Use minimal-shallow variant: current-branch, shallow init done above, reduce files downloaded
  58. if timeout $SYNC_TIMEOUT repo sync -c --current-branch --no-clone-bundle --no-tags --jobs-checkout=4 -j4; then
  59. echo "repo sync succeeded on attempt $attempt."
  60. break
  61. fi
  62. rc=$?
  63. if [ $rc -eq 124 ]; then
  64. echo "repo sync timed out after $SYNC_TIMEOUT."
  65. else
  66. echo "repo sync failed with exit code $rc."
  67. fi
  68. if [ $attempt -lt $MAX_RETRIES ]; then
  69. echo "Cleaning workspace and retrying after ${RETRY_DELAY_SHORT}s..."
  70. rm -rf .repo || true
  71. sleep $RETRY_DELAY_SHORT
  72. init_repo
  73. else
  74. echo "All $MAX_RETRIES attempts failed." >&2
  75. exit $rc
  76. fi
  77. attempt=$((attempt+1))
  78. done
  79. - name: Download manifest.xml for branch (with deprecated fallback)
  80. shell: bash
  81. if: ${{ inputs.use_repo != 'true' }}
  82. working-directory: ${{ github.workspace }}/kernel
  83. run: |
  84. set -euo pipefail
  85. VERSION="${{ inputs.version }}"
  86. ANDROID_PART=$(echo "$VERSION" | cut -d- -f1)
  87. KERNEL_PART=$(echo "$VERSION" | cut -d- -f2)
  88. FORMATTED_BRANCH="${ANDROID_PART}-${KERNEL_PART}-${{ inputs.os_patch_level }}"
  89. MAIN_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  90. DEPRECATED_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/deprecated/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  91. echo "Trying to fetch manifest from $MAIN_MANIFEST_URL"
  92. if curl -fsSL "$MAIN_MANIFEST_URL" | base64 -d > manifest.xml; then
  93. echo "Fetched manifest from $MAIN_MANIFEST_URL"
  94. else
  95. echo "Main manifest fetch failed, trying deprecated branch."
  96. echo "⚠ Note: Branch common-${FORMATTED_BRANCH} is considered deprecated."
  97. if curl -fsSL "$DEPRECATED_MANIFEST_URL" | base64 -d > manifest.xml; then
  98. echo "Fetched manifest from $DEPRECATED_MANIFEST_URL"
  99. else
  100. echo "ERROR: Neither main nor deprecated branch exists for $FORMATTED_BRANCH" >&2
  101. exit 22
  102. fi
  103. fi
  104. - name: Debug Show manifest.xml
  105. shell: bash
  106. if: ${{ inputs.use_repo != 'true' }}
  107. working-directory: ${{ github.workspace }}/kernel
  108. run: cat manifest.xml
  109. - name: Fast Parallel Archive Download
  110. shell: bash
  111. if: ${{ inputs.use_repo != 'true' }}
  112. working-directory: ${{ github.workspace }}/kernel
  113. run: |
  114. python "${{ github.workspace }}/.github/actions/download-kernel/fast_parallel_download.py"
  115. - name: Capture Kernel Common Commit Metadata
  116. shell: bash
  117. working-directory: ${{ github.workspace }}/kernel
  118. run: |
  119. set -euo pipefail
  120. if [[ ! -d common ]]; then
  121. echo "WARNING: common folder not found; skipping commit metadata capture."
  122. exit 0
  123. fi
  124. cd common
  125. if [[ ! -d .git ]]; then
  126. echo "WARNING: common is not a git checkout; skipping commit metadata capture."
  127. exit 0
  128. fi
  129. COMMIT_DATE=$(git log -1 --format=%cI)
  130. COMMIT_MSG=$(git log -1 --format=%s)
  131. echo "Kernel common commit date: $COMMIT_DATE"
  132. echo "Kernel common commit msg: $COMMIT_MSG"