diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..591127b --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,157 @@ +name: Update Community Skins README + +on: + schedule: + - cron: '*/5 * * * *' + workflow_dispatch: + +env: + README_PATH: "${{ github.workspace }}/README.md" + IMAGE_NAME: arlind/skins + GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1 + +jobs: + generate_everything: + name: Full CI/CD Pipeline + runs-on: ubuntu-latest + container: + image: ${{ vars.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.TOKEN }} + + - name: Find matching skin entries + id: find_skins + shell: sh + run: | + total_valid_entries=0 + user_rows_file=$(mktemp) + avatar_rows_file=$(mktemp) + + echo "Fetching users page 1..." >&2 + users_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/admin/users?limit=50&page=1") + + jq_type=$(echo "$users_json" | jq -r 'type' 2>/dev/null || echo "jq_error_type") + jq_length=$(echo "$users_json" | jq 'length' 2>/dev/null || echo "jq_error_length") + if [ "$jq_type" != "array" ] || [ "$jq_length" -eq 0 ]; then + echo "No users found or invalid JSON received on page 1. (Type: $jq_type, Length: $jq_length)." >&2 + exit 1 + fi + + i=0 + while [ "$i" -lt "$jq_length" ]; do + user_login=$(echo "$users_json" | jq -r ".[$i].login") + echo "Processing user: $user_login" >&2 + + repos_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/users/$user_login/repos") + 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") + if [ "$repos_type" != "array" ] || [ "$repos_count" -eq 0 ]; then + echo " No repos or invalid JSON for $user_login" >&2 + i=$((i + 1)) + continue + fi + + j=0 + while [ "$j" -lt "$repos_count" ]; 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 + readme_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "$GITEA_API/repos/$owner/$repo/contents/README.md" || echo "{}") + + if echo "$readme_json" | jq -e '.content' >/dev/null 2>&1; then + content=$(echo "$readme_json" | jq -r .content | base64 -d || echo "") + + 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 + user_data=$(curl -s "https://osu.ppy.sh/api/get_user?k=${{ secrets.OSUAPIV1 }}&u=$osu_id&type=id") + 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| %s%s%sProfileSkins\n" \ + "$padded_rank" "$username" "$pp_rank" "$pp_country_rank" "$osu_id" "$html_url" >> "$user_rows_file" + printf "%s| \n" \ + "$padded_rank" "$html_url" "$osu_id" >> "$avatar_rows_file" + total_valid_entries=$((total_valid_entries + 1)) + fi + fi + fi + j=$((j + 1)) + done + i=$((i + 1)) + done + + 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: | + echo "# osu! Swiss Community Skin collection" > "$README_PATH" + echo "" >> "$README_PATH" + echo "Welcome to the osu! Swiss Community Skin collection, this repository archives and showcases Skins osc members use." >> "$README_PATH" + echo "" >> "$README_PATH" + echo "Enjoy looking around, click file names to download the skins." >> "$README_PATH" + echo "" >> "$README_PATH" + echo "## How do I add my skins here?" >> "$README_PATH" + echo "" >> "$README_PATH" + echo "If you're interested in adding your skins here please follow this tutorial [how-to-use](/how-to-use.md)" >> "$README_PATH" + echo "" >> "$README_PATH" + echo "## Skins" >> "$README_PATH" + echo "" >> "$README_PATH" + echo "
" >> "$README_PATH" + echo " list instead of icons" >> "$README_PATH" + echo "
" >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + echo " " >> "$README_PATH" + sort -t '|' -k1,1n "${{ steps.find_skins.outputs.user_rows_file }}" | cut -d'|' -f2- >> "$README_PATH" + echo " " >> "$README_PATH" + echo "
NameGlobal RankCountry RankProfileSkins
" >> "$README_PATH" + echo "
" >> "$README_PATH" + echo "" >> "$README_PATH" + echo "

" >> "$README_PATH" + sort -t '|' -k1,1n "${{ steps.find_skins.outputs.avatar_rows_file }}" | cut -d'|' -f2- >> "$README_PATH" + echo "

" >> "$README_PATH" + rm -f "${{ steps.find_skins.outputs.user_rows_file }}" "${{ steps.find_skins.outputs.avatar_rows_file }}" + echo "Generated skins section and updated '$README_PATH' successfully." >&2 + + - name: Configure Git + run: | + git config user.email "arlind@sulej.ch" + git config user.name "ci-bot" + 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 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 + git push origin HEAD:main || echo "No changes to push" + else + git push origin HEAD:"${GITHUB_REF_NAME}" || echo "No changes to push" + fi diff --git a/.gitea/workflows/deploy-ci.yaml b/.gitea/workflows/deploy-ci.yaml new file mode 100644 index 0000000..f051fcd --- /dev/null +++ b/.gitea/workflows/deploy-ci.yaml @@ -0,0 +1,121 @@ +name: Sync CI from skins-template to Every User Repository + +on: + workflow_dispatch: + +env: + TEMPLATE_REPO_URL: https://${{ secrets.TOKEN }}@${{ vars.CONTAINER_REGISTRY }}/osc/skins-template.git + TEMPLATE_REL_PATH: .gitea/workflows/ci.yml + GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1 + +jobs: + sync-all: + runs-on: ubuntu-latest + container: + image: ${{ vars.CONTAINER_REGISTRY }}/arlind/skins:latest + + steps: + - name: Clone skins-template + run: | + echo "[Sync CI Started]" + git clone --quiet "${{ env.TEMPLATE_REPO_URL }}" --depth 1 template-repo + cd template-repo + git checkout --quiet HEAD -- "${{ env.TEMPLATE_REL_PATH }}" + + - name: Fetch and update every user repository + run: | + page=1 + per_page=50 + + while :; do + users_json=$( + curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" \ + "${{ env.GITEA_API }}/admin/users?limit=$per_page&page=$page" + ) + users_count=$(echo "$users_json" | jq 'length') + if [ "$users_count" -eq 0 ]; then + break + fi + + for i in $(seq 0 $((users_count - 1))); do + user_login=$(echo "$users_json" | jq -r ".[$i].login") + repos_json=$( + curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" \ + "${{ env.GITEA_API }}/users/${user_login}/repos" + ) + repo_count=$(echo "$repos_json" | jq 'length') + + for j in $(seq 0 $((repo_count - 1))); do + owner=$(echo "$repos_json" | jq -r ".[$j].owner.login") + repo=$(echo "$repos_json" | jq -r ".[$j].name") + + ( + set -e + echo "" + echo "[Processing repository: ${owner}/${repo}]" + + echo " Checking README.md content" + readme_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" \ + "${{ env.GITEA_API }}/repos/${owner}/${repo}/contents/README.md" || echo "{}") + + if ! echo "$readme_json" | jq -e '.content' >/dev/null 2>&1; then + echo " → No README.md found or inaccessible, skipping ${owner}/${repo}" + exit 0 + fi + + content=$(echo "$readme_json" | jq -r .content | base64 -d 2>/dev/null || echo "") + if ! echo "$content" | head -n 20 | grep -q "^---$"; then + echo " → Missing YAML front matter (---), skipping ${owner}/${repo}" + exit 0 + fi + if ! ( echo "$content" | grep -q "^gitea: none" \ + && echo "$content" | grep -q "^include_toc: true" \ + && echo "$content" | grep -q "^# Skins" ); then + echo " → README.md does not match required headers, skipping ${owner}/${repo}" + exit 0 + fi + + echo " ✓ README.md matches expected format; proceeding" + + echo " Cloning ${owner}/${repo}..." + tmpdir=$(mktemp -d) + git clone --quiet "https://${{ secrets.TOKEN }}@${{ vars.CONTAINER_REGISTRY }}/${owner}/${repo}.git" \ + --depth 1 "$tmpdir" + + cd "$tmpdir" + echo " Configuring commit identity" + git config user.email "arlind@sulej.ch" + git config user.name "ci-bot" + + echo " Copying CI file into .gitea/workflows/ci.yml" + mkdir -p .gitea/workflows + cp "/workspace/osc/skins/template-repo/${{ env.TEMPLATE_REL_PATH }}" \ + ".gitea/workflows/ci.yml" + git add ".gitea/workflows/ci.yml" + + echo " Checking for staged changes" + if git diff --cached --quiet; then + echo " → No changes detected, skipping update for ${owner}/${repo}" + else + echo " ✓ Changes detected" + echo " Committing update" + git commit -m "Update CI" + echo " Pushing to main branch" + git push origin HEAD:main + echo " ✓ Update pushed" + fi + + cd - >/dev/null + rm -rf "$tmpdir" + echo "[Completed ${owner}/${repo}]" + ) || { + echo "⚠ Skipping ${owner}/${repo} due to an error." + } + done + done + + page=$((page + 1)) + done + + echo "" + echo "[Sync CI Complete]" diff --git a/README.md b/README.md index dd10e31..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,30 +0,0 @@ -# osu! Swiss Community - -Welcome to the osu! Swiss Community skinhub, this repository archives and showcases lots of player-made skins. - -Enjoy looking around, click file names to download 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 - -
- list instead of icons
- Arlind
- Skellers
- marcel7
-
- -

- - - - - - - - - -

diff --git a/docs/example_variables.png b/docs/example_variables.png new file mode 100644 index 0000000..8421a27 Binary files /dev/null and b/docs/example_variables.png differ diff --git a/docs/secret1.png b/docs/secret.png similarity index 100% rename from docs/secret1.png rename to docs/secret.png diff --git a/docs/secret2.png b/docs/secret2.png deleted file mode 100644 index 7da9b75..0000000 Binary files a/docs/secret2.png and /dev/null differ diff --git a/how-to-use.md b/how-to-use.md index 14e4fd8..a284c00 100644 --- a/how-to-use.md +++ b/how-to-use.md @@ -70,15 +70,24 @@ Go to your repository's **Settings**. ![Navigate Repo Settings](/docs/navigate_repository_settings.png) -Then under **Actions** open the **Secrets** tab and add these two: +Then under **Actions** open the **Secrets** tab and add this: -| Secret Name | Secret Value | -| -------------------- | -------------------------- | -| `TOKEN` | The token you just created | -| `CONTAINER_REGISTRY` | `git.sulejmani.xyz` | +| Secret Name | Secret Value | +| ----------- | -------------------------- | +| `TOKEN` | The token you just created | -![Add Secret 1](/docs/secret1.png) -![Add Secret 2](/docs/secret2.png) +![Add Secret](/docs/secret.png) + +Then under **Actions** open the **Variables** tab and add these two: + +| Variable Name | Variable Value | +| -------------------- | ------------------- | +| `CONTAINER_REGISTRY` | `git.sulejmani.xyz` | +| `OSUID` | Your osu player id | + +So in my case my osu profile is https://osu.ppy.sh/users/13792719 and I use 13792719 + +![Example Variables](/docs/example_variables.png) --- @@ -213,7 +222,7 @@ git push ### 11. Adding your skin to https://git.sulejmani.xyz/osc/skins -After you did every step please DM @arlind on discord +After you did every step it should be in https://git.sulejmani.xyz/osc/skins after a couple minutes, if it doesn't show up please message me on Discord. ---