Update .gitea/workflows/ci.yml

This commit is contained in:
2025-11-22 23:45:17 +01:00
parent ef1ebc5578
commit 34146b8a36

View File

@@ -43,129 +43,115 @@ jobs:
jq -e . >/dev/null 2>&1 jq -e . >/dev/null 2>&1
} }
curl_json() {
body=$(mktemp)
code=$(curl --retry 3 --retry-delay 5 -s -o "$body" -w "%{http_code}" "$1")
printf "%s\n%s" "$code" "$body"
}
page=1 page=1
while :; do while :; do
# Fetch user list # Fetch user list
users_response=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" \ read users_code users_body < <(curl_json "$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)")
-H "Authorization: token ${{ secrets.TOKEN }}" \ users_json=$(cat "$users_body")
"$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)")
users_code=$(printf "%s" "$users_response" | tail -c 3) if [ "$users_code" != "200" ] || ! printf "%s" "$users_json" | json_valid; then
users_json=$(printf "%s" "$users_response" | head -c -3)
if [ "$users_code" != "200" ] || ! echo "$users_json" | json_valid; then
echo "❌ Invalid users JSON on page $page (HTTP $users_code)" echo "❌ Invalid users JSON on page $page (HTTP $users_code)"
echo "$users_json" > "$ARTIFACT_PATH/invalid_users_page_${page}.json" echo "$users_json" > "$ARTIFACT_PATH/invalid_users_page_${page}.json"
break break
fi fi
count=$(echo "$users_json" | jq 'length') count=$(printf "%s" "$users_json" | jq 'length')
[ "$count" -eq 0 ] && break [ "$count" -eq 0 ] && break
echo "📄 Found $count users on page $page" echo "📄 Found $count users on page $page"
# Loop through users
for i in $(seq 0 $((count - 1))); do for i in $(seq 0 $((count - 1))); do
user_login=$(echo "$users_json" | jq -r ".[$i].login") user_login=$(printf "%s" "$users_json" | jq -r ".[$i].login")
echo "🔍 User: $user_login" echo "🔍 User: $user_login"
# Fetch repos for user # Fetch repos
repos_response=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" \ read repos_code repos_body < <(curl_json "$GITEA_API/users/$user_login/repos?_ts=$(date +%s)")
-H "Authorization: token ${{ secrets.TOKEN }}" \ repos_json=$(cat "$repos_body")
"$GITEA_API/users/$user_login/repos?_ts=$(date +%s)")
repos_code=$(printf "%s" "$repos_response" | tail -c 3) if [ "$repos_code" != "200" ] || ! printf "%s" "$repos_json" | json_valid; then
repos_json=$(printf "%s" "$repos_response" | head -c -3)
if [ "$repos_code" != "200" ] || ! echo "$repos_json" | json_valid; then
echo " ❌ Invalid repo list for $user_login (HTTP $repos_code)" echo " ❌ Invalid repo list for $user_login (HTTP $repos_code)"
echo "$repos_json" > "$ARTIFACT_PATH/invalid_repos_${user_login}.json" echo "$repos_json" > "$ARTIFACT_PATH/invalid_repos_${user_login}.json"
continue continue
fi fi
repos_count=$(echo "$repos_json" | jq 'length') repos_count=$(printf "%s" "$repos_json" | jq 'length')
echo " 📦 $repos_count repos found" echo " 📦 $repos_count repos found"
[ "$repos_count" -eq 0 ] && continue [ "$repos_count" -eq 0 ] && continue
# Loop through repos
for j in $(seq 0 $((repos_count - 1))); do for j in $(seq 0 $((repos_count - 1))); do
owner=$(echo "$repos_json" | jq -r ".[$j].owner.login") owner=$(printf "%s" "$repos_json" | jq -r ".[$j].owner.login")
repo=$(echo "$repos_json" | jq -r ".[$j].name") repo=$(printf "%s" "$repos_json" | jq -r ".[$j].name")
html_url=$(echo "$repos_json" | jq -r ".[$j].html_url") html_url=$(printf "%s" "$repos_json" | jq -r ".[$j].html_url")
echo " → Repo: $owner/$repo" echo " → Repo: $owner/$repo"
# Check Skins directory # Check Skins directory
dir_response=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" \ read dir_code dir_body < <(curl_json "$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=$(printf "%s" "$dir_response" | tail -c 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
# Check README.md # Check README.md
readme_response=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" \ read readme_code readme_body < <(curl_json "$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)")
-H "Authorization: token ${{ secrets.TOKEN }}" \ readme_json=$(cat "$readme_body")
"$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)")
readme_code=$(printf "%s" "$readme_response" | tail -c 3)
readme_json=$(printf "%s" "$readme_response" | head -c -3)
if [ "$readme_code" != "200" ] || ! echo "$readme_json" | json_valid; then if [ "$readme_code" != "200" ] || ! printf "%s" "$readme_json" | json_valid; then
echo " ❌ Skipped: No README.md or invalid JSON (HTTP $readme_code)" echo " ❌ Skipped: No README.md or invalid JSON (HTTP $readme_code)"
continue continue
fi fi
# Decode README content content=$(printf "%s" "$readme_json" | jq -r .content | base64 -d 2>/dev/null || echo "")
content=$(echo "$readme_json" | jq -r .content | base64 -d 2>/dev/null || echo "")
# Extract osuid
osu_id=$(printf "%s" "$content" | grep -oE "osuid:[ ]*[0-9]+" | grep -oE "[0-9]+" | head -1) osu_id=$(printf "%s" "$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
# Fetch osu! API # Fetch osu API
osu_response=$(curl --retry 3 --retry-delay 5 -s \ read api_code api_body < <(curl_json "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)") osu_json=$(cat "$api_body")
if ! printf "%s" "$osu_response" | json_valid; then if ! printf "%s" "$osu_json" | json_valid; then
echo " ❌ Invalid osu! API JSON for $osu_id" echo " ❌ Invalid osu! API JSON for $osu_id"
printf "%s" "$osu_response" > "$ARTIFACT_PATH/invalid_osu_user_${osu_id}.json" printf "%s" "$osu_json" > "$ARTIFACT_PATH/invalid_osu_user_${osu_id}.json"
continue continue
fi fi
if [ "$(echo "$osu_response" | jq 'length')" -eq 0 ]; then if [ "$(printf "%s" "$osu_json" | jq 'length')" -eq 0 ]; then
echo " 🚫 Restricted or banned user" echo " 🚫 Restricted or banned user"
username="$owner" username="$owner"
pp_rank="RESTRICTED" pp_rank="RESTRICTED"
pp_country_rank="RESTRICTED" pp_country_rank="RESTRICTED"
padded_rank="9999999" padded_rank="9999999"
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 ))"
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" "$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"
total_valid_entries=$((total_valid_entries + 1)) total_valid_entries=$((total_valid_entries + 1))
continue continue
fi fi
# Normal account # Normal user
pp_rank=$(echo "$osu_response" | jq -r '.[0].pp_rank // "9999999"') pp_rank=$(printf "%s" "$osu_json" | jq -r '.[0].pp_rank // "9999999"')
pp_country_rank=$(echo "$osu_response" | jq -r '.[0].pp_country_rank // "-"') pp_country_rank=$(printf "%s" "$osu_json" | jq -r '.[0].pp_country_rank // "-"')
country=$(echo "$osu_response" | jq -r '.[0].country // "-"') country=$(printf "%s" "$osu_json" | jq -r '.[0].country // "-"')
username=$(echo "$osu_response" | jq -r '.[0].username // "'$owner'"') username=$(printf "%s" "$osu_json" | jq -r '.[0].username // "'$owner'"')
padded_rank=$(printf "%07d" "$pp_rank") padded_rank=$(printf "%07d" "$pp_rank")
@@ -180,7 +166,7 @@ jobs:
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"
echo " ✅ Added: $username (#$pp_rank, $cc_rank)" echo " ✅ Added: $username (#$pp_rank, $cc_rank)"
@@ -191,7 +177,6 @@ jobs:
page=$((page + 1)) page=$((page + 1))
done done
echo
echo "✅ Total valid entries found: $total_valid_entries" echo "✅ Total valid entries found: $total_valid_entries"
- id: upload-tables - id: upload-tables