Update .gitea/workflows/ci.yml
All checks were successful
Update Community Skins README / Full CI/CD Pipeline (push) Successful in 7s
All checks were successful
Update Community Skins README / Full CI/CD Pipeline (push) Successful in 7s
This commit is contained in:
@@ -6,16 +6,17 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
README_PATH: "${{ github.workspace }}/README.md"
|
||||||
IMAGE_NAME: osc/skins-image
|
IMAGE_NAME: osc/skins-image
|
||||||
GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1
|
GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1
|
||||||
README_PATH: "README.md"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update_readme:
|
generate_everything:
|
||||||
name: Fetch Skin Data and Update README
|
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
|
||||||
@@ -23,89 +24,67 @@ jobs:
|
|||||||
token: ${{ secrets.TOKEN }}
|
token: ${{ secrets.TOKEN }}
|
||||||
|
|
||||||
- name: Pull latest changes
|
- name: Pull latest changes
|
||||||
run: git pull --rebase origin main || echo "Nothing to rebase"
|
|
||||||
|
|
||||||
- name: Generate and Update README
|
|
||||||
shell: bash
|
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
git pull --rebase origin main || echo "Nothing to rebase"
|
||||||
|
|
||||||
user_rows_file="/tmp/user_rows.txt"
|
- name: Find Skin Repositories for all users
|
||||||
avatar_rows_file="/tmp/avatar_rows.txt"
|
id: find_skins
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
total_valid_entries=0
|
total_valid_entries=0
|
||||||
|
user_rows_file=$(mktemp)
|
||||||
> "$user_rows_file"
|
avatar_rows_file=$(mktemp)
|
||||||
> "$avatar_rows_file"
|
|
||||||
|
|
||||||
page=1
|
page=1
|
||||||
users_data_found=true
|
while :; do
|
||||||
while "$users_data_found"; do
|
|
||||||
echo "Fetching users page $page..." >&2
|
echo "Fetching users page $page..." >&2
|
||||||
users_json=$(curl --fail --retry 3 --retry-delay 5 -sSL \
|
users_json=$(curl --retry 3 --retry-delay 5 -sSL \
|
||||||
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
||||||
"$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)")
|
"$GITEA_API/admin/users?limit=50&page=$page&_ts=$(date +%s)")
|
||||||
|
|
||||||
if [ "$(echo "$users_json" | jq 'length')" -eq 0 ]; then
|
count=$(echo "$users_json" | jq 'length')
|
||||||
users_data_found=false
|
[ "$count" -eq 0 ] && break
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
mapfile -t user_logins < <(echo "$users_json" | jq -r '.[].login')
|
for i in $(seq 0 $((count - 1))); do
|
||||||
|
user_login=$(echo "$users_json" | jq -r ".[$i].login")
|
||||||
for user_login in "${user_logins[@]}"; do
|
|
||||||
echo "Processing user: $user_login" >&2
|
echo "Processing user: $user_login" >&2
|
||||||
|
|
||||||
repos_json=$(curl --fail --retry 3 --retry-delay 5 -sSL \
|
repos_json=$(curl --retry 3 --retry-delay 5 -sSL \
|
||||||
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
||||||
"$GITEA_API/users/$user_login/repos?limit=50&page=1&_ts=$(date +%s)")
|
"$GITEA_API/users/$user_login/repos?_ts=$(date +%s)")
|
||||||
|
|
||||||
if ! echo "$repos_json" | jq -e '.[0]' >/dev/null; then
|
repos_type=$(echo "$repos_json" | jq -r 'type' 2>/dev/null || echo "not_array")
|
||||||
continue
|
repos_count=$(echo "$repos_json" | jq 'length' 2>/dev/null || echo "0")
|
||||||
fi
|
[ "$repos_type" != "array" ] || [ "$repos_count" -eq 0 ] && continue
|
||||||
|
|
||||||
mapfile -t repo_details < <(echo "$repos_json" | jq -r '.[] | .owner.login, .name, .html_url')
|
for j in $(seq 0 $((repos_count - 1))); do
|
||||||
|
owner=$(echo "$repos_json" | jq -r ".[$j].owner.login")
|
||||||
for ((i=0; i<${#repo_details[@]}; i+=3)); do
|
repo=$(echo "$repos_json" | jq -r ".[$j].name")
|
||||||
owner="${repo_details[i]}"
|
html_url=$(echo "$repos_json" | jq -r ".[$j].html_url")
|
||||||
repo="${repo_details[i+1]}"
|
|
||||||
html_url="${repo_details[i+2]}"
|
|
||||||
|
|
||||||
echo " Checking repo: $repo" >&2
|
echo " Checking repo: $repo" >&2
|
||||||
|
http_code=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_readme.json \
|
||||||
curl -sSL -w "%{http_code}" -o readme_content.json \
|
|
||||||
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
-H "Authorization: token ${{ secrets.TOKEN }}" \
|
||||||
"$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)" > http_code.txt
|
"$GITEA_API/repos/$owner/$repo/contents/README.md?_ts=$(date +%s)")
|
||||||
|
|
||||||
http_code=$(cat http_code.txt)
|
[ "$http_code" != "200" ] && continue
|
||||||
rm -f http_code.txt
|
|
||||||
|
|
||||||
if [ "$http_code" != "200" ]; then
|
readme_json=$(cat temp_readme.json)
|
||||||
echo "README not found for $owner/$repo (HTTP $http_code)" >&2
|
content=$(echo "$readme_json" | jq -r .content | base64 -d || echo "")
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
readme_content=$(jq -r '.content' readme_content.json | base64 -d || echo "")
|
|
||||||
rm -f readme_content.json
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
osu_id=$(echo "$readme_content" | awk '/osuid:[ ]*[0-9]+/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }')
|
|
||||||
|
|
||||||
|
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 }')
|
||||||
if [ -n "$osu_id" ]; then
|
if [ -n "$osu_id" ]; then
|
||||||
user_data=$(curl --fail --retry 3 --retry-delay 5 -s \
|
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)")
|
"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_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 --arg owner "$owner" '.[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" \
|
||||||
@@ -116,19 +95,25 @@ jobs:
|
|||||||
"$padded_rank" "$html_url" "$osu_id" "$timestamp" >> "$avatar_rows_file"
|
"$padded_rank" "$html_url" "$osu_id" "$timestamp" >> "$avatar_rows_file"
|
||||||
|
|
||||||
total_valid_entries=$((total_valid_entries + 1))
|
total_valid_entries=$((total_valid_entries + 1))
|
||||||
else
|
|
||||||
echo "osu! ID not found in README for $owner/$repo" >&2
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
else
|
|
||||||
echo "README for $owner/$repo does not match required format" >&2
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
page=$((page + 1))
|
page=$((page + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
# Create README
|
echo "user_rows_file=$user_rows_file" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "avatar_rows_file=$avatar_rows_file" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "total_valid_entries=$total_valid_entries" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- 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
|
||||||
cat > "$README_PATH" <<-EOF
|
cat > "$README_PATH" <<-EOF
|
||||||
# osu! Swiss Community Skin collection
|
# osu! Swiss Community Skin collection
|
||||||
|
|
||||||
@@ -174,20 +159,24 @@ jobs:
|
|||||||
</p>
|
</p>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
rm -f "$user_rows_file" "$avatar_rows_file"
|
||||||
|
|
||||||
- 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: Commit and Push
|
- name: Add and Commit changes
|
||||||
run: |
|
run: |
|
||||||
git config advice.addIgnoredFile false
|
git config advice.addIgnoredFile false
|
||||||
git add "$README_PATH"
|
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
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user