Update .gitea/workflows/ci.yml

This commit is contained in:
Arlind
2025-06-20 15:47:18 +02:00
parent 9bd725ce86
commit 1b4a773127

View File

@@ -6,17 +6,20 @@ on:
workflow_dispatch:
env:
README_PATH: "${{ github.workspace }}/README.md"
IMAGE_NAME: osc/skins-image
GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1
README_PATH: "README.md"
jobs:
generate_everything:
name: Full CI/CD Pipeline
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
@@ -24,13 +27,14 @@ jobs:
token: ${{ secrets.TOKEN }}
- name: Pull latest changes
run: |
git pull --rebase origin main || echo "Nothing to rebase"
run: git pull --rebase origin main || echo "Nothing to rebase"
- name: Find Skin Repositories for all users
id: find_skins
- 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)
@@ -38,53 +42,64 @@ jobs:
page=1
while :; do
echo "Fetching users page $page..." >&2
users_json=$(curl --retry 3 --retry-delay 5 -sSL \
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)")
count=$(echo "$users_json" | jq 'length')
[ "$count" -eq 0 ] && break
if [ "$(echo "$users_json" | jq 'length')" -eq 0 ]; then
break
fi
for i in $(seq 0 $((count - 1))); do
user_login=$(echo "$users_json" | jq -r ".[$i].login")
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 --retry 3 --retry-delay 5 -sSL \
repos_json=$(curl --fail --retry 3 --retry-delay 5 -sSL \
-H "Authorization: token ${{ secrets.TOKEN }}" \
"$GITEA_API/users/$user_login/repos?_ts=$(date +%s)")
"$GITEA_API/users/$user_login/repos?limit=50&page=1&_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 '.[0]' >/dev/null; then
continue
fi
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 "$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
http_code=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_readme.json \
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)")
"$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
[ "$http_code" != "200" ] && continue
readme_content=$(jq -r '.content' readme_content.json | base64 -d || echo "")
rm -f readme_content.json
readme_json=$(cat temp_readme.json)
content=$(echo "$readme_json" | jq -r .content | base64 -d || echo "")
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
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 }')
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 --retry 3 --retry-delay 5 -s \
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'"')
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" \
@@ -95,11 +110,14 @@ jobs:
"$padded_rank" "$html_url" "$osu_id" "$timestamp" >> "$avatar_rows_file"
total_valid_entries=$((total_valid_entries + 1))
else
echo "osu! ID not found in README for $owner/$repo" >&2
fi
else
echo "README for $owner/$repo does not match required format" >&2
fi
done
done
page=$((page + 1))
done
@@ -107,13 +125,23 @@ jobs:
echo "avatar_rows_file=$avatar_rows_file" >> "$GITHUB_OUTPUT"
echo "total_valid_entries=$total_valid_entries" >> "$GITHUB_OUTPUT"
update_and_push_readme:
name: Update README and Push Changes
runs-on: ubuntu-latest
needs: fetch_and_process_data
container:
image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN }}
- name: Update README with user skins
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
# Use `cat >` for the initial content, no indentation inside the heredoc
user_rows_file="${{ needs.fetch_and_process_data.outputs.user_rows_file }}"
avatar_rows_file="${{ needs.fetch_and_process_data.outputs.avatar_rows_file }}"
cat > "$README_PATH" <<-EOF
# osu! Swiss Community Skin collection
@@ -165,12 +193,13 @@ jobs:
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.md
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
@@ -179,4 +208,4 @@ jobs:
git push origin HEAD:main || echo "No changes to push"
else
git push origin HEAD:"${GITHUB_REF_NAME}" || echo "No changes to push"
fi
fi