Files
skins/.gitea/workflows/ci.yml
Arlind 98a0711657
Some checks failed
Update Community Skins README / gather-skins (push) Successful in 9s
Update Community Skins README / generate-readme (push) Failing after 8s
Update Community Skins README / commit-readme (push) Has been skipped
Update .gitea/workflows/ci.yml
2025-06-25 13:44:54 +02:00

220 lines
7.7 KiB
YAML

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:
gather-skins:
runs-on: ubuntu-latest
container:
image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
steps:
- name: Mask Sensitive Tokens
run: |
echo "::add-mask::${{ secrets.TOKEN }}"
echo "::add-mask::${{ secrets.OSUAPIV1 }}"
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN }}
- name: Find Skin Repositories and Generate Tables
run: |
set -eo pipefail
mkdir -p data
user_rows_file=data/user_rows.txt
avatar_rows_file=data/avatar_rows.txt
total_valid_entries=0
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")
dir_code=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_dir.json \
-H "Authorization: token ${{ secrets.TOKEN }}" \
"$GITEA_API/repos/$owner/$repo/contents/Skins?_ts=$(date +%s)")
[ "$dir_code" != "200" ] && continue
readme_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)")
[ "$readme_code" != "200" ] && continue
content=$(jq -r .content < temp_readme.json | base64 -d || echo "")
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)")
[ "$(echo "$user_data" | jq 'length')" -eq 0 ] && continue
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|<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"
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"
total_valid_entries=$((total_valid_entries + 1))
done
done
page=$((page + 1))
done
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: skin-tables
path: data/
generate-readme:
needs: gather-skins
runs-on: ubuntu-latest
container:
image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
steps:
- name: Download skin data
uses: actions/download-artifact@v3
with:
name: skin-tables
path: ./data
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN }}
- name: Generate README
run: |
set -eo pipefail
README_PATH="${{ env.README_PATH }}"
cp "$README_PATH" "${README_PATH}.bak"
cat > "$README_PATH" <<-EOF
# osu! Swiss Community Skin collection
Welcome to the osu! Swiss Community Skin collection, this repository archives and showcases Skins osc members use.
Enjoy looking around, click file names to download the skins and click on the images to see more about the skins.
## How do I add my skins here?
If you're interested in adding your skins here please follow this tutorial [how-to-use](/how-to-use.md)
## Skins
<details>
<summary>list instead of icons</summary>
<br />
<table border="1" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Global Rank</th>
<th>Country Rank</th>
<th>Profile</th>
<th>Skins</th>
</tr>
</thead>
<tbody>
EOF
sort -t '|' -k1,1n data/user_rows.txt | cut -d'|' -f2- | sed 's/^/ /' >> "$README_PATH"
cat >> "$README_PATH" <<-EOF
</tbody>
</table>
</details>
<p align="center">
EOF
sort -t '|' -k1,1n data/avatar_rows.txt | cut -d'|' -f2- | sed 's/^/ /' >> "$README_PATH"
cat >> "$README_PATH" <<-EOF
</p>
EOF
if git diff --quiet "$README_PATH"; then
echo "README has not changed"
rm -f "${README_PATH}.bak"
else
echo "README updated"
rm -f "${README_PATH}.bak"
fi
- name: Upload updated README
uses: actions/upload-artifact@v3
with:
name: updated-readme
path: ${{ env.README_PATH }}
commit-readme:
needs: generate-readme
runs-on: ubuntu-latest
container:
image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
steps:
- name: Download README
uses: actions/download-artifact@v3
with:
name: updated-readme
path: .
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN }}
- 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: Commit and Push README
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"
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