forked from WildKernels/OnePlus_KernelSU_SUSFS
-
Notifications
You must be signed in to change notification settings - Fork 22
155 lines (133 loc) Β· 6.17 KB
/
clone-clang.yml
File metadata and controls
155 lines (133 loc) Β· 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Mirror clang to GitHub Release
permissions:
contents: write
on:
workflow_dispatch:
jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- name: Ensure Single Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create the release once. If it exists, it fails safely.
gh release create "source-cache" \
--title "Source Mirror Cache" \
--notes "Deduplicated Clang Toolchains" \
--draft \
--repo "${{ github.repository }}" || echo "Release already exists."
generate-mirror-matrix:
runs-on: ubuntu-latest
needs: prepare-release
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: π₯ Checkout Code
uses: actions/checkout@v6
- name: π Generate Mirror Matrix
id: generate-config
shell: bash
run: |
set -euo pipefail
echo "[" > all_configs.json
mapfile -t files < <(find configs/ -name "*.json")
for i in "${!files[@]}"; do
cat "${files[$i]}" >> all_configs.json
[[ $((i+1)) -lt ${#files[@]} ]] && echo "," >> all_configs.json
done
echo "]" >> all_configs.json
- name: π Resolve Unique Projects
id: set-matrix
shell: python
env:
PYTHONUNBUFFERED: "1"
run: |
import xml.etree.ElementTree as ET
import json
import os
import subprocess
import shutil
with open('all_configs.json', 'r') as f:
configs = json.load(f)
unique_clang = {}
seen_count = 0
print(f"π§ Processing {len(configs)} configurations...")
print("-" * 50)
for cfg in configs:
op_model = cfg.get('model', 'Unknown')
op_branch = cfg.get('branch', '')
op_manifest = cfg.get('manifest', '')
op_os_version = cfg.get('os_version', '').lower()
xml_file = "temp_manifest.xml"
try:
if op_manifest.startswith("https://"):
subprocess.run(f"curl -LfsS {op_manifest} -o {xml_file}", shell=True, check=True)
elif op_branch.startswith("wild/"):
shutil.copy(f"manifests/{op_os_version}/{op_manifest}", xml_file)
else:
url = f"https://raw.githubusercontent.com/OnePlusOSS/kernel_manifest/refs/heads/{op_branch}/{op_manifest}"
subprocess.run(f"curl -LfsS {url} -o {xml_file}", shell=True, check=True)
root = ET.parse(xml_file).getroot()
remotes = {r.get('name'): r.get('fetch').rstrip('/') for r in root.findall('remote')}
default = root.find('default')
def_remote = default.get('remote')
def_rev = default.get('revision')
for project in root.findall('project'):
name = project.get('name')
if "clang" in name.lower():
remote_name = project.get('remote', def_remote)
rev = project.get('revision', def_rev)
base_url = remotes.get(remote_name, "")
if rev not in unique_clang and ("git.codelinaro.org" in base_url or "googlesource.com" in base_url):
if "googlesource.com" in base_url:
dl_url = f"{base_url}/{name}/+archive/{rev}.tar.gz"
else:
dl_url = f"{base_url}/{name}/-/archive/{rev}.tar.gz"
unique_clang[rev] = {"rev": rev, "url": dl_url, "name": name}
print(f"π [{op_model}][{op_os_version}] -> New Clang found: {rev}")
else:
print(f"β»οΈ [{op_model}][{op_os_version}] -> Using existing Clang: {rev}")
except Exception as e:
print(f"β οΈ Failed to process {op_manifest}: {e}")
matrix = {"include": list(unique_clang.values())}
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"matrix={json.dumps(matrix)}\n")
print(f"β
Found {len(unique_clang)} unique projects to mirror.")
mirror-to-release:
needs: [prepare-release, generate-mirror-matrix]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.generate-mirror-matrix.outputs.matrix) }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: π Sync & Upload
run: |
TARGET_REPO="${{ github.repository }}"
REV="${{ matrix.rev }}"
FILENAME="${REV}.tar.gz"
# Check cache
HTTP_STATUS=$(curl -I -s -o /dev/null -w "%{http_code}" -L \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://github.com/${{ github.repository }}/releases/download/source-cache/${REV}.tar.gz")
if [ "$HTTP_STATUS" != "302" ] && [ "$HTTP_STATUS" != "200" ]; then
echo "π₯ Downloading Clang: ${{ matrix.name }}..."
curl -LfsS -H 'User-Agent: Mozilla/5.0' --tcp-fastopen -o "$FILENAME" "${{ matrix.url }}"
FILE_SIZE=$(stat -c%s "$FILENAME")
MAX_SIZE=2000000000 # ~1.86GB
if [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
echo "β οΈ File is > 2GB $FILE_SIZE bytes. Splitting..."
split -b 1500M "$FILENAME" "${FILENAME}.part"
for part in ${FILENAME}.part*; do
echo "π€ Uploading $part..."
gh release upload "source-cache" "$part" --clobber --repo "$TARGET_REPO"
done
else
echo "π€ Uploading single file..."
gh release upload "source-cache" "$FILENAME" --clobber --repo "$TARGET_REPO"
fi
else
echo "β
Clang revision ${{ matrix.rev }} already cached."
fi