Update .gitea/workflows/ci.yml
This commit is contained in:
@@ -1,15 +1,3 @@
|
||||
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
|
||||
@@ -23,6 +11,11 @@ jobs:
|
||||
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"
|
||||
@@ -31,46 +24,43 @@ jobs:
|
||||
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
|
||||
echo "Fetching users page $page..." >&2
|
||||
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")
|
||||
echo "Processing user: $user_login" >&2
|
||||
|
||||
repos_json=$(curl --retry 3 --retry-delay 5 -sSL \
|
||||
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
||||
"$GITEA_API/users/$user_login/repos?_ts=$(date +%s)")
|
||||
|
||||
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
|
||||
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")
|
||||
|
||||
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=$(jq -r .content < temp_readme.json | base64 -d || echo "")
|
||||
|
||||
echo "$content" | grep -q "^---$" && \
|
||||
echo "$content" | grep -q "^gitea: none" && \
|
||||
@@ -78,24 +68,28 @@ jobs:
|
||||
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 }')
|
||||
if [ -n "$osu_id" ]; then
|
||||
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)")
|
||||
[ -z "$osu_id" ] && 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")
|
||||
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)")
|
||||
|
||||
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))
|
||||
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|<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))
|
||||
fi
|
||||
done
|
||||
done
|
||||
@@ -108,58 +102,35 @@ jobs:
|
||||
echo "total_valid_entries=$total_valid_entries" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Update README with user skins
|
||||
id: update_readme
|
||||
run: |
|
||||
user_rows_file="${{ steps.find_skins.outputs.user_rows_file }}"
|
||||
avatar_rows_file="${{ steps.find_skins.outputs.avatar_rows_file }}"
|
||||
README_PATH="README.md" # Assuming README.md is in the root of the repository
|
||||
total_valid_entries="${{ steps.find_skins.outputs.total_valid_entries }}"
|
||||
README_PATH="README.md"
|
||||
|
||||
if [ "$total_valid_entries" -eq 0 ]; then
|
||||
echo "No valid entries found – skipping README update"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cp "$README_PATH" "${README_PATH}.bak"
|
||||
|
||||
# Use `cat >` for the initial content, no indentation inside the heredoc
|
||||
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 "$user_rows_file" | cut -d'|' -f2- | sed 's/^/ /' >> "$README_PATH"
|
||||
# (append sorted entries to README like before)
|
||||
...
|
||||
|
||||
cat >> "$README_PATH" <<-EOF
|
||||
</tbody>
|
||||
</table>
|
||||
</details>
|
||||
# Check for change
|
||||
if cmp -s "$README_PATH" "${README_PATH}.bak"; then
|
||||
echo "README has not changed, skipping commit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
<p align="center">
|
||||
EOF
|
||||
|
||||
sort -t '|' -k1,1n "$avatar_rows_file" | cut -d'|' -f2- | sed 's/^/ /' >> "$README_PATH"
|
||||
|
||||
cat >> "$README_PATH" <<-EOF
|
||||
</p>
|
||||
EOF
|
||||
|
||||
rm -f "$user_rows_file" "$avatar_rows_file"
|
||||
echo "README updated"
|
||||
|
||||
- name: Configure Git
|
||||
run: |
|
||||
|
||||
Reference in New Issue
Block a user