Update .gitea/workflows/ci.yml

This commit is contained in:
2025-11-22 23:32:46 +01:00
parent 1fa8d729f9
commit 3c0d6f21c7

View File

@@ -36,14 +36,26 @@ jobs:
name: Find Skin Repositories and Generate Tables name: Find Skin Repositories and Generate Tables
run: | run: |
set -eo pipefail set -eo pipefail
mkdir -p "$ARTIFACT_PATH" mkdir -p "$ARTIFACT_PATH"
total_valid_entries=0 total_valid_entries=0
json_valid() {
jq -e . >/dev/null 2>&1
}
page=1 page=1
while :; do while :; do
users_json=$(curl --retry 3 --retry-delay 5 -sSL \ users_json=$(curl --retry 3 --retry-delay 5 -sSL \
-H "Authorization: token ${{ secrets.TOKEN }}" \ -H "Authorization: token ${{ secrets.TOKEN }}" \
"$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)") "$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)")
if ! echo "$users_json" | json_valid; then
echo "❌ Invalid users JSON on page $page. Skipping."
echo "$users_json" > "$ARTIFACT_PATH/invalid_users_page_$page.json"
break
fi
count=$(echo "$users_json" | jq 'length') count=$(echo "$users_json" | jq 'length')
[ "$count" -eq 0 ] && break [ "$count" -eq 0 ] && break
@@ -53,12 +65,17 @@ jobs:
user_login=$(echo "$users_json" | jq -r ".[$i].login") user_login=$(echo "$users_json" | jq -r ".[$i].login")
echo "🔍 User: $user_login" echo "🔍 User: $user_login"
repos_json=$(curl --retry 3 --retry-delay 5 -sSL \ # Fetch repos
repos_response=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" \
-H "Authorization: token ${{ secrets.TOKEN }}" \ -H "Authorization: token ${{ secrets.TOKEN }}" \
"$GITEA_API/users/$user_login/repos?_ts=$(date +%s)") "$GITEA_API/users/$user_login/repos?_ts=$(date +%s)")
if ! echo "$repos_json" | jq -e . >/dev/null 2>&1; then repos_code="${repos_response: -3}"
echo " ⚠️ Could not parse repos for $user_login" repos_json="${repos_response::-3}"
if [ "$repos_code" != "200" ] || ! echo "$repos_json" | json_valid; then
echo " ❌ Invalid repo list for $user_login (HTTP $repos_code)"
echo "$repos_json" > "$ARTIFACT_PATH/invalid_repos_${user_login}.json"
continue continue
fi fi
@@ -71,34 +88,51 @@ jobs:
owner=$(echo "$repos_json" | jq -r ".[$j].owner.login") owner=$(echo "$repos_json" | jq -r ".[$j].owner.login")
repo=$(echo "$repos_json" | jq -r ".[$j].name") repo=$(echo "$repos_json" | jq -r ".[$j].name")
html_url=$(echo "$repos_json" | jq -r ".[$j].html_url") html_url=$(echo "$repos_json" | jq -r ".[$j].html_url")
echo " → Repo: $owner/$repo" echo " → Repo: $owner/$repo"
dir_code=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_dir.json \ # Check Skins/ directory
-H "Authorization: token ${{ secrets.TOKEN }}" \ dir_response=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" \
"$GITEA_API/repos/$owner/$repo/contents/Skins?_ts=$(date +%s)") -H "Authorization: token ${{ secrets.TOKEN }}" \
"$GITEA_API/repos/$owner/$repo/contents/Skins?_ts=$(date +%s)")
dir_code="${dir_response: -3}"
if [ "$dir_code" != "200" ]; then if [ "$dir_code" != "200" ]; then
echo " ❌ Skipped: No Skins/ directory (HTTP $dir_code)" echo " ❌ Skipped: No Skins/ directory (HTTP $dir_code)"
continue continue
fi fi
readme_code=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_readme.json \ # Check README.md
-H "Authorization: token ${{ secrets.TOKEN }}" \ readme_response=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" \
"$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)") -H "Authorization: token ${{ secrets.TOKEN }}" \
if [ "$readme_code" != "200" ]; then "$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)")
echo " ❌ Skipped: No README.md (HTTP $readme_code)" readme_code="${readme_response: -3}"
readme_json="${readme_response::-3}"
if [ "$readme_code" != "200" ] || ! echo "$readme_json" | json_valid; then
echo " ❌ Skipped: No README.md or JSON invalid (HTTP $readme_code)"
continue continue
fi fi
content=$(jq -r .content < temp_readme.json | base64 -d || echo "") content=$(echo "$readme_json" | jq -r .content | base64 -d || echo "")
osu_id=$(echo "$content" | awk '/osuid:[ ]*[0-9]+/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }')
# Extract osuid
osu_id=$(echo "$content" | grep -oE "osuid:[ ]*[0-9]+" | grep -oE "[0-9]+" | head -1)
if [ -z "$osu_id" ]; then if [ -z "$osu_id" ]; then
echo " ❌ Skipped: No osuid in README" echo " ❌ Skipped: No osuid in README"
continue continue
fi fi
user_data=$(curl --retry 3 --retry-delay 5 -s \ # Fetch osu! user data
user_data=$(curl -s \
"https://osu.ppy.sh/api/get_user?k=${{ secrets.OSUAPIV1 }}&u=$osu_id&type=id&_ts=$(date +%s)") "https://osu.ppy.sh/api/get_user?k=${{ secrets.OSUAPIV1 }}&u=$osu_id&type=id&_ts=$(date +%s)")
if ! echo "$user_data" | json_valid; then
echo " ❌ Invalid osu! API response for $osu_id"
continue
fi
if [ "$(echo "$user_data" | jq 'length')" -eq 0 ]; then if [ "$(echo "$user_data" | jq 'length')" -eq 0 ]; then
echo " 🚫 Restricted or banned user" echo " 🚫 Restricted or banned user"
@@ -106,14 +140,11 @@ jobs:
pp_rank="RESTRICTED" pp_rank="RESTRICTED"
pp_country_rank="RESTRICTED" pp_country_rank="RESTRICTED"
padded_rank="9999999" padded_rank="9999999"
osu_profile_url="https://osu.ppy.sh/users/$osu_id" profile_url="https://osu.ppy.sh/users/$osu_id"
avatar_url="https://a.ppy.sh/$osu_id?$(( $(date +%s)/86400*86400 ))"
# ensure timestamp exists before using it
timestamp=$(( $(date +%s) / 86400 * 86400 ))
avatar_url="https://a.ppy.sh/$osu_id?$timestamp"
printf "%s|<tr><td>%s</td><td>%s</td><td>%s</td><td><a href=\"%s\">Profile</a></td><td><a href=\"%s\">Skins</a></td></tr>\n" \ printf "%s|<tr><td>%s</td><td>%s</td><td>%s</td><td><a href=\"%s\">Profile</a></td><td><a href=\"%s\">Skins</a></td></tr>\n" \
"$padded_rank" "$username" "$pp_rank" "$pp_country_rank" "$osu_profile_url" "$html_url" >> "$USER_ROWS_FILE" "$padded_rank" "$username" "$pp_rank" "$pp_country_rank" "$profile_url" "$html_url" >> "$USER_ROWS_FILE"
printf "%s|<a href=\"%s\"><img src=\"%s\" width=175 height=175></a>\n" \ printf "%s|<a href=\"%s\"><img src=\"%s\" width=175 height=175></a>\n" \
"$padded_rank" "$html_url" "$avatar_url" >> "$AVATAR_ROWS_FILE" "$padded_rank" "$html_url" "$avatar_url" >> "$AVATAR_ROWS_FILE"
@@ -122,19 +153,15 @@ jobs:
continue continue
fi fi
# Normal user
pp_rank=$(echo "$user_data" | jq -r '.[0].pp_rank // "9999999"') pp_rank=$(echo "$user_data" | jq -r '.[0].pp_rank // "9999999"')
pp_country_rank=$(echo "$user_data" | jq -r '.[0].pp_country_rank // "-"') pp_country_rank=$(echo "$user_data" | jq -r '.[0].pp_country_rank // "-"')
country=$(echo "$user_data" | jq -r '.[0].country // "-"') country=$(echo "$user_data" | jq -r '.[0].country // "-"')
username=$(echo "$user_data" | jq -r '.[0].username // "'$owner'"') username=$(echo "$user_data" | jq -r '.[0].username // "'$owner'"')
padded_rank=$(printf "%07d" "$pp_rank") padded_rank=$(printf "%07d" "$pp_rank")
# Build CC+rank like CH28; fall back sanely if data missing if [ "$pp_country_rank" != "-" ] && [ "$country" != "-" ]; then
if [ "$pp_country_rank" != "-" ] && [ -n "$pp_country_rank" ] && [ "$pp_country_rank" != "null" ]; then cc_rank="${country}${pp_country_rank}"
if [ "$country" != "-" ] && [ -n "$country" ] && [ "$country" != "null" ]; then
cc_rank="${country}${pp_country_rank}"
else
cc_rank="$pp_country_rank"
fi
else else
cc_rank="-" cc_rank="-"
fi fi
@@ -143,6 +170,7 @@ jobs:
"$padded_rank" "$username" "$pp_rank" "$cc_rank" "$osu_id" "$html_url" >> "$USER_ROWS_FILE" "$padded_rank" "$username" "$pp_rank" "$cc_rank" "$osu_id" "$html_url" >> "$USER_ROWS_FILE"
timestamp=$(( $(date +%s) / 86400 * 86400 )) timestamp=$(( $(date +%s) / 86400 * 86400 ))
printf "%s|<a href=\"%s\"><img src=\"https://a.ppy.sh/%s?%s\" width=175 height=175></a>\n" \ printf "%s|<a href=\"%s\"><img src=\"https://a.ppy.sh/%s?%s\" width=175 height=175></a>\n" \
"$padded_rank" "$html_url" "$osu_id" "$timestamp" >> "$AVATAR_ROWS_FILE" "$padded_rank" "$html_url" "$osu_id" "$timestamp" >> "$AVATAR_ROWS_FILE"
@@ -150,6 +178,7 @@ jobs:
total_valid_entries=$((total_valid_entries + 1)) total_valid_entries=$((total_valid_entries + 1))
done done
done done
page=$((page + 1)) page=$((page + 1))
done done