Update .gitea/workflows/ci.yml
This commit is contained in:
@@ -6,17 +6,20 @@ 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:
|
||||||
generate_everything:
|
fetch_and_process_data:
|
||||||
name: Full CI/CD Pipeline
|
name: Fetch and Process Skin Data
|
||||||
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
|
||||||
|
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:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -24,13 +27,14 @@ jobs:
|
|||||||
token: ${{ secrets.TOKEN }}
|
token: ${{ secrets.TOKEN }}
|
||||||
|
|
||||||
- name: Pull latest changes
|
- name: Pull latest changes
|
||||||
run: |
|
run: git pull --rebase origin main || echo "Nothing to rebase"
|
||||||
git pull --rebase origin main || echo "Nothing to rebase"
|
|
||||||
|
|
||||||
- name: Find Skin Repositories for all users
|
- name: Generate Skin Data Files
|
||||||
id: find_skins
|
id: generate_data
|
||||||
shell: sh
|
shell: sh
|
||||||
run: |
|
run: |
|
||||||
|
set -euo pipefail # Exit on error, unset variable, or pipeline failure
|
||||||
|
|
||||||
total_valid_entries=0
|
total_valid_entries=0
|
||||||
user_rows_file=$(mktemp)
|
user_rows_file=$(mktemp)
|
||||||
avatar_rows_file=$(mktemp)
|
avatar_rows_file=$(mktemp)
|
||||||
@@ -38,53 +42,64 @@ jobs:
|
|||||||
page=1
|
page=1
|
||||||
while :; do
|
while :; do
|
||||||
echo "Fetching users page $page..." >&2
|
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 }}" \
|
-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)")
|
||||||
|
|
||||||
count=$(echo "$users_json" | jq 'length')
|
if [ "$(echo "$users_json" | jq 'length')" -eq 0 ]; then
|
||||||
[ "$count" -eq 0 ] && break
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
for i in $(seq 0 $((count - 1))); do
|
echo "$users_json" | jq -c '.[]' | while read -r user_obj; do
|
||||||
user_login=$(echo "$users_json" | jq -r ".[$i].login")
|
user_login=$(echo "$user_obj" | jq -r '.login')
|
||||||
echo "Processing user: $user_login" >&2
|
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 }}" \
|
-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")
|
if ! echo "$repos_json" | jq -e '.[0]' >/dev/null; then
|
||||||
repos_count=$(echo "$repos_json" | jq 'length' 2>/dev/null || echo "0")
|
continue
|
||||||
[ "$repos_type" != "array" ] || [ "$repos_count" -eq 0 ] && continue
|
fi
|
||||||
|
|
||||||
for j in $(seq 0 $((repos_count - 1))); do
|
echo "$repos_json" | jq -c '.[]' | while read -r repo_obj; do
|
||||||
owner=$(echo "$repos_json" | jq -r ".[$j].owner.login")
|
owner=$(echo "$repo_obj" | jq -r '.owner.login')
|
||||||
repo=$(echo "$repos_json" | jq -r ".[$j].name")
|
repo=$(echo "$repo_obj" | jq -r '.name')
|
||||||
html_url=$(echo "$repos_json" | jq -r ".[$j].html_url")
|
html_url=$(echo "$repo_obj" | jq -r '.html_url')
|
||||||
|
|
||||||
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 \
|
if ! http_code=$(curl --fail --retry 3 --retry-delay 5 -s -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)")
|
"$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)
|
if echo "$readme_content" | grep -qE "^---$" && \
|
||||||
content=$(echo "$readme_json" | jq -r .content | base64 -d || echo "")
|
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 "^---$" && \
|
osu_id=$(echo "$readme_content" | awk '/osuid:[ ]*[0-9]+/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH); exit }')
|
||||||
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 --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)")
|
"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 '.[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" \
|
||||||
@@ -95,11 +110,14 @@ 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
|
||||||
|
else
|
||||||
|
echo "README for $owner/$repo does not match required format" >&2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
page=$((page + 1))
|
page=$((page + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -107,13 +125,23 @@ jobs:
|
|||||||
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"
|
||||||
|
|
||||||
|
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
|
- name: Update README with user skins
|
||||||
run: |
|
run: |
|
||||||
user_rows_file="${{ steps.find_skins.outputs.user_rows_file }}"
|
user_rows_file="${{ needs.fetch_and_process_data.outputs.user_rows_file }}"
|
||||||
avatar_rows_file="${{ steps.find_skins.outputs.avatar_rows_file }}"
|
avatar_rows_file="${{ needs.fetch_and_process_data.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
|
||||||
|
|
||||||
@@ -165,12 +193,13 @@ jobs:
|
|||||||
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"
|
||||||
|
# Ensure this is correct for your Gitea LFS setup
|
||||||
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_PATH"
|
||||||
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
|
||||||
@@ -179,4 +208,4 @@ jobs:
|
|||||||
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
|
||||||
Reference in New Issue
Block a user