Skip to content

Commit c6be32f

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

4 files changed

Lines changed: 237 additions & 74 deletions

File tree

Lines changed: 12 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,13 @@ 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 }}
328+
debug: ${{ inputs.debug }}
353329

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

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ on:
3333
description: 'Enter KernelSU build json'
3434
required: true
3535
type: string
36-
default: '[{"type":"ksun","hash":"dev"}]'
36+
default: '[{"type":"ksun","hash":"551ad80473f60e052917aec08abf5323b6ab2f7c"}]'
3737
optimize_level:
3838
description: "Compiler optimization level"
3939
required: true
@@ -56,23 +56,23 @@ on:
5656
android12-5_10_susfs_branch_or_commit:
5757
description: 'Enter SusFS Branch or commit hash for android12-5.10'
5858
type: string
59-
default: ''
59+
default: '674f72b6f683e837d7f557704cabe00a83eeb0b4'
6060
android13-5_15_susfs_branch_or_commit:
6161
description: 'Enter SusFS Branch or commit hash for android13-5.15'
6262
type: string
63-
default: ''
63+
default: 'eaa5d299dd85a4230f936b94dc5dd8303f27130a'
6464
android14-6_1_susfs_branch_or_commit:
6565
description: 'Enter SusFS Branch or commit hash for android14-6.1'
6666
type: string
67-
default: ''
67+
default: '971cc4e770b7f344a4df35ce92d7a859e6a1e0fd'
6868
android15-6_6_susfs_branch_or_commit:
6969
description: 'Enter SusFS Branch or commit hash for android15-6.6'
7070
type: string
71-
default: ''
71+
default: '85bcfac5edc8ba7808581e8d0a3ca9c7deca78e4'
7272
android16-6_12_susfs_branch_or_commit:
7373
description: 'Enter SusFS Branch or commit hash for android16-6.12'
7474
type: string
75-
default: ''
75+
default: '5fbf04e8c6c08b8ca759e0ac81bed7d2dc96f7f8'
7676

7777
jobs:
7878
set-op-model:
@@ -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)