@@ -26,18 +26,31 @@ jobs:
2626 echo "Data files found:"
2727 ls -la data/projects* 2>/dev/null || echo " No data/projects* files"
2828 repos=""
29+ langs=""
2930 for f in data/projects*.yml data/projects*.yaml; do
3031 [ -f "$f" ] || continue
3132 echo "Processing: $f"
32- # Use explicit array iteration for better compatibility
3333 extracted=$(yq '[.[].repos[]] | unique | .[]' "$f" 2>&1) || true
3434 echo " Extracted: $extracted"
3535 repos="$repos"$'\n'"$extracted"
36+ # Extract language code from filename: projects.{lang}.yml -> {lang}
37+ basename="${f##*/}"
38+ name="${basename%.*}"
39+ lang="${name#projects}"
40+ if [ -n "$lang" ] && [ "$lang" != "$name" ]; then
41+ lang="${lang#.}"
42+ echo " Language: $lang"
43+ langs="$langs"$'\n'"$lang"
44+ fi
3645 done
3746 repos=$(echo "$repos" | sort -u | grep -v '^$' || true)
47+ langs=$(echo "$langs" | sort -u | grep -v '^$' || true)
3848 echo "$repos" > /tmp/repos.txt
49+ echo "$langs" > /tmp/langs.txt
3950 echo "Found repos:"
4051 cat /tmp/repos.txt
52+ echo "Found languages:"
53+ cat /tmp/langs.txt
4154 if [ -z "$repos" ]; then
4255 echo "No repos found, skipping cache update"
4356 fi
@@ -49,26 +62,19 @@ jobs:
4962 cache_file="data/caches/projects.json"
5063 mkdir -p data/caches
5164
52- # Load existing cache if present
53- if [ -f "$cache_file" ]; then
54- existing=$(cat "$cache_file")
55- else
56- existing="{}"
57- fi
58-
59- result="{}"
65+ echo "{}" > /tmp/result.json
6066 cached_count=0
6167 while IFS= read -r repo; do
6268 [ -z "$repo" ] && continue
6369 echo "Fetching: $repo"
6470
6571 # Get repo info
66- repo_json=$( gh api "repos/$repo" 2>/dev/null) || {
72+ gh api "repos/$repo" > /tmp/repo.json 2>/dev/null || {
6773 echo " Failed to fetch repo info, skipping"
6874 continue
6975 }
7076
71- # Get README content
77+ # Get default README content
7278 readme_content=""
7379 readme_html_url=""
7480 readme_json=$(gh api "repos/$repo/readme" 2>/dev/null) || true
@@ -82,49 +88,74 @@ jobs:
8288 continue
8389 fi
8490
85- echo " README length: ${#readme_content} chars"
91+ echo " Default README length: ${#readme_content} chars"
8692
87- # Write readme content to temp file to avoid shell escaping issues
93+ # Write default readme to temp file
8894 echo "$readme_content" > /tmp/readme_content.txt
8995 printf '%s' "$readme_html_url" > /tmp/readme_html_url.txt
9096
91- # Merge repo info with readme
92- entry=$(echo "$repo_json" | jq -c \
93- --rawfile readme_content /tmp/readme_content.txt \
94- --rawfile readme_html_url /tmp/readme_html_url.txt \
95- '. + {
96- readme: {
97- content: $readme_content,
98- html_url: ($readme_html_url | gsub("\n"; ""))
99- }
100- }') || true
97+ # Build readme object
98+ jq -n \
99+ --rawfile content /tmp/readme_content.txt \
100+ --rawfile html_url /tmp/readme_html_url.txt \
101+ '{ content: $content, html_url: ($html_url | gsub("\n"; "")) }' > /tmp/readme.json || true
102+
103+ # Fetch localized READMEs
104+ while IFS= read -r lang; do
105+ [ -z "$lang" ] && continue
106+ lang_readme_json=$(gh api "repos/$repo/contents/README.$lang.md" 2>/dev/null) || true
107+ if [ -n "$lang_readme_json" ]; then
108+ lang_content=$(echo "$lang_readme_json" | jq -r '.content // empty' | base64 -d 2>/dev/null) || true
109+ lang_html_url=$(echo "$lang_readme_json" | jq -r '.html_url // empty') || true
110+ if [ -n "$lang_content" ]; then
111+ echo "$lang_content" > /tmp/lang_content.txt
112+ printf '%s' "$lang_html_url" > /tmp/lang_html_url.txt
113+ jq -n \
114+ --rawfile content /tmp/lang_content.txt \
115+ --rawfile html_url /tmp/lang_html_url.txt \
116+ '{ content: $content, html_url: ($html_url | gsub("\n"; "")) }' > /tmp/lang_readme.json || true
117+ jq -c --slurpfile lang /tmp/lang_readme.json --arg lang "$lang" \
118+ '. + {($lang): $lang[0]}' /tmp/readme.json > /tmp/readme_tmp.json && mv /tmp/readme_tmp.json /tmp/readme.json || true
119+ echo " README.$lang.md found"
120+ fi
121+ fi
122+ done < /tmp/langs.txt
123+
124+ # Extract only the fields used by templates, merge with readme
125+ entry=$(jq -c \
126+ --slurpfile readme /tmp/readme.json \
127+ '{
128+ created_at, updated_at, full_name, name, html_url, homepage,
129+ description, default_branch, visibility, is_template, archived,
130+ language, topics, stargazers_count, forks_count,
131+ owner: { login: .owner.login, html_url: .owner.html_url, avatar_url: .owner.avatar_url },
132+ readme: $readme[0]
133+ } + (if .parent then { parent: { html_url: .parent.html_url, full_name: .parent.full_name } } else {} end)
134+ ' /tmp/repo.json) 2>&1 || entry=""
101135
102136 if [ -z "$entry" ] || [ "$entry" = "null" ]; then
103- echo " Failed to build entry, skipping "
137+ echo " Failed to build entry: $entry "
104138 continue
105139 fi
106140
107141 # Add to result, keyed by full_name
108- full_name=$(echo "$repo_json" | jq -r '.full_name') || true
109- # Write entry to temp file to avoid shell escaping
142+ full_name=$(echo "$entry" | jq -r '.full_name')
110143 echo "$entry" > /tmp/entry.json
111- result=$(echo "$result" | jq -c --arg key "$full_name" --slurpfile val /tmp/entry.json '. + {($key): $val[0]}') || true
144+ jq -c --arg key "$full_name" --slurpfile val /tmp/entry.json \
145+ '. + {($key): $val[0]}' /tmp/result.json > /tmp/result_tmp.json && mv /tmp/result_tmp.json /tmp/result.json || true
112146 cached_count=$((cached_count + 1))
113147 echo " Cached: $full_name"
114148 done < /tmp/repos.txt
115149
116150 echo "Total repos cached: $cached_count"
117- echo "Result keys: $(echo "$result" | jq -r 'keys | length' 2>/dev/null || echo 0)"
118-
119- # Merge with existing cache (keep entries not in current list)
120- echo "$result" > /tmp/fresh.json
121- echo "$existing" > /tmp/existing.json
122- merged=$(jq -n --slurpfile existing /tmp/existing.json --slurpfile fresh /tmp/fresh.json '$existing[0] * $fresh[0]') || true
123- if [ -n "$merged" ] && [ "$merged" != "null" ]; then
124- echo "$merged" | jq '.' > "$cache_file"
125- echo "Cache updated: $cache_file ($(echo "$merged" | jq 'keys | length') repos)"
151+ final_keys=$(jq -r 'keys | length' /tmp/result.json 2>/dev/null || echo 0)
152+ echo "Result keys: $final_keys"
153+
154+ if [ "$final_keys" -gt 0 ] 2>/dev/null; then
155+ jq '.' /tmp/result.json > "$cache_file"
156+ echo "Cache updated: $cache_file ($final_keys repos)"
126157 else
127- echo "Warning: merged result is empty , skipping write"
158+ echo "No repos cached , skipping write"
128159 fi
129160
130161 - name : Commit changes
0 commit comments