|
| 1 | +name: 'Download and configure Source code' |
| 2 | + |
| 3 | +inputs: |
| 4 | + source_location: |
| 5 | + description: 'Folder path to save Kernel source' |
| 6 | + required: true |
| 7 | + type: string |
| 8 | + github_token: |
| 9 | + description: 'GitHub Token' |
| 10 | + required: true |
| 11 | + |
| 12 | +runs: |
| 13 | + using: 'composite' |
| 14 | + steps: |
| 15 | + - name: Download and Prepare Manifest |
| 16 | + shell: bash |
| 17 | + working-directory: ${{ inputs.source_location }} |
| 18 | + run: | |
| 19 | + if [[ "$OP_MANIFEST" == https://* ]]; then |
| 20 | + curl --fail --show-error --location --proto '=https' "$OP_MANIFEST" -o manifest.xml |
| 21 | + elif [[ "$OP_BRANCH" == wild/* ]]; then |
| 22 | + cp "../manifests/$(echo "$OP_OS_VERSION" | tr '[:upper:]' '[:lower:]')/$OP_MANIFEST" manifest.xml |
| 23 | + else |
| 24 | + curl --fail --show-error --location --proto '=https' "https://raw.githubusercontent.com/OnePlusOSS/kernel_manifest/refs/heads/$OP_BRANCH/$OP_MANIFEST" -o manifest.xml |
| 25 | + fi |
| 26 | +
|
| 27 | + - name: Download Manifest Archives (Parallel) |
| 28 | + shell: python |
| 29 | + env: |
| 30 | + PYTHONUNBUFFERED: "1" |
| 31 | + GITHUB_TOKEN: ${{ inputs.github_token }} |
| 32 | + working-directory: ${{ inputs.source_location }} |
| 33 | + run: | |
| 34 | + import xml.etree.ElementTree as ET |
| 35 | + import subprocess |
| 36 | + import os, shutil |
| 37 | + import time |
| 38 | + import glob |
| 39 | + from concurrent.futures import ThreadPoolExecutor |
| 40 | + |
| 41 | + MAX_WORKERS = (os.cpu_count() or 2) * 4 |
| 42 | + TARGET_REPO = "${{ github.repository }}" |
| 43 | + |
| 44 | + def sync_project(task): |
| 45 | + name, path, url, strip, rev = task |
| 46 | + if path not in ["./", "."]: |
| 47 | + os.makedirs(path, exist_ok=True) |
| 48 | + |
| 49 | + headers = ( |
| 50 | + "-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' " |
| 51 | + "-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' " |
| 52 | + "-H 'Accept-Encoding: gzip, deflate, br' " |
| 53 | + "-H 'Connection: keep-alive' " |
| 54 | + "--tcp-fastopen" |
| 55 | + ) |
| 56 | + |
| 57 | + print(f"🚀 Syncing: {name} -> {path}") |
| 58 | + start_time = time.time() |
| 59 | + print(f" [PENDING] {name}") |
| 60 | + try: |
| 61 | + if "clang" in name.lower() or "rust" in name.lower(): |
| 62 | + label = "rust" if "rust" in name.lower() else "clang" |
| 63 | + filename = f"{label}-{rev}.tar.gz" |
| 64 | + |
| 65 | + print(f" [CACHE] Fetching {label} toolchain: {filename}...") |
| 66 | + # Download all parts matching the pattern |
| 67 | + subprocess.run( |
| 68 | + f"gh release download source-cache --repo {TARGET_REPO} --pattern '{filename}*' --clobber", |
| 69 | + shell=True, check=True, capture_output=True |
| 70 | + ) |
| 71 | + |
| 72 | + # Recombine if split parts exist |
| 73 | + parts = sorted(glob.glob(f"{filename}.part*")) |
| 74 | + if parts: |
| 75 | + print(f"🧩 [MERGE] Combining {len(parts)} parts for {rev}...") |
| 76 | + with open(filename, 'wb') as outfile: |
| 77 | + for part in parts: |
| 78 | + with open(part, 'rb') as infile: |
| 79 | + shutil.copyfileobj(infile, outfile) |
| 80 | + os.remove(part) |
| 81 | + |
| 82 | + # Extract from the local tar.gz |
| 83 | + subprocess.run(f"tar -I pigz -x -f {filename} -C {path} {strip}", shell=True, check=True) |
| 84 | + if os.path.exists(filename): |
| 85 | + os.remove(filename) |
| 86 | + else: |
| 87 | + cmd = f"curl -LfsS {headers} --retry 5 --connect-timeout 30 '{url}' | tar -I pigz -x -C {path} {strip}" |
| 88 | + subprocess.run(cmd, shell=True, check=True) |
| 89 | + |
| 90 | + duration = time.time() - start_time |
| 91 | + print(f" [SUCCESS] Synced {name} ({duration:.2f}s)") |
| 92 | + return True |
| 93 | + except subprocess.CalledProcessError as e: |
| 94 | + print(f"❌ [ERROR] Command failed for {name}: {e.cmd}") |
| 95 | + print(f" Stderr: {e.stderr.decode() if e.stderr else 'No stderr'}") |
| 96 | + return False |
| 97 | + except Exception as e: |
| 98 | + print(f" [ERROR] Failed to sync {name}") |
| 99 | + return False |
| 100 | + |
| 101 | + global_start = time.time() |
| 102 | + |
| 103 | + with open('manifest.xml', 'r') as f: |
| 104 | + manifest_content = f.read() |
| 105 | + |
| 106 | + root = ET.fromstring(manifest_content) |
| 107 | + top_dir = os.getcwd() |
| 108 | + |
| 109 | + remotes = {r.get('name'): r.get('fetch').rstrip('/') for r in root.findall('remote')} |
| 110 | + default = root.find('default') |
| 111 | + def_remote = default.get('remote') if default is not None else None |
| 112 | + def_rev = default.get('revision') if default is not None else None |
| 113 | + |
| 114 | + sync_tasks = [] |
| 115 | + post_process_data = [] |
| 116 | + |
| 117 | + for project in root.findall('project'): |
| 118 | + name = project.get('name') |
| 119 | + path = project.get('path', name) |
| 120 | + remote_name = project.get('remote', def_remote) |
| 121 | + rev = project.get('revision', def_rev) |
| 122 | + base_url = remotes.get(remote_name) |
| 123 | + |
| 124 | + if not base_url: continue |
| 125 | + |
| 126 | + if "github.com" in base_url: |
| 127 | + url = f"{base_url}/{name}/archive/{rev}.tar.gz" |
| 128 | + strip = "--strip-components=1" |
| 129 | + elif "googlesource.com" in base_url: |
| 130 | + url = f"{base_url}/{name}/+archive/{rev}.tar.gz" |
| 131 | + strip = "" |
| 132 | + elif "git.codelinaro.org" in base_url: |
| 133 | + url = f"{base_url}/{name}/-/archive/{rev}.tar.gz" |
| 134 | + strip = "--strip-components=1" |
| 135 | + else: |
| 136 | + continue |
| 137 | + |
| 138 | + sync_tasks.append((name, path, url, strip, rev)) |
| 139 | + |
| 140 | + for child in project: |
| 141 | + if child.tag in ['linkfile', 'copyfile']: |
| 142 | + post_process_data.append((path, child)) |
| 143 | + |
| 144 | + print(f"Starting parallel sync of {len(sync_tasks)} projects...") |
| 145 | + with ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor: |
| 146 | + success_list = list(executor.map(sync_project, sync_tasks)) |
| 147 | + |
| 148 | + if not all(success_list): |
| 149 | + print("::error::One or more projects failed to sync!") |
| 150 | + exit(1) |
| 151 | + |
| 152 | + print("Processing linkfiles and copyfiles...") |
| 153 | + for path, child in post_process_data: |
| 154 | + src_rel = child.get('src') |
| 155 | + dest_rel = child.get('dest') |
| 156 | + if not src_rel or not dest_rel: continue |
| 157 | + |
| 158 | + src_path = os.path.join(top_dir, path, src_rel) |
| 159 | + dest_path = os.path.join(top_dir, dest_rel) |
| 160 | + os.makedirs(os.path.dirname(dest_path), exist_ok=True) |
| 161 | + |
| 162 | + if child.tag == 'linkfile': |
| 163 | + if os.path.lexists(dest_path): os.remove(dest_path) |
| 164 | + rel_target = os.path.relpath(src_path, os.path.dirname(dest_path)) |
| 165 | + os.symlink(rel_target, dest_path) |
| 166 | + print(f" [Link] {dest_rel} -> {src_rel}") |
| 167 | + elif child.tag == 'copyfile': |
| 168 | + shutil.copy2(src_path, dest_path) |
| 169 | + print(f" [Copy] {dest_rel} from {src_rel}") |
| 170 | + |
| 171 | + |
| 172 | + total_duration = time.time() - global_start |
| 173 | + minutes = int(total_duration // 60) |
| 174 | + seconds = total_duration % 60 |
| 175 | + print(f"Kernel Sync completed in {minutes}m {seconds:.2f}s") |
0 commit comments