Skip to content

Commit 86db6a9

Browse files
committed
Test new Repo downloader
1 parent 30f30c3 commit 86db6a9

3 files changed

Lines changed: 186 additions & 38 deletions

File tree

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ inputs:
4242
required: false
4343
type: boolean
4444
default: false
45+
github_token:
46+
description: 'GitHub Token'
47+
required: true
4548

4649
outputs:
4750
kernel_version:
@@ -298,6 +301,8 @@ runs:
298301
run: |
299302
set -euo pipefail
300303
CONFIG="$OP_MODEL"
304+
echo "Creating folder for configuration: $CONFIG"
305+
mkdir -p "$CONFIG"
301306
echo "CONFIG=$CONFIG" >> "$GITHUB_ENV"
302307
REPO="/usr/local/bin/repo"
303308
if [ ! -x "$REPO" ]; then
@@ -314,42 +319,12 @@ runs:
314319
git config --global core.fsmonitor true
315320
git config --global pack.sparse true
316321
317-
- name: Initialize and Sync Kernel Source
318-
shell: bash
319-
run: |
320-
set -euo pipefail
321-
echo "::group::Initialize kernel source"
322-
echo "Creating folder for configuration: $CONFIG"
323-
mkdir -p "$CONFIG"
324-
cd "$CONFIG"
325-
echo "Initializing and syncing kernel source..."
326-
327-
if [[ "$OP_MANIFEST" == https://* ]]; then
328-
mkdir -p .repo/manifests
329-
curl --fail --show-error --location --proto '=https' "$OP_MANIFEST" -o .repo/manifests/temp_manifest.xml
330-
"$REPO" init -u https://github.com/OnePlusOSS/kernel_manifest.git -b "oneplus/sm8650" -m temp_manifest.xml --repo-rev=v2.16 --depth=1 --no-clone-bundle --no-tags
331-
elif [[ "$OP_BRANCH" == wild/* ]]; then
332-
mkdir -p .repo/manifests
333-
cp "../manifests/$(echo "$OP_OS_VERSION" | tr '[:upper:]' '[:lower:]')/$OP_MANIFEST" .repo/manifests/temp_manifest.xml
334-
"$REPO" init -u https://github.com/OnePlusOSS/kernel_manifest.git -b "oneplus/sm8650" -m temp_manifest.xml --repo-rev=v2.16 --depth=1 --no-clone-bundle --no-tags
335-
else
336-
"$REPO" init -u https://github.com/OnePlusOSS/kernel_manifest.git -b "$OP_BRANCH" -m "$OP_MANIFEST" --repo-rev=v2.16 --depth=1 --no-clone-bundle --no-tags
337-
fi
338-
339-
"$REPO" --version
340-
success=false
341-
for i in 1 2 3; do
342-
if "$REPO" sync -c --no-clone-bundle --no-tags --optimized-fetch \
343-
-j"$(nproc --all)" --fail-fast; then
344-
success=true
345-
break
346-
fi
347-
echo "⚠️ repo sync attempt $i failed; retrying..."
348-
sleep 30
349-
done
350-
$success || { echo "::error::repo sync failed after 3 attempts"; exit 1; }
351-
echo "✅ Kernel source synced"
352-
echo "::endgroup::"
322+
- name: Sync Kernel Source
323+
id: sync-kernel-source
324+
uses: ./.github/actions/repo-downloader
325+
with:
326+
source_location: ${{ env.CONFIG }}
327+
github_token: ${{ inputs.github_token }}
353328

354329
- name: Set Dir Paths
355330
shell: bash
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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+
from concurrent.futures import ThreadPoolExecutor
39+
40+
MAX_WORKERS = (os.cpu_count() or 2) * 4
41+
TARGET_REPO = "${{ github.repository }}"
42+
43+
def sync_project(task):
44+
name, path, url, strip, rev = task
45+
if path not in ["./", "."]:
46+
os.makedirs(path, exist_ok=True)
47+
48+
headers = (
49+
"-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' "
50+
"-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' "
51+
"-H 'Accept-Encoding: gzip, deflate, br' "
52+
"-H 'Connection: keep-alive' "
53+
"--tcp-fastopen"
54+
)
55+
56+
print(f"🚀 Syncing: {name} -> {path}")
57+
start_time = time.time()
58+
print(f" [PENDING] {name}")
59+
try:
60+
if "clang" in name.lower():
61+
print(f" [CACHE] Fetching {name} from GitHub Releases...")
62+
filename = f"{rev}.tar.gz"
63+
# Download all parts matching the pattern
64+
subprocess.run(
65+
f"gh release download source-cache --repo {TARGET_REPO} --pattern '{filename}*' --clobber",
66+
shell=True, check=True, capture_output=True
67+
)
68+
69+
# Recombine if split parts exist
70+
parts = sorted(glob.glob(f"{filename}.part*"))
71+
if parts:
72+
print(f"🧩 [MERGE] Combining {len(parts)} parts for {rev}...")
73+
with open(filename, 'wb') as outfile:
74+
for part in parts:
75+
with open(part, 'rb') as infile:
76+
shutil.copyfileobj(infile, outfile)
77+
os.remove(part)
78+
79+
# Extract from the local tar.gz
80+
subprocess.run(f"tar -I pigz -x -f {filename} -C {path} {strip}", shell=True, check=True)
81+
if os.path.exists(filename):
82+
os.remove(filename)
83+
else:
84+
cmd = f"curl -LfsS {headers} --retry 5 --connect-timeout 30 '{url}' | tar -I pigz -x -C {path} {strip}"
85+
subprocess.run(cmd, shell=True, check=True)
86+
87+
duration = time.time() - start_time
88+
print(f" [SUCCESS] Synced {name} ({duration:.2f}s)")
89+
return True
90+
except subprocess.CalledProcessError as e:
91+
print(f"❌ [ERROR] Command failed for {name}: {e.cmd}")
92+
print(f" Stderr: {e.stderr.decode() if e.stderr else 'No stderr'}")
93+
return False
94+
except Exception as e:
95+
print(f" [ERROR] Failed to sync {name}")
96+
return False
97+
98+
global_start = time.time()
99+
100+
with open('manifest.xml', 'r') as f:
101+
manifest_content = f.read()
102+
103+
root = ET.fromstring(manifest_content)
104+
top_dir = os.getcwd()
105+
106+
remotes = {r.get('name'): r.get('fetch').rstrip('/') for r in root.findall('remote')}
107+
default = root.find('default')
108+
def_remote = default.get('remote') if default is not None else None
109+
def_rev = default.get('revision') if default is not None else None
110+
111+
sync_tasks = []
112+
post_process_data = []
113+
114+
for project in root.findall('project'):
115+
name = project.get('name')
116+
path = project.get('path', name)
117+
remote_name = project.get('remote', def_remote)
118+
rev = project.get('revision', def_rev)
119+
base_url = remotes.get(remote_name)
120+
121+
if not base_url: continue
122+
123+
if "github.com" in base_url:
124+
url = f"{base_url}/{name}/archive/{rev}.tar.gz"
125+
strip = "--strip-components=1"
126+
elif "googlesource.com" in base_url:
127+
url = f"{base_url}/{name}/+archive/{rev}.tar.gz"
128+
strip = ""
129+
elif "git.codelinaro.org" in base_url:
130+
url = f"{base_url}/{name}/-/archive/{rev}.tar.gz"
131+
strip = "--strip-components=1"
132+
else:
133+
continue
134+
135+
sync_tasks.append((name, path, url, strip, rev))
136+
137+
for child in project:
138+
if child.tag in ['linkfile', 'copyfile']:
139+
post_process_data.append((path, child))
140+
141+
print(f"Starting parallel sync of {len(sync_tasks)} projects...")
142+
with ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
143+
success_list = list(executor.map(sync_project, sync_tasks))
144+
145+
if not all(success_list):
146+
print("::error::One or more projects failed to sync!")
147+
exit(1)
148+
149+
print("Processing linkfiles and copyfiles...")
150+
for path, child in post_process_data:
151+
src_rel = child.get('src')
152+
dest_rel = child.get('dest')
153+
if not src_rel or not dest_rel: continue
154+
155+
src_path = os.path.join(top_dir, path, src_rel)
156+
dest_path = os.path.join(top_dir, dest_rel)
157+
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
158+
159+
if child.tag == 'linkfile':
160+
if os.path.lexists(dest_path): os.remove(dest_path)
161+
rel_target = os.path.relpath(src_path, os.path.dirname(dest_path))
162+
os.symlink(rel_target, dest_path)
163+
print(f" [Link] {dest_rel} -> {src_rel}")
164+
elif child.tag == 'copyfile':
165+
shutil.copy2(src_path, dest_path)
166+
print(f" [Copy] {dest_rel} from {src_rel}")
167+
168+
169+
total_duration = time.time() - global_start
170+
minutes = int(total_duration // 60)
171+
seconds = total_duration % 60
172+
print(f"Kernel Sync completed in {minutes}m {seconds:.2f}s")

.github/workflows/build-kernel-release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ jobs:
571571
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
572572
git curl ca-certificates build-essential clang lld flex bison \
573573
libelf-dev libssl-dev libncurses-dev zlib1g-dev liblz4-tool \
574-
libxml2-utils rsync unzip dwarves file python3 ccache jq bc dos2unix kmod libdw-dev elfutils
574+
libxml2-utils rsync unzip dwarves file python3 ccache jq bc dos2unix kmod libdw-dev elfutils pigz
575575
sudo apt-get clean
576576
echo "✅ Dependencies installed"
577577
echo "::endgroup::"
@@ -604,7 +604,7 @@ jobs:
604604
605605
- name: 🔨 Build Kernel
606606
id: build
607-
uses: ./.github/actions
607+
uses: ./.github/actions/build-kernel
608608
with:
609609
op_config_json: ${{ steps.prepare_config.outputs.config_json }}
610610
ksu_type: ${{ matrix.ksu_type }}
@@ -614,6 +614,7 @@ jobs:
614614
build_timestamp: ${{ inputs.build_timestamp }}
615615
clean: ${{ inputs.clean_build }}
616616
debug: ${{ inputs.debug }}
617+
github_token: ${{ secrets.GITHUB_TOKEN }}
617618

618619
- name: 📊 Build statistics
619620
id: build-stat

0 commit comments

Comments
 (0)