action.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. DEPTHS=(1 50 0)
  56. while [ $attempt -le $MAX_RETRIES ]; do
  57. CURRENT_DEPTH="${DEPTHS[$((attempt-1))]}"
  58. echo "Attempt $attempt/$MAX_RETRIES: initialize and sync kernel repository (depth=${CURRENT_DEPTH}, sync timeout $SYNC_TIMEOUT)..."
  59. if init_repo "$CURRENT_DEPTH"; then
  60. # Use minimal-shallow variant: current-branch, shallow init done above, reduce files downloaded
  61. if timeout $SYNC_TIMEOUT repo sync -c --current-branch --no-clone-bundle --no-tags --jobs-checkout=4 -j4; then
  62. echo "Kernel repository initialization and sync succeeded on attempt $attempt."
  63. break
  64. else
  65. rc=$?
  66. if [ $rc -eq 124 ]; then
  67. echo "repo sync timed out after $SYNC_TIMEOUT."
  68. else
  69. echo "repo sync failed with exit code $rc."
  70. fi
  71. fi
  72. else
  73. rc=$?
  74. echo "repo init or branch preflight failed with exit code $rc."
  75. fi
  76. if [ $attempt -lt $MAX_RETRIES ]; then
  77. echo "Cleaning workspace and retrying after ${RETRY_DELAY_SHORT}s..."
  78. rm -rf .repo || true
  79. sleep $RETRY_DELAY_SHORT
  80. else
  81. echo "All $MAX_RETRIES attempts failed." >&2
  82. exit $rc
  83. fi
  84. attempt=$((attempt+1))
  85. done
  86. # --- Non-repo steps (commented out; we only use repo now) ---
  87. # - name: Download manifest.xml for branch (with deprecated fallback)
  88. # shell: bash
  89. # working-directory: ${{ github.workspace }}/kernel
  90. # run: |
  91. # set -euo pipefail
  92. # VERSION="${{ inputs.version }}"
  93. # ANDROID_PART=$(echo "$VERSION" | cut -d- -f1)
  94. # KERNEL_PART=$(echo "$VERSION" | cut -d- -f2)
  95. # FORMATTED_BRANCH="${ANDROID_PART}-${KERNEL_PART}-${{ inputs.os_patch_level }}"
  96. # MAIN_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  97. # DEPRECATED_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/deprecated/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
  98. # echo "Trying to fetch manifest from $MAIN_MANIFEST_URL"
  99. # if curl -fsSL "$MAIN_MANIFEST_URL" | base64 -d > manifest.xml; then
  100. # echo "Fetched manifest from $MAIN_MANIFEST_URL"
  101. # else
  102. # echo "Main manifest fetch failed, trying deprecated branch."
  103. # echo "[!] Note: Branch common-${FORMATTED_BRANCH} is considered deprecated."
  104. # if curl -fsSL "$DEPRECATED_MANIFEST_URL" | base64 -d > manifest.xml; then
  105. # echo "Fetched manifest from $DEPRECATED_MANIFEST_URL"
  106. # else
  107. # echo "ERROR: Neither main nor deprecated branch exists for $FORMATTED_BRANCH" >&2
  108. # exit 22
  109. # fi
  110. # fi
  111. #
  112. # - name: Debug Show manifest.xml
  113. # shell: bash
  114. # working-directory: ${{ github.workspace }}/kernel
  115. # run: cat manifest.xml
  116. #
  117. # - name: Fast Parallel Archive Download
  118. # shell: bash
  119. # working-directory: ${{ github.workspace }}/kernel
  120. # run: |
  121. # python "${{ github.workspace }}/.github/actions/download-kernel/fast_parallel_download.py"
  122. - name: Capture Kernel Common Commit Metadata
  123. shell: bash
  124. working-directory: ${{ github.workspace }}/kernel
  125. run: |
  126. set -euo pipefail
  127. if [[ ! -d common ]]; then
  128. echo "WARNING: common folder not found; skipping commit metadata capture."
  129. exit 0
  130. fi
  131. cd common
  132. if [[ ! -d .git ]]; then
  133. echo "WARNING: common is not a git checkout; skipping commit metadata capture."
  134. exit 0
  135. fi
  136. COMMIT_DATE=$(git log -1 --format=%cI)
  137. COMMIT_MSG=$(git log -1 --format=%s)
  138. COMMIT_SHA=$(git rev-parse HEAD)
  139. echo "KERNEL_SOURCE_COMMIT=$COMMIT_SHA" >> "$GITHUB_ENV"
  140. echo "Kernel common commit date: $COMMIT_DATE"
  141. echo "Kernel common commit msg: $COMMIT_MSG"
  142. echo "Kernel common commit SHA: $COMMIT_SHA"