| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- name: 'Download Kernel Repository'
- description: 'Initialize and sync Android kernel source repository'
- inputs:
- android_version:
- description: 'Android version (e.g., android14)'
- required: true
- kernel_version:
- description: 'Kernel version (e.g., 5.15, 6.1)'
- required: true
- version:
- description: 'Combined version (e.g., android14-6.1)'
- required: true
- os_patch_level:
- description: 'OS patch level (e.g., 2024-01)'
- required: true
- outputs:
- deprecated_branch:
- description: 'Whether the branch is deprecated'
- value: ${{ steps.sync.outputs.deprecated }}
- runs:
- using: composite
- steps:
- - name: Initialize and Sync Kernel Repository
- id: sync
- shell: bash
- working-directory: ${{ github.workspace }}/kernel
- run: |
- set -euo pipefail
- # Derive android and kernel from combined version when available
- VERSION="${{ inputs.version }}"
- ANDROID_PART=$(echo "$VERSION" | cut -d- -f1)
- KERNEL_PART=$(echo "$VERSION" | cut -d- -f2)
- FORMATTED_BRANCH="${ANDROID_PART}-${KERNEL_PART}-${{ inputs.os_patch_level }}"
- init_repo() {
- local depth="$1"
- local depth_flag=""
- if [ "$depth" != "0" ]; then
- depth_flag="--depth=${depth}"
- fi
- repo init -u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} ${depth_flag} || { echo "ERROR: repo init failed" >&2; return 1; }
- REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH}) || { echo "ERROR: git ls-remote failed" >&2; return 1; }
- DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
- DEPRECATED=false
- if grep -q deprecated <<< "$REMOTE_BRANCH"; then
- sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" "$DEFAULT_MANIFEST_PATH"
- echo "[!] Note: Branch ${FORMATTED_BRANCH} is considered deprecated."
- DEPRECATED=true
- fi
- echo "deprecated=$DEPRECATED" >> $GITHUB_OUTPUT
- }
- MAX_RETRIES=3
- RETRY_DELAY_SHORT=15
- SYNC_TIMEOUT="15m"
- attempt=1
- # Always shallow: the build only needs the branch tip. Deeper retries
- # just download more data into a strained runner (slower + more disk).
- DEPTHS=(1 1 1)
- clean_workspace() {
- echo "Disk before cleanup:"
- df -h "$PWD" | tail -n +2 || true
- # Remove repo metadata AND any half-checked-out project dirs from the
- # previous attempt. Deleting only .repo leaves stale checkouts behind
- # and every later sync fails with "Checking out local projects failed".
- find "$PWD" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
- echo "Disk after cleanup:"
- df -h "$PWD" | tail -n +2 || true
- }
- while [ $attempt -le $MAX_RETRIES ]; do
- CURRENT_DEPTH="${DEPTHS[$((attempt-1))]}"
- echo "Attempt $attempt/$MAX_RETRIES: initialize and sync kernel repository (depth=${CURRENT_DEPTH}, sync timeout $SYNC_TIMEOUT)..."
- df -h "$PWD" | tail -n +2 || true
- if init_repo "$CURRENT_DEPTH"; then
- # Use minimal-shallow variant: current-branch, shallow init done above, reduce files downloaded
- if timeout $SYNC_TIMEOUT repo sync -c --current-branch --no-clone-bundle --no-tags --jobs-checkout=4 -j4; then
- echo "Kernel repository initialization and sync succeeded on attempt $attempt."
- break
- else
- rc=$?
- if [ $rc -eq 124 ]; then
- echo "repo sync timed out after $SYNC_TIMEOUT."
- else
- echo "repo sync failed with exit code $rc."
- fi
- fi
- else
- rc=$?
- echo "repo init or branch preflight failed with exit code $rc."
- fi
- if [ $attempt -lt $MAX_RETRIES ]; then
- echo "Cleaning workspace and retrying after ${RETRY_DELAY_SHORT}s..."
- clean_workspace || true
- sleep $RETRY_DELAY_SHORT
- else
- echo "All $MAX_RETRIES attempts failed." >&2
- exit $rc
- fi
- attempt=$((attempt+1))
- done
- # --- Non-repo steps (commented out; we only use repo now) ---
- # - name: Download manifest.xml for branch (with deprecated fallback)
- # shell: bash
- # working-directory: ${{ github.workspace }}/kernel
- # run: |
- # set -euo pipefail
- # VERSION="${{ inputs.version }}"
- # ANDROID_PART=$(echo "$VERSION" | cut -d- -f1)
- # KERNEL_PART=$(echo "$VERSION" | cut -d- -f2)
- # FORMATTED_BRANCH="${ANDROID_PART}-${KERNEL_PART}-${{ inputs.os_patch_level }}"
- # MAIN_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
- # DEPRECATED_MANIFEST_URL="https://android.googlesource.com/kernel/manifest/+/refs/heads/deprecated/common-${FORMATTED_BRANCH}/default.xml?format=TEXT"
- # echo "Trying to fetch manifest from $MAIN_MANIFEST_URL"
- # if curl -fsSL "$MAIN_MANIFEST_URL" | base64 -d > manifest.xml; then
- # echo "Fetched manifest from $MAIN_MANIFEST_URL"
- # else
- # echo "Main manifest fetch failed, trying deprecated branch."
- # echo "[!] Note: Branch common-${FORMATTED_BRANCH} is considered deprecated."
- # if curl -fsSL "$DEPRECATED_MANIFEST_URL" | base64 -d > manifest.xml; then
- # echo "Fetched manifest from $DEPRECATED_MANIFEST_URL"
- # else
- # echo "ERROR: Neither main nor deprecated branch exists for $FORMATTED_BRANCH" >&2
- # exit 22
- # fi
- # fi
- #
- # - name: Debug Show manifest.xml
- # shell: bash
- # working-directory: ${{ github.workspace }}/kernel
- # run: cat manifest.xml
- #
- # - name: Fast Parallel Archive Download
- # shell: bash
- # working-directory: ${{ github.workspace }}/kernel
- # run: |
- # python "${{ github.workspace }}/.github/actions/download-kernel/fast_parallel_download.py"
- - name: Capture Kernel Common Commit Metadata
- shell: bash
- working-directory: ${{ github.workspace }}/kernel
- run: |
- set -euo pipefail
- if [[ ! -d common ]]; then
- echo "WARNING: common folder not found; skipping commit metadata capture."
- exit 0
- fi
- cd common
- if [[ ! -d .git ]]; then
- echo "WARNING: common is not a git checkout; skipping commit metadata capture."
- exit 0
- fi
- COMMIT_DATE=$(git log -1 --format=%cI)
- COMMIT_MSG=$(git log -1 --format=%s)
- COMMIT_SHA=$(git rev-parse HEAD)
- echo "KERNEL_SOURCE_COMMIT=$COMMIT_SHA" >> "$GITHUB_ENV"
- echo "Kernel common commit date: $COMMIT_DATE"
- echo "Kernel common commit msg: $COMMIT_MSG"
- echo "Kernel common commit SHA: $COMMIT_SHA"
|