name: Update Community Skins README on: schedule: - cron: '*/5 * * * *' workflow_dispatch: env: IMAGE_NAME: osc/skins-image GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1 README_PATH: "README.md" jobs: fetch_and_process_data: name: Fetch and Process Skin Data runs-on: ubuntu-latest container: image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest outputs: user_rows_file: ${{ steps.generate_data.outputs.user_rows_file }} avatar_rows_file: ${{ steps.generate_data.outputs.avatar_rows_file }} total_valid_entries: ${{ steps.generate_data.outputs.total_valid_entries }} steps: - name: Checkout Repository uses: actions/checkout@v4 with: token: ${{ secrets.TOKEN }} - name: Pull latest changes run: git pull --rebase origin main || echo "Nothing to rebase" - name: Generate Skin Data Files id: generate_data shell: sh run: | set -euo pipefail # Exit on error, unset variable, or pipeline failure total_valid_entries=0 user_rows_file=$(mktemp) avatar_rows_file=$(mktemp) page=1 while :; do echo "Fetching users page $page..." >&2 users_json=$(curl --fail --retry 3 --retry-delay 5 -sSL \ -H "Authorization: token ${{ secrets.TOKEN }}" \ "$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)") if [ "$(echo "$users_json" | jq 'length')" -eq 0 ]; then break fi echo "$users_json" | jq -c '.[]' | while read -r user_obj; do user_login=$(echo "$user_obj" | jq -r '.login') echo "Processing user: $user_login" >&2 repos_json=$(curl --fail --retry 3 --retry-delay 5 -sSL \ -H "Authorization: token ${{ secrets.TOKEN }}" \ "$GITEA_API/users/$user_login/repos?limit=50&page=1&_ts=$(date +%s)") if ! echo "$repos_json" | jq -e '.[0]' >/dev/null; then continue fi echo "$repos_json" | jq -c '.[]' | while read -r repo_obj; do owner=$(echo "$repo_obj" | jq -r '.owner.login') repo=$(echo "$repo_obj" | jq -r '.name') html_url=$(echo "$repo_obj" | jq -r '.html_url') echo " Checking repo: $repo" >&2 if ! http_code=$(curl --fail --retry 3 --retry-delay 5 -s -w "%{http_code}" -o readme_content.json \ -H "Authorization: token ${{ secrets.TOKEN }}" \ "$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)"); then echo "Failed to fetch README for $owner/$repo (HTTP $http_code)" >&2 continue fi if [ "$http_code" != "200" ]; then echo "README not found for $owner/$repo (HTTP $http_code)" >&2 continue fi readme_content=$(jq -r '.content' readme_content.json | base64 -d || echo "") rm -f readme_content.json if echo "$readme_content" | grep -qE "^---$" && \ echo "$readme_content" | grep -qE "^gitea: none" && \ echo "$readme_content" | grep -qE "^include_toc: true" && \ echo "$readme_content" | grep -qE "^# Skins"; then osu_id=$(echo "$readme_content" | awk '/osuid:[ ]*[0-9]+/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }') if [ -n "$osu_id" ]; then user_data=$(curl --fail --retry 3 --retry-delay 5 -s \ "https://osu.ppy.sh/api/get_user?k=${{ secrets.OSUAPIV1 }}&u=$osu_id&type=id&_ts=$(date +%s)") if ! echo "$user_data" | jq -e '.[0]' >/dev/null; then echo "No osu! data found for ID: $osu_id" >&2 continue fi pp_rank=$(echo "$user_data" | jq -r '.[0].pp_rank // "9999999"') pp_country_rank=$(echo "$user_data" | jq -r '.[0].pp_country_rank // "-"') username=$(echo "$user_data" | jq -r '.[0].username // "'"$owner"'")' padded_rank=$(printf "%07d" "$pp_rank") printf "%s|
| Name | Global Rank | Country Rank | Profile | Skins |
|---|
EOF sort -t '|' -k1,1n "$avatar_rows_file" | cut -d'|' -f2- | sed 's/^/ /' >> "$README_PATH" cat >> "$README_PATH" <<-EOF
EOF rm -f "$user_rows_file" "$avatar_rows_file" - name: Configure Git run: | git config user.email "arlind@sulej.ch" git config user.name "ci-bot" # Ensure this is correct for your Gitea LFS setup git config lfs.https://${{ vars.CONTAINER_REGISTRY }}/arlind/skins.git/info/lfs.locksverify true - name: Add and Commit changes run: | git config advice.addIgnoredFile false git add "$README_PATH" git commit -m "[ci skip] push back from pipeline" -q || echo "No changes to commit" - name: Push changes and create tag run: | if [ "${GITHUB_REF}" = "refs/heads/main" ]; then git push origin HEAD:main || echo "No changes to push" else git push origin HEAD:"${GITHUB_REF_NAME}" || echo "No changes to push" fi