Update .gitea/workflows/ci.yml
All checks were successful
Update Community Skins README / Full CI/CD Pipeline (push) Successful in 11s

This commit is contained in:
Arlind
2025-06-09 09:49:57 +02:00
parent b7a270366b
commit ade2e05431

View File

@@ -1,157 +1,157 @@
name: Update Community Skins README name: Update Community Skins README
on: on:
schedule: schedule:
- cron: '*/5 * * * *' - cron: '*/5 * * * *'
workflow_dispatch: workflow_dispatch:
env: env:
README_PATH: "${{ github.workspace }}/README.md" README_PATH: "${{ github.workspace }}/README.md"
IMAGE_NAME: arlind/skins IMAGE_NAME: osc/skins-image
GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1 GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1
jobs: jobs:
generate_everything: generate_everything:
name: Full CI/CD Pipeline name: Full CI/CD Pipeline
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
steps: steps:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
token: ${{ secrets.TOKEN }} token: ${{ secrets.TOKEN }}
- name: Find Skin Repositories for all users - name: Find Skin Repositories for all users
id: find_skins id: find_skins
shell: sh shell: sh
run: | run: |
total_valid_entries=0 total_valid_entries=0
user_rows_file=$(mktemp) user_rows_file=$(mktemp)
avatar_rows_file=$(mktemp) avatar_rows_file=$(mktemp)
echo "Fetching users page 1..." >&2 echo "Fetching users page 1..." >&2
users_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/admin/users?limit=50&page=1") users_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/admin/users?limit=50&page=1")
jq_type=$(echo "$users_json" | jq -r 'type' 2>/dev/null || echo "jq_error_type") 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") jq_length=$(echo "$users_json" | jq 'length' 2>/dev/null || echo "jq_error_length")
if [ "$jq_type" != "array" ] || [ "$jq_length" -eq 0 ]; then 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 echo "No users found or invalid JSON received on page 1. (Type: $jq_type, Length: $jq_length)." >&2
exit 1 exit 1
fi fi
i=0 i=0
while [ "$i" -lt "$jq_length" ]; do while [ "$i" -lt "$jq_length" ]; do
user_login=$(echo "$users_json" | jq -r ".[$i].login") user_login=$(echo "$users_json" | jq -r ".[$i].login")
echo "Processing user: $user_login" >&2 echo "Processing user: $user_login" >&2
repos_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/users/$user_login/repos") repos_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/users/$user_login/repos")
repos_type=$(echo "$repos_json" | jq -r 'type' 2>/dev/null || echo "not_array") 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_count=$(echo "$repos_json" | jq 'length' 2>/dev/null || echo "0")
if [ "$repos_type" != "array" ] || [ "$repos_count" -eq 0 ]; then if [ "$repos_type" != "array" ] || [ "$repos_count" -eq 0 ]; then
echo " No repos or invalid JSON for $user_login" >&2 echo " No repos or invalid JSON for $user_login" >&2
i=$((i + 1)) i=$((i + 1))
continue continue
fi fi
j=0 j=0
while [ "$j" -lt "$repos_count" ]; do while [ "$j" -lt "$repos_count" ]; do
owner=$(echo "$repos_json" | jq -r ".[$j].owner.login") owner=$(echo "$repos_json" | jq -r ".[$j].owner.login")
repo=$(echo "$repos_json" | jq -r ".[$j].name") repo=$(echo "$repos_json" | jq -r ".[$j].name")
html_url=$(echo "$repos_json" | jq -r ".[$j].html_url") html_url=$(echo "$repos_json" | jq -r ".[$j].html_url")
echo " Checking repo: $repo" >&2 echo " Checking repo: $repo" >&2
readme_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/repos/$owner/$repo/contents/README.md" || echo "{}") readme_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/repos/$owner/$repo/contents/README.md" || echo "{}")
if echo "$readme_json" | jq -e '.content' >/dev/null 2>&1; then if echo "$readme_json" | jq -e '.content' >/dev/null 2>&1; then
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 "^---$" && \
echo "$content" | grep -q "^gitea: none" && \ echo "$content" | grep -q "^gitea: none" && \
echo "$content" | grep -q "^include_toc: true" && \ echo "$content" | grep -q "^include_toc: true" && \
echo "$content" | grep -q "^# Skins" echo "$content" | grep -q "^# Skins"
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 "https://osu.ppy.sh/api/get_user?k=${{ secrets.OSUAPIV1 }}&u=$osu_id&type=id") user_data=$(curl -s "https://osu.ppy.sh/api/get_user?k=${{ secrets.OSUAPIV1 }}&u=$osu_id&type=id")
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"
printf "%s| <a href=\"%s\"><img src=\"https://a.ppy.sh/%s\" width=175 height=175></a>\n" \ printf "%s| <a href=\"%s\"><img src=\"https://a.ppy.sh/%s\" width=175 height=175></a>\n" \
"$padded_rank" "$html_url" "$osu_id" >> "$avatar_rows_file" "$padded_rank" "$html_url" "$osu_id" >> "$avatar_rows_file"
total_valid_entries=$((total_valid_entries + 1)) total_valid_entries=$((total_valid_entries + 1))
fi fi
fi fi
fi fi
j=$((j + 1)) j=$((j + 1))
done done
i=$((i + 1)) i=$((i + 1))
done done
echo "user_rows_file=$user_rows_file" >> "$GITHUB_OUTPUT" echo "user_rows_file=$user_rows_file" >> "$GITHUB_OUTPUT"
echo "avatar_rows_file=$avatar_rows_file" >> "$GITHUB_OUTPUT" echo "avatar_rows_file=$avatar_rows_file" >> "$GITHUB_OUTPUT"
echo "total_valid_entries=$total_valid_entries" >> "$GITHUB_OUTPUT" echo "total_valid_entries=$total_valid_entries" >> "$GITHUB_OUTPUT"
- name: Update README with user skins - name: Update README with user skins
run: | run: |
echo "# osu! Swiss Community Skin collection" > "$README_PATH" echo "# osu! Swiss Community Skin collection" > "$README_PATH"
echo "" >> "$README_PATH" echo "" >> "$README_PATH"
echo "Welcome to the osu! Swiss Community Skin collection, this repository archives and showcases Skins osc members use." >> "$README_PATH" echo "Welcome to the osu! Swiss Community Skin collection, this repository archives and showcases Skins osc members use." >> "$README_PATH"
echo "" >> "$README_PATH" echo "" >> "$README_PATH"
echo "Enjoy looking around, click file names to download the skins." >> "$README_PATH" echo "Enjoy looking around, click file names to download the skins." >> "$README_PATH"
echo "" >> "$README_PATH" echo "" >> "$README_PATH"
echo "## How do I add my skins here?" >> "$README_PATH" echo "## How do I add my skins here?" >> "$README_PATH"
echo "" >> "$README_PATH" 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" echo "If you're interested in adding your skins here please follow this tutorial [how-to-use](/how-to-use.md)" >> "$README_PATH"
echo "" >> "$README_PATH" echo "" >> "$README_PATH"
echo "## Skins" >> "$README_PATH" echo "## Skins" >> "$README_PATH"
echo "" >> "$README_PATH" echo "" >> "$README_PATH"
echo "<details>" >> "$README_PATH" echo "<details>" >> "$README_PATH"
echo " <summary>list instead of icons</summary>" >> "$README_PATH" echo " <summary>list instead of icons</summary>" >> "$README_PATH"
echo " <br>" >> "$README_PATH" echo " <br>" >> "$README_PATH"
echo " <table border=\"1\" cellpadding=\"5\" cellspacing=\"0\">" >> "$README_PATH" echo " <table border=\"1\" cellpadding=\"5\" cellspacing=\"0\">" >> "$README_PATH"
echo " <thead>" >> "$README_PATH" echo " <thead>" >> "$README_PATH"
echo " <tr>" >> "$README_PATH" echo " <tr>" >> "$README_PATH"
echo " <th>Name</th>" >> "$README_PATH" echo " <th>Name</th>" >> "$README_PATH"
echo " <th>Global Rank</th>" >> "$README_PATH" echo " <th>Global Rank</th>" >> "$README_PATH"
echo " <th>Country Rank</th>" >> "$README_PATH" echo " <th>Country Rank</th>" >> "$README_PATH"
echo " <th>Profile</th>" >> "$README_PATH" echo " <th>Profile</th>" >> "$README_PATH"
echo " <th>Skins</th>" >> "$README_PATH" echo " <th>Skins</th>" >> "$README_PATH"
echo " </tr>" >> "$README_PATH" echo " </tr>" >> "$README_PATH"
echo " </thead>" >> "$README_PATH" echo " </thead>" >> "$README_PATH"
echo " <tbody>" >> "$README_PATH" echo " <tbody>" >> "$README_PATH"
sort -t '|' -k1,1n "${{ steps.find_skins.outputs.user_rows_file }}" | cut -d'|' -f2- >> "$README_PATH" sort -t '|' -k1,1n "${{ steps.find_skins.outputs.user_rows_file }}" | cut -d'|' -f2- >> "$README_PATH"
echo " </tbody>" >> "$README_PATH" echo " </tbody>" >> "$README_PATH"
echo " </table>" >> "$README_PATH" echo " </table>" >> "$README_PATH"
echo "</details>" >> "$README_PATH" echo "</details>" >> "$README_PATH"
echo "" >> "$README_PATH" echo "" >> "$README_PATH"
echo "<p align=\"center\">" >> "$README_PATH" echo "<p align=\"center\">" >> "$README_PATH"
sort -t '|' -k1,1n "${{ steps.find_skins.outputs.avatar_rows_file }}" | cut -d'|' -f2- >> "$README_PATH" sort -t '|' -k1,1n "${{ steps.find_skins.outputs.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 }}" 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 echo "Generated skins section and updated '$README_PATH' successfully." >&2
- name: Configure Git - name: Configure Git
run: | run: |
git config user.email "arlind@sulej.ch" git config user.email "arlind@sulej.ch"
git config user.name "ci-bot" git config user.name "ci-bot"
git config lfs.https://${{ vars.CONTAINER_REGISTRY }}/arlind/skins.git/info/lfs.locksverify true git config lfs.https://${{ vars.CONTAINER_REGISTRY }}/arlind/skins.git/info/lfs.locksverify true
- name: Add and Commit changes - name: Add and Commit changes
run: | run: |
git config advice.addIgnoredFile false git config advice.addIgnoredFile false
git add README.md git add README.md
git commit -m "[ci skip] push back from pipeline" -q || echo "No changes to commit" git commit -m "[ci skip] push back from pipeline" -q || echo "No changes to commit"
- name: Push changes and create tag - name: Push changes and create tag
run: | run: |
if [ "${GITHUB_REF}" = "refs/heads/main" ]; then if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
git push origin HEAD:main || echo "No changes to push" git push origin HEAD:main || echo "No changes to push"
else else
git push origin HEAD:"${GITHUB_REF_NAME}" || echo "No changes to push" git push origin HEAD:"${GITHUB_REF_NAME}" || echo "No changes to push"
fi fi