add bash as shell
All checks were successful
Update Community Skins README / Full CI/CD Pipeline (push) Successful in 3s

This commit is contained in:
2025-06-08 17:05:00 +02:00
parent 0a2ac4529b
commit 24445bb75f

View File

@@ -10,16 +10,14 @@ jobs:
image: ${{ vars.CONTAINER_REGISTRY }}/arlind/skins:latest image: ${{ vars.CONTAINER_REGISTRY }}/arlind/skins:latest
env: env:
GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1 GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1
TOKEN: ${{ secrets.TOKEN }} TOKEN: ${{ secrets.TOKEN }}
TEMPLATE_PATH: .gitea/workflows/ci.yml TEMPLATE_PATH: .gitea/workflows/ci.yml
steps: steps:
- name: Fetch CI template via Gitea API - name: Fetch CI template via Gitea API
shell: bash shell: bash
run: | run: |
resp=$(curl -sSL \ resp=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/repos/osc/skins-template/contents/$TEMPLATE_PATH?ref=main")
-H "Authorization: token $TOKEN" \
"$GITEA_API/repos/osc/skins-template/contents/$TEMPLATE_PATH?ref=main")
template_b64=$(echo "$resp" | jq -r .content) template_b64=$(echo "$resp" | jq -r .content)
echo "TEMPLATE_B64=$template_b64" >> $GITHUB_ENV echo "TEMPLATE_B64=$template_b64" >> $GITHUB_ENV
@@ -29,55 +27,38 @@ jobs:
page=1 page=1
per_page=50 per_page=50
valid_repos_file=$(mktemp) valid_repos_file=$(mktemp)
user_count_total=$(curl -sSL \ user_count_total=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/admin/users" | jq 'length')
-H "Authorization: token $TOKEN" \
"$GITEA_API/admin/users" \
| jq 'length')
user_counter=1 user_counter=1
while :; do while :; do
users_json=$(curl -sSL \ users_json=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/admin/users?limit=$per_page&page=$page")
-H "Authorization: token $TOKEN" \
"$GITEA_API/admin/users?limit=$per_page&page=$page")
users_count=$(echo "$users_json" | jq 'length') users_count=$(echo "$users_json" | jq 'length')
[ "$users_count" -eq 0 ] && break [ "$users_count" -eq 0 ] && break
for i in $(seq 0 $((users_count - 1))); do for i in $(seq 0 $((users_count - 1))); do
user_login=$(echo "$users_json" | jq -r ".[$i].login") user_login=$(echo "$users_json" | jq -r ".[$i].login")
echo "[$user_counter/$user_count_total] Processing user: $user_login" echo "[$user_counter/$user_count_total] Processing user: $user_login"
repos_json=$(curl -sSL \ repos_json=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/users/$user_login/repos")
-H "Authorization: token $TOKEN" \
"$GITEA_API/users/$user_login/repos")
repo_count=$(echo "$repos_json" | jq 'length') repo_count=$(echo "$repos_json" | jq 'length')
if [ "$repo_count" -eq 0 ]; then if [ "$repo_count" -eq 0 ]; then
echo " ✖ No repos for $user_login" echo "no repos for $user_login"
else else
repo_matched=false repo_matched=false
for j in $(seq 0 $((repo_count - 1))); do for j in $(seq 0 $((repo_count - 1))); do
owner=$(echo "$repos_json" | jq -r ".[$j].owner.login") owner=$(echo "$repos_json" | jq -r ".[$j].owner.login")
repo=$(echo "$repos_json" | jq -r ".[$j].name") repo=$(echo "$repos_json" | jq -r ".[$j].name")
readme_json=$(curl -sSL \ readme_json=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/repos/$owner/$repo/contents/README.md" || echo "{}")
-H "Authorization: token $TOKEN" \ content=$(echo "$readme_json" | jq -r .content 2>/dev/null | base64 -d 2>/dev/null || echo "")
"$GITEA_API/repos/$owner/$repo/contents/README.md" \
|| echo "{}")
content=$(echo "$readme_json" \
| jq -r .content 2>/dev/null \
| base64 -d 2>/dev/null \
|| echo "")
if echo "$content" | grep -qE "^---$" && \ if echo "$content" | grep -qE "^---$" && echo "$content" | grep -q "^gitea: none" && echo "$content" | grep -q "^include_toc: true" && echo "$content" | grep -q "^# Skins"; then
echo "$content" | grep -q "^gitea: none" && \
echo "$content" | grep -q "^include_toc: true" && \
echo "$content" | grep -q "^# Skins"; then
echo "$owner/$repo" >> "$valid_repos_file" echo "$owner/$repo" >> "$valid_repos_file"
echo " ✓ Added $owner/$repo" echo "added $owner/$repo"
repo_matched=true repo_matched=true
fi fi
done done
[ "$repo_matched" = false ] && \ [ "$repo_matched" = false ] && echo "no matching repos for $user_login"
echo " ✓ No matching repos for $user_login"
fi fi
user_counter=$((user_counter + 1)) user_counter=$((user_counter + 1))
@@ -92,41 +73,28 @@ jobs:
shell: bash shell: bash
run: | run: |
mapfile -t repos < "$VALID_REPOS_FILE" mapfile -t repos < "$VALID_REPOS_FILE"
total=${#repos[@]}
for idx in "${!repos[@]}"; do for idx in "${!repos[@]}"; do
repo_full=${repos[$idx]} repo_full=${repos[$idx]}
owner=${repo_full%%/*} owner=${repo_full%%/*}
repo=${repo_full##*/} repo=${repo_full##*/}
url="$GITEA_API/repos/$owner/$repo/contents/$TEMPLATE_PATH" url="$GITEA_API/repos/$owner/$repo/contents/$TEMPLATE_PATH"
echo "[$((idx+1))/$total] Fetching SHA for $owner/$repo…" tags_resp=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/repos/$owner/$repo/tags")
sha=$(curl -sSL \ latest_tag=$(echo "$tags_resp" | jq -r '.[0].name // ""')
-H "Authorization: token $TOKEN" \ if [ -n "$latest_tag" ] && [ "$latest_tag" != "v1.0.0" ]; then
"$url" \ curl -sSL -X DELETE -H "Authorization: token $TOKEN" "$GITEA_API/repos/$owner/$repo/git/refs/tags/$latest_tag"
| jq -r .sha // echo "")
if [ -z "$sha" ] || [ "$sha" = "null" ]; then
payload=$(jq -n \
--arg m "Add CI from skins-template" \
--arg c "$TEMPLATE_B64" \
'{message: $m, content: $c, branch: "main"}')
else
payload=$(jq -n \
--arg m "Update CI from skins-template" \
--arg c "$TEMPLATE_B64" \
--arg s "$sha" \
'{message: $m, content: $c, sha: $s, branch: "main"}')
fi fi
echo "→ PUT $url" resp=$(curl -sSL -H "Authorization: token $TOKEN" "$url")
curl -sSL -X PUT \ sha=$(echo "$resp" | jq -r 'if (type=="object" and .sha!=null) then .sha else "" end')
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \ if [ -z "$sha" ]; then
-d "$payload" \ payload=$(jq -n --arg m "Add CI from skins-template" --arg c "$TEMPLATE_B64" '{message: $m, content: $c, branch: "main"}')
"$url" \ else
&& echo "✓ Updated $owner/$repo" \ payload=$(jq -n --arg m "Update CI from skins-template" --arg c "$TEMPLATE_B64" --arg s "$sha" '{message: $m, content: $c, sha: $s, branch: "main"}')
|| echo "✖ Failed $owner/$repo" fi
curl -sSL -X PUT -H "Authorization: token $TOKEN" -H "Content-Type: application/json" -d "$payload" "$url"
done done
- name: Cleanup - name: Cleanup