name: Update Community Skins README on: schedule: - cron: '*/5 * * * *' workflow_dispatch: env: README_PATH: "${{ github.workspace }}/README.md" IMAGE_NAME: osc/skins-image GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1 jobs: generate_everything: name: Full CI/CD Pipeline runs-on: ubuntu-latest container: image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest steps: - name: Checkout Repository uses: actions/checkout@v4 with: token: ${{ secrets.TOKEN }} - name: Mask Sensitive Tokens run: | echo "::add-mask::${{ secrets.TOKEN }}" echo "::add-mask::${{ secrets.OSUAPIV1 }}" - name: Pull latest changes run: | git pull --rebase origin main || echo "Nothing to rebase" - name: Find Skin Repositories for all users id: find_skins shell: sh run: | set -eo pipefail total_valid_entries=0 user_rows_file=$(mktemp) avatar_rows_file=$(mktemp) page=1 while :; do users_json=$(curl --retry 3 --retry-delay 5 -sSL \ -H "Authorization: token ${{ secrets.TOKEN }}" \ "$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)") count=$(echo "$users_json" | jq 'length') [ "$count" -eq 0 ] && break for i in $(seq 0 $((count - 1))); do user_login=$(echo "$users_json" | jq -r ".[$i].login") repos_json=$(curl --retry 3 --retry-delay 5 -sSL \ -H "Authorization: token ${{ secrets.TOKEN }}" \ "$GITEA_API/users/$user_login/repos?_ts=$(date +%s)") if ! echo "$repos_json" | jq -e . >/dev/null 2>&1; then continue fi repos_count=$(echo "$repos_json" | jq 'length') [ "$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") 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 content=$(jq -r .content < temp_readme.json | base64 -d || echo "") echo "$content" | grep -q "^---$" && \ echo "$content" | grep -q "^gitea: none" && \ echo "$content" | grep -q "^include_toc: true" && \ echo "$content" | grep -q "^# Skins" if [ $? -eq 0 ]; then osu_id=$(echo "$content" | awk '/osuid:[ ]*[0-9]+/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }') [ -z "$osu_id" ] && continue user_data=$(curl --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 'length')" -eq 0 ]; then 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 # Clean up temp files rm -f "$user_rows_file" "$avatar_rows_file" # Check for differences to avoid unnecessary commit if cmp -s "$README_PATH" "${README_PATH}.bak"; then echo "README has not changed, skipping commit" exit 0 else echo "README updated" fi - name: Configure Git run: | git config user.email "arlind@sulej.ch" git config user.name "ci-bot" 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.md 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