action.yml 5.6 KB

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