action.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. MAX_RETRIES=3
  47. RETRY_DELAY_SHORT=15
  48. SYNC_TIMEOUT="15m"
  49. attempt=1
  50. while [ $attempt -le $MAX_RETRIES ]; do
  51. echo "Attempt $attempt/$MAX_RETRIES: initialize and sync kernel repository (sync timeout $SYNC_TIMEOUT)..."
  52. if init_repo; then
  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 "Kernel repository initialization and sync succeeded on attempt $attempt."
  56. break
  57. else
  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. fi
  65. else
  66. rc=$?
  67. echo "repo init or branch preflight failed with exit code $rc."
  68. fi
  69. if [ $attempt -lt $MAX_RETRIES ]; then
  70. echo "Cleaning workspace and retrying after ${RETRY_DELAY_SHORT}s..."
  71. rm -rf .repo || true
  72. sleep $RETRY_DELAY_SHORT
  73. else
  74. echo "All $MAX_RETRIES attempts failed." >&2
  75. exit $rc
  76. fi
  77. attempt=$((attempt+1))
  78. done
  79. # --- Non-repo steps (commented out; we only use repo now) ---
  80. # - name: Download manifest.xml for branch (with deprecated fallback)
  81. # shell: bash
  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. #
  105. # - name: Debug Show manifest.xml
  106. # shell: bash
  107. # working-directory: ${{ github.workspace }}/kernel
  108. # run: cat manifest.xml
  109. #
  110. # - name: Fast Parallel Archive Download
  111. # shell: bash
  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. COMMIT_SHA=$(git rev-parse HEAD)
  132. echo "KERNEL_SOURCE_COMMIT=$COMMIT_SHA" >> "$GITHUB_ENV"
  133. echo "Kernel common commit date: $COMMIT_DATE"
  134. echo "Kernel common commit msg: $COMMIT_MSG"
  135. echo "Kernel common commit SHA: $COMMIT_SHA"