Update .gitea/workflows/ci.yml

This commit is contained in:
Arlind
2025-06-20 17:20:32 +02:00
parent cea283ecc3
commit ce6c71b4d4

View File

@@ -18,19 +18,26 @@ jobs:
image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
steps: steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN }}
- name: Mask Sensitive Tokens - name: Mask Sensitive Tokens
run: | run: |
echo "::add-mask::${{ secrets.TOKEN }}" echo "::add-mask::${{ secrets.TOKEN }}"
echo "::add-mask::${{ secrets.OSUAPIV1 }}" echo "::add-mask::${{ secrets.OSUAPIV1 }}"
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.TOKEN }}
- name: Pull latest changes - name: Pull latest changes
run: | run: |
git pull --rebase origin main || echo "Nothing to rebase" # Pull latest changes to prevent push conflicts
git remote set-url origin https://x-access-token:${{ secrets.TOKEN }}@${{ github.repository_owner }}.gitea.io/${{ github.repository }}.git
git fetch origin main
git rebase origin/main || {
echo "⚠️ Git rebase failed, likely due to conflicts."
git rebase --abort || true
exit 1
}
- name: Find Skin Repositories for all users - name: Find Skin Repositories for all users
id: find_skins id: find_skins
@@ -39,6 +46,7 @@ jobs:
total_valid_entries=0 total_valid_entries=0
user_rows_file=$(mktemp) user_rows_file=$(mktemp)
avatar_rows_file=$(mktemp) avatar_rows_file=$(mktemp)
trap 'rm -f "$user_rows_file" "$avatar_rows_file" temp_dir.json temp_readme.json' EXIT
page=1 page=1
while :; do while :; do
@@ -65,70 +73,63 @@ jobs:
continue continue
fi fi
repos_count=$(echo "$repos_json" | jq 'length') echo "$repos_json" | jq -c '.[]' | xargs -n1 -P4 -I{} bash -c '
echo " 📦 Found $repos_count repos" repo_data="{}"
owner=$(echo "$repo_data" | jq -r ".owner.login")
if [ "$repos_count" -eq 0 ]; then repo=$(echo "$repo_data" | jq -r ".name")
echo html_url=$(echo "$repo_data" | jq -r ".html_url")
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 " → Repo: $owner/$repo" echo " → Repo: $owner/$repo"
dir_code=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_dir.json \ dir_code=$(curl --connect-timeout 5 --max-time 10 --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_dir.json \
-H "Authorization: token ${{ secrets.TOKEN }}" \ -H "Authorization: token ${{ secrets.TOKEN }}" \
"$GITEA_API/repos/$owner/$repo/contents/Skins?_ts=$(date +%s)") "$GITEA_API/repos/$owner/$repo/contents/Skins?_ts=$(date +%s)")
if [ "$dir_code" != "200" ]; then if [ "$dir_code" != "200" ]; then
echo " ❌ Skipped: No 'Skins/' directory found (HTTP $dir_code)" echo " ❌ Skipped: No Skins/ dir (HTTP $dir_code)"
continue exit 0
fi fi
readme_code=$(curl --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_readme.json \ readme_code=$(curl --connect-timeout 5 --max-time 10 --retry 3 --retry-delay 5 -s -w "%{http_code}" -o temp_readme.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)")
if [ "$readme_code" != "200" ]; then if [ "$readme_code" != "200" ]; then
echo " ❌ Skipped: No README.md found to extract osuid (HTTP $readme_code)" echo " ❌ Skipped: No README.md (HTTP $readme_code)"
continue exit 0
fi fi
content=$(jq -r .content < temp_readme.json | base64 -d || echo "") content=$(jq -r .content < temp_readme.json | base64 -d || echo "")
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 [ -z "$osu_id" ]; then if [ -z "$osu_id" ]; then
echo " ❌ Skipped: osuid not found in README" echo " ❌ Skipped: no osuid"
continue exit 0
fi fi
user_data=$(curl --retry 3 --retry-delay 5 -s \ user_data=$(curl --connect-timeout 5 --max-time 10 --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 'length')" -eq 0 ]; then if [ "$(echo "$user_data" | jq length)" -eq 0 ]; then
echo " ❌ Skipped: osu! API returned no data for osuid $osu_id" echo " ❌ Skipped: osu! API no data"
continue exit 0
fi 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" \
"$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"
timestamp=$(( $(date +%s) / 86400 * 86400 )) timestamp=$(( $(date +%s) / 86400 * 86400 ))
printf "%s|<a href=\"%s\"><img src=\"https://a.ppy.sh/%s?%s\" width=175 height=175></a>\n" \ 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" "$padded_rank" "$html_url" "$osu_id" "$timestamp" >> "$avatar_rows_file"
echo " ✅ Match: $username (Rank #$pp_rank), repo contains Skins/ directory" echo " ✅ Match: $username (Rank #$pp_rank)"
total_valid_entries=$((total_valid_entries + 1)) exit 0
done '
done done
page=$((page + 1)) page=$((page + 1))
done done
@@ -150,7 +151,7 @@ jobs:
user_rows_file="${{ steps.find_skins.outputs.user_rows_file }}" user_rows_file="${{ steps.find_skins.outputs.user_rows_file }}"
avatar_rows_file="${{ steps.find_skins.outputs.avatar_rows_file }}" avatar_rows_file="${{ steps.find_skins.outputs.avatar_rows_file }}"
total_valid_entries="${{ steps.find_skins.outputs.total_valid_entries }}" total_valid_entries="${{ steps.find_skins.outputs.total_valid_entries }}"
README_PATH="README.md" README_PATH="${{ env.README_PATH }}"
if [ "$total_valid_entries" -eq 0 ]; then if [ "$total_valid_entries" -eq 0 ]; then
echo "No valid entries found, skipping README update" echo "No valid entries found, skipping README update"
@@ -204,15 +205,13 @@ jobs:
</p> </p>
EOF EOF
rm -f "$user_rows_file" "$avatar_rows_file" if git diff --quiet "$README_PATH"; then
if cmp -s "$README_PATH" "${README_PATH}.bak"; then
echo "README has not changed, skipping commit" echo "README has not changed, skipping commit"
rm -rf README.md.bak temp_dir.json temp_readme.json rm -rf "${README_PATH}.bak"
exit 0 exit 0
else else
echo "README updated" echo "README updated"
rm -rf README.md.bak temp_dir.json temp_readme.json rm -rf "${README_PATH}.bak"
fi fi
- name: Configure Git - name: Configure Git
@@ -224,7 +223,7 @@ jobs:
- 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