Skip to content

Commit 6bf1b3b

Browse files
committed
Clone clang and use it always
1 parent fa13f3e commit 6bf1b3b

1 file changed

Lines changed: 118 additions & 0 deletions

File tree

.github/workflows/clone-clang.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Mirror clang to GitHub Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
workflow_dispatch:
8+
9+
jobs:
10+
generate-mirror-matrix:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
matrix: ${{ steps.set-matrix.outputs.matrix }}
14+
steps:
15+
- name: 📥 Checkout Code
16+
uses: actions/checkout@v6
17+
18+
- name: 🔍 Generate Mirror Matrix
19+
id: generate-config
20+
shell: bash
21+
run: |
22+
set -euo pipefail
23+
24+
echo "[" > all_configs.json
25+
mapfile -t files < <(find configs/ -name "*.json")
26+
for i in "${!files[@]}"; do
27+
cat "${files[$i]}" >> all_configs.json
28+
[[ $((i+1)) -lt ${#files[@]} ]] && echo "," >> all_configs.json
29+
done
30+
echo "]" >> all_configs.json
31+
32+
- name: 🔍 Resolve Unique Projects
33+
id: set-matrix
34+
shell: python
35+
env:
36+
PYTHONUNBUFFERED: "1"
37+
run: |
38+
import xml.etree.ElementTree as ET
39+
import json
40+
import os
41+
import subprocess
42+
import shutil
43+
44+
with open('all_configs.json', 'r') as f:
45+
configs = json.load(f)
46+
47+
unique_clang = {}
48+
49+
for cfg in configs:
50+
op_branch = cfg.get('branch', '')
51+
op_manifest = cfg.get('manifest', '')
52+
op_os_version = cfg.get('os_version', '').lower()
53+
54+
xml_file = "temp_manifest.xml"
55+
56+
try:
57+
if op_manifest.startswith("https://"):
58+
subprocess.run(f"curl -LfsS {op_manifest} -o {xml_file}", shell=True, check=True)
59+
elif op_branch.startswith("wild/"):
60+
shutil.copy(f"manifests/{op_os_version}/{op_manifest}", xml_file)
61+
else:
62+
url = f"https://raw.githubusercontent.com/OnePlusOSS/kernel_manifest/refs/heads/{op_branch}/{op_manifest}"
63+
subprocess.run(f"curl -LfsS {url} -o {xml_file}", shell=True, check=True)
64+
65+
root = ET.parse(xml_file).getroot()
66+
remotes = {r.get('name'): r.get('fetch').rstrip('/') for r in root.findall('remote')}
67+
default = root.find('default')
68+
def_remote = default.get('remote')
69+
def_rev = default.get('revision')
70+
71+
for project in root.findall('project'):
72+
name = project.get('name')
73+
if "clang" in name.lower():
74+
remote_name = project.get('remote', def_remote)
75+
rev = project.get('revision', def_rev)
76+
base_url = remotes.get(remote_name, "")
77+
78+
if rev not in unique_clang and ("git.codelinaro.org" in base_url or "googlesource.com" in base_url):
79+
if "googlesource.com" in base_url:
80+
dl_url = f"{base_url}/{name}/+archive/{rev}.tar.gz"
81+
else:
82+
dl_url = f"{base_url}/{name}/-/archive/{rev}.tar.gz"
83+
unique_clang[rev] = {"rev": rev, "url": dl_url, "name": name}
84+
except Exception as e:
85+
print(f"⚠️ Failed to process {op_manifest}: {e}")
86+
matrix = {"include": list(unique_clang.values())}
87+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
88+
f.write(f"matrix={json.dumps(matrix)}\n")
89+
print(f"✅ Found {len(unique_clang)} unique projects to mirror.")
90+
91+
mirror-to-release:
92+
needs: generate-mirror-matrix
93+
runs-on: ubuntu-latest
94+
strategy:
95+
fail-fast: false
96+
matrix: ${{ fromJSON(needs.generate-mirror-matrix.outputs.matrix) }}
97+
env:
98+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
steps:
100+
- name: 🚀 Sync & Upload
101+
run: |
102+
TARGET_REPO="${{ github.repository }}"
103+
104+
gh release create "source-cache" --title "Source Mirror Cache" --draft --repo "$TARGET_REPO" 2>/dev/null || true
105+
106+
# Check cache
107+
HTTP_STATUS=$(curl -I -s -o /dev/null -w "%{http_code}" -L \
108+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
109+
"https://github.com/${{ github.repository }}/releases/download/source-cache/${{ matrix.rev }}.tar.gz")
110+
111+
if [ "$HTTP_STATUS" != "302" ] && [ "$HTTP_STATUS" != "200" ]; then
112+
echo "📥 Downloading Clang: ${{ matrix.name }}..."
113+
curl -LfsS -H 'User-Agent: Mozilla/5.0' --tcp-fastopen -o "${{ matrix.rev }}.tar.gz" "${{ matrix.url }}"
114+
echo "📤 Uploading to GitHub..."
115+
gh release upload "source-cache" "${{ matrix.rev }}.tar.gz" --clobber --repo "$TARGET_REPO"
116+
else
117+
echo "✅ Clang revision ${{ matrix.rev }} already cached."
118+
fi

0 commit comments

Comments
 (0)