Update .gitea/workflows/ci.yml

This commit is contained in:
Arlind
2025-06-20 15:35:49 +02:00
parent e3dde02ab3
commit 038ee03ce8

View File

@@ -35,53 +35,41 @@ jobs:
user_rows_file=$(mktemp) user_rows_file=$(mktemp)
avatar_rows_file=$(mktemp) avatar_rows_file=$(mktemp)
echo "Fetching users page 1..." >&2 page=1
users_json=$(curl -sSL \ while :; do
-H "Authorization: token ${{ secrets.TOKEN }}" \ echo "Fetching users page $page..." >&2
-H "Cache-Control: no-cache" \ users_json=$(curl --retry 3 --retry-delay 5 -sSL \
-H "Pragma: no-cache" \
"$GITEA_API/admin/users?limit=50&page=1&_ts=$(date +%s)")
jq_type=$(echo "$users_json" | jq -r 'type' 2>/dev/null || echo "jq_error_type")
jq_length=$(echo "$users_json" | jq 'length' 2>/dev/null || echo "jq_error_length")
if [ "$jq_type" != "array" ] || [ "$jq_length" -eq 0 ]; then
echo "No users found or invalid JSON received on page 1. (Type: $jq_type, Length: $jq_length)." >&2
exit 1
fi
i=0
while [ "$i" -lt "$jq_length" ]; do
user_login=$(echo "$users_json" | jq -r ".[$i].login")
echo "Processing user: $user_login" >&2
repos_json=$(curl -sSL \
-H "Authorization: token ${{ secrets.TOKEN }}" \ -H "Authorization: token ${{ secrets.TOKEN }}" \
-H "Cache-Control: no-cache" \ "$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)")
-H "Pragma: no-cache" \
"$GITEA_API/users/$user_login/repos?_ts=$(date +%s)")
repos_type=$(echo "$repos_json" | jq -r 'type' 2>/dev/null || echo "not_array") count=$(echo "$users_json" | jq 'length')
repos_count=$(echo "$repos_json" | jq 'length' 2>/dev/null || echo "0") [ "$count" -eq 0 ] && break
if [ "$repos_type" != "array" ] || [ "$repos_count" -eq 0 ]; then
echo " No repos or invalid JSON for $user_login" >&2
i=$((i + 1))
continue
fi
j=0 for i in $(seq 0 $((count - 1))); do
while [ "$j" -lt "$repos_count" ]; do user_login=$(echo "$users_json" | jq -r ".[$i].login")
owner=$(echo "$repos_json" | jq -r ".[$j].owner.login") echo "Processing user: $user_login" >&2
repo=$(echo "$repos_json" | jq -r ".[$j].name")
html_url=$(echo "$repos_json" | jq -r ".[$j].html_url")
echo " Checking repo: $repo" >&2 repos_json=$(curl --retry 3 --retry-delay 5 -sSL \
readme_json=$(curl -sSL \
-H "Authorization: token ${{ secrets.TOKEN }}" \ -H "Authorization: token ${{ secrets.TOKEN }}" \
-H "Cache-Control: no-cache" \ "$GITEA_API/users/$user_login/repos?_ts=$(date +%s)")
-H "Pragma: no-cache" \
"$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)" || echo "{}")
if echo "$readme_json" | jq -e '.content' >/dev/null 2>&1; then repos_type=$(echo "$repos_json" | jq -r 'type' 2>/dev/null || echo "not_array")
repos_count=$(echo "$repos_json" | jq 'length' 2>/dev/null || echo "0")
[ "$repos_type" != "array" ] || [ "$repos_count" -eq 0 ] && continue
for j in $(seq 0 $((repos_count - 1))); do
owner=$(echo "$repos_json" | jq -r ".[$j].owner.login")
repo=$(echo "$repos_json" | jq -r ".[$j].name")
html_url=$(echo "$repos_json" | jq -r ".[$j].html_url")
echo " Checking repo: $repo" >&2
http_code=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_readme.json \
-H "Authorization: token ${{ secrets.TOKEN }}" \
"$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)")
[ "$http_code" != "200" ] && continue
readme_json=$(cat temp_readme.json)
content=$(echo "$readme_json" | jq -r .content | base64 -d || echo "") content=$(echo "$readme_json" | jq -r .content | base64 -d || echo "")
echo "$content" | grep -q "^---$" && \ echo "$content" | grep -q "^---$" && \
@@ -91,28 +79,28 @@ jobs:
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
osu_id=$(echo "$content" | awk '/osuid:[ ]*[0-9]+/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }') osu_id=$(echo "$content" | awk '/osuid:[ ]*[0-9]+/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }')
if [ -n "$osu_id" ]; then if [ -n "$osu_id" ]; then
user_data=$(curl -s \ user_data=$(curl --retry 3 --retry-delay 5 -s \
-H 'Cache-Control: no-cache' \ "https://osu.ppy.sh/api/get_user?k=${{ secrets.OSUAPIV1 }}&u=$osu_id&type=id&_ts=$(date +%s)")
-H 'Pragma: no-cache' \
--compressed "https://osu.ppy.sh/api/get_user?k=${{ secrets.OSUAPIV1 }}&u=$osu_id&type=id&_ts=$(date +%s)")
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 // "-"')
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")
printf "%s| <tr><td>%s</td><td>%s</td><td>%s</td><td><a href=\"https://osu.ppy.sh/users/%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=\"https://osu.ppy.sh/users/%s\">Profile</a></td><td><a href=\"%s\">Skins</a></td></tr>\n" \
"$padded_rank" "$username" "$pp_rank" "$pp_country_rank" "$osu_id" "$html_url" >> "$user_rows_file" "$padded_rank" "$username" "$pp_rank" "$pp_country_rank" "$osu_id" "$html_url" >> "$user_rows_file"
timestamp=$(( $(date +%s) / 86400 * 86400 ))
printf "%s| <a href=\"%s\"><img src=\"https://a.ppy.sh/%s?%s\" width=175 height=175></a>\n" \ timestamp=$(( $(date +%s) / 86400 * 86400 ))
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"
total_valid_entries=$((total_valid_entries + 1)) total_valid_entries=$((total_valid_entries + 1))
fi fi
fi fi
fi done
j=$((j + 1))
done done
i=$((i + 1))
page=$((page + 1))
done done
echo "user_rows_file=$user_rows_file" >> "$GITHUB_OUTPUT" echo "user_rows_file=$user_rows_file" >> "$GITHUB_OUTPUT"
@@ -121,42 +109,51 @@ jobs:
- name: Update README with user skins - name: Update README with user skins
run: | run: |
echo "# osu! Swiss Community Skin collection" > "$README_PATH" user_rows_file="${{ steps.find_skins.outputs.user_rows_file }}"
echo "" >> "$README_PATH" avatar_rows_file="${{ steps.find_skins.outputs.avatar_rows_file }}"
echo "Welcome to the osu! Swiss Community Skin collection, this repository archives and showcases Skins osc members use." >> "$README_PATH"
echo "" >> "$README_PATH" cat <<EOF > "$README_PATH"
echo "Enjoy looking around, click file names to download the skins and click on the images to see more about the skins." >> "$README_PATH" # osu! Swiss Community Skin collection
echo "" >> "$README_PATH"
echo "## How do I add my skins here?" >> "$README_PATH" Welcome to the osu! Swiss Community Skin collection, this repository archives and showcases Skins osc members use.
echo "" >> "$README_PATH"
echo "If you're interested in adding your skins here please follow this tutorial [how-to-use](/how-to-use.md)" >> "$README_PATH" Enjoy looking around, click file names to download the skins and click on the images to see more about the skins.
echo "" >> "$README_PATH"
echo "## Skins" >> "$README_PATH" ## How do I add my skins here?
echo "" >> "$README_PATH"
echo "<details>" >> "$README_PATH" If you're interested in adding your skins here please follow this tutorial [how-to-use](/how-to-use.md)
echo " <summary>list instead of icons</summary>" >> "$README_PATH"
echo " <br>" >> "$README_PATH" ## Skins
echo " <table border=\"1\" cellpadding=\"5\" cellspacing=\"0\">" >> "$README_PATH" <details>
echo " <thead>" >> "$README_PATH" <summary>list instead of icons</summary>
echo " <tr>" >> "$README_PATH" <br>
echo " <th>Name</th>" >> "$README_PATH" <table border="1" cellpadding="5" cellspacing="0">
echo " <th>Global Rank</th>" >> "$README_PATH" <thead>
echo " <th>Country Rank</th>" >> "$README_PATH" <tr>
echo " <th>Profile</th>" >> "$README_PATH" <th>Name</th>
echo " <th>Skins</th>" >> "$README_PATH" <th>Global Rank</th>
echo " </tr>" >> "$README_PATH" <th>Country Rank</th>
echo " </thead>" >> "$README_PATH" <th>Profile</th>
echo " <tbody>" >> "$README_PATH" <th>Skins</th>
sort -t '|' -k1,1n "${{ steps.find_skins.outputs.user_rows_file }}" | cut -d'|' -f2- >> "$README_PATH" </tr>
echo " </tbody>" >> "$README_PATH" </thead>
echo " </table>" >> "$README_PATH" <tbody>
echo "</details>" >> "$README_PATH" EOF
echo "" >> "$README_PATH"
echo "<p align=\"center\">" >> "$README_PATH" sort -t '|' -k1,1n "$user_rows_file" | cut -d'|' -f2- >> "$README_PATH"
sort -t '|' -k1,1n "${{ steps.find_skins.outputs.avatar_rows_file }}" | cut -d'|' -f2- >> "$README_PATH"
cat <<EOF >> "$README_PATH"
</tbody>
</table>
</details>
<p align="center">
EOF
sort -t '|' -k1,1n "$avatar_rows_file" | cut -d'|' -f2- >> "$README_PATH"
echo "</p>" >> "$README_PATH" echo "</p>" >> "$README_PATH"
rm -f "${{ steps.find_skins.outputs.user_rows_file }}" "${{ steps.find_skins.outputs.avatar_rows_file }}"
echo "Generated skins section and updated '$README_PATH' successfully." >&2 rm -f "$user_rows_file" "$avatar_rows_file"
- name: Configure Git - name: Configure Git
run: | run: |