action.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. 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. id: sync
  25. shell: bash
  26. working-directory: ${{ github.workspace }}/kernel
  27. run: |
  28. set -euo pipefail
  29. # Derive android and kernel from combined version when available
  30. VERSION="${{ inputs.version }}"
  31. ANDROID_PART=$(echo "$VERSION" | cut -d- -f1)
  32. KERNEL_PART=$(echo "$VERSION" | cut -d- -f2)
  33. FORMATTED_BRANCH="${ANDROID_PART}-${KERNEL_PART}-${{ inputs.os_patch_level }}"
  34. init_repo() {
  35. local depth="$1"
  36. local depth_flag=""
  37. if [ "$depth" != "0" ]; then
  38. depth_flag="--depth=${depth}"
  39. fi
  40. repo init -u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} ${depth_flag} || { echo "ERROR: repo init failed" >&2; return 1; }
  41. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH}) || { echo "ERROR: git ls-remote failed" >&2; return 1; }
  42. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  43. DEPRECATED=false
  44. if grep -q deprecated <<< "$REMOTE_BRANCH"; then
  45. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" "$DEFAULT_MANIFEST_PATH"
  46. echo "[!] Note: Branch ${FORMATTED_BRANCH} is considered deprecated."
  47. DEPRECATED=true
  48. fi
  49. echo "deprecated=$DEPRECATED" >> $GITHUB_OUTPUT
  50. }
  51. MAX_RETRIES=3
  52. RETRY_DELAY_SHORT=15
  53. SYNC_TIMEOUT="15m"
  54. attempt=1
  55. # Always shallow: the build only needs the branch tip. Deeper retries
  56. # just download more data into a strained runner (slower + more disk).
  57. DEPTHS=(1 1 1)
  58. clean_workspace() {
  59. echo "Disk before cleanup:"
  60. df -h "$PWD" | tail -n +2 || true
  61. # Remove repo metadata AND any half-checked-out project dirs from the
  62. # previous attempt. Deleting only .repo leaves stale checkouts behind
  63. # and every later sync fails with "Checking out local projects failed".
  64. find "$PWD" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
  65. echo "Disk after cleanup:"
  66. df -h "$PWD" | tail -n +2 || true
  67. }
  68. while [ $attempt -le $MAX_RETRIES ]; do
  69. CURRENT_DEPTH="${DEPTHS[$((attempt-1))]}"
  70. echo "Attempt $attempt/$MAX_RETRIES: initialize and sync kernel repository (depth=${CURRENT_DEPTH}, sync timeout $SYNC_TIMEOUT)..."
  71. df -h "$PWD" | tail -n +2 || true
  72. if init_repo "$CURRENT_DEPTH"; then
  73. # Use minimal-shallow variant: current-branch, shallow init done above, reduce files downloaded
  74. if timeout $SYNC_TIMEOUT repo sync -c --current-branch --no-clone-bundle --no-tags --jobs-checkout=4 -j4; then
  75. echo "Kernel repository initialization and sync succeeded on attempt $attempt."
  76. break
  77. else
  78. rc=$?
  79. if [ $rc -eq 124 ]; then
  80. echo "repo sync timed out after $SYNC_TIMEOUT."
  81. else
  82. echo "repo sync failed with exit code $rc."
  83. fi
  84. fi
  85. else
  86. rc=$?
  87. echo "repo init or branch preflight failed with exit code $rc."
  88. fi
  89. if [ $attempt -lt $MAX_RETRIES ]; then
  90. echo "Cleaning workspace and retrying after ${RETRY_DELAY_SHORT}s..."
  91. clean_workspace || true
  92. sleep $RETRY_DELAY_SHORT
  93. else
  94. echo "All $MAX_RETRIES attempts failed." >&2
  95. exit $rc
  96. fi
  97. attempt=$((attempt+1))
  98. done
  99. # --- Non-repo steps (commented out; we only use repo now) ---
  100. # - name: Download manifest.xml for branch (with deprecated fallback)
  101. # shell: bash
  102. # working-directory: ${{ github.workspace }}/kernel
  103. # run: |
  104. # set -euo pipefail
  105. # VERSION="${{ inputs.version }}"
  106. # ANDROID_PART=$(echo "$VERSION" | cut -d- -f1)
  107. # KERNEL_PART=$(echo "$VERSION" | cut -d- -f2)
  108. # FORMATTED_BRANCH="${ANDROID_PART}-${KERNEL_PART}-${{ inputs.os_patch_level }}"
  109. # MAIN_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  110. # DEPRECATED_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/deprecated/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  111. # echo "Trying to fetch manifest from $MAIN_MANIFEST_URL"
  112. # if curl -fsSL "$MAIN_MANIFEST_URL" | base64 -d > manifest.xml; then
  113. # echo "Fetched manifest from $MAIN_MANIFEST_URL"
  114. # else
  115. # echo "Main manifest fetch failed, trying deprecated branch."
  116. # echo "[!] Note: Branch common-${FORMATTED_BRANCH} is considered deprecated."
  117. # if curl -fsSL "$DEPRECATED_MANIFEST_URL" | base64 -d > manifest.xml; then
  118. # echo "Fetched manifest from $DEPRECATED_MANIFEST_URL"
  119. # else
  120. # echo "ERROR: Neither main nor deprecated branch exists for $FORMATTED_BRANCH" >&2
  121. # exit 22
  122. # fi
  123. # fi
  124. #
  125. # - name: Debug Show manifest.xml
  126. # shell: bash
  127. # working-directory: ${{ github.workspace }}/kernel
  128. # run: cat manifest.xml
  129. #
  130. # - name: Fast Parallel Archive Download
  131. # shell: bash
  132. # working-directory: ${{ github.workspace }}/kernel
  133. # run: |
  134. # python "${{ github.workspace }}/.github/actions/download-kernel/fast_parallel_download.py"
  135. - name: Capture Kernel Common Commit Metadata
  136. shell: bash
  137. working-directory: ${{ github.workspace }}/kernel
  138. run: |
  139. set -euo pipefail
  140. if [[ ! -d common ]]; then
  141. echo "WARNING: common folder not found; skipping commit metadata capture."
  142. exit 0
  143. fi
  144. cd common
  145. if [[ ! -d .git ]]; then
  146. echo "WARNING: common is not a git checkout; skipping commit metadata capture."
  147. exit 0
  148. fi
  149. COMMIT_DATE=$(git log -1 --format=%cI)
  150. COMMIT_MSG=$(git log -1 --format=%s)
  151. COMMIT_SHA=$(git rev-parse HEAD)
  152. echo "KERNEL_SOURCE_COMMIT=$COMMIT_SHA" >> "$GITHUB_ENV"
  153. echo "Kernel common commit date: $COMMIT_DATE"
  154. echo "Kernel common commit msg: $COMMIT_MSG"
  155. echo "Kernel common commit SHA: $COMMIT_SHA"