wth
This commit is contained in:
@@ -17,8 +17,7 @@ jobs:
|
|||||||
- name: Fetch CI template via Gitea API
|
- name: Fetch CI template via Gitea API
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
resp=$(curl -sSL -H "Authorization: token $TOKEN" \
|
resp=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/repos/osc/skins-template/contents/$TEMPLATE_PATH?ref=main")
|
||||||
"$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
|
||||||
|
|
||||||
@@ -28,106 +27,66 @@ jobs:
|
|||||||
page=1
|
page=1
|
||||||
per_page=50
|
per_page=50
|
||||||
valid_repos_file=$(mktemp)
|
valid_repos_file=$(mktemp)
|
||||||
user_count_total=$(curl -sSL -H "Authorization: token $TOKEN" \
|
user_count_total=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/admin/users" | jq 'length')
|
||||||
"$GITEA_API/admin/users" | jq 'length')
|
|
||||||
user_counter=1
|
user_counter=1
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
users_json=$(curl -sSL -H "Authorization: token $TOKEN" \
|
users_json=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/admin/users?limit=$per_page&page=$page")
|
||||||
"$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 -H "Authorization: token $TOKEN" \
|
repos_json=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/users/$user_login/repos")
|
||||||
"$GITEA_API/users/$user_login/repos")
|
|
||||||
repo_count=$(echo "$repos_json" | jq 'length')
|
repo_count=$(echo "$repos_json" | jq 'length')
|
||||||
|
if [ "$repo_count" -ne 0 ]; then
|
||||||
if [ "$repo_count" -eq 0 ]; then
|
|
||||||
echo "no repos for $user_login"
|
|
||||||
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 -H "Authorization: token $TOKEN" "$GITEA_API/repos/$owner/$repo/contents/README.md?ref=main" || echo "{}")
|
||||||
readme_json=$(curl -sSL -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?ref=main" \
|
|
||||||
|| echo "{}")
|
|
||||||
content=$(echo "$readme_json" | jq -r .content 2>/dev/null \
|
|
||||||
| base64 -d 2>/dev/null || echo "")
|
|
||||||
|
|
||||||
if echo "$content" | grep -qE '^[[:space:]]*#[[:space:]]*Skins[[:space:]]*$'; then
|
if echo "$content" | grep -qE '^[[:space:]]*#[[:space:]]*Skins[[:space:]]*$'; 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 ] && echo "no matching repos for $user_login"
|
[ "$repo_matched" = false ] && echo "no matching repos for $user_login"
|
||||||
|
else
|
||||||
|
echo "no repos for $user_login"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
user_counter=$((user_counter + 1))
|
user_counter=$((user_counter + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
page=$((page + 1))
|
page=$((page + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "VALID_REPOS_FILE=$valid_repos_file" >> $GITHUB_ENV
|
echo "VALID_REPOS_FILE=$valid_repos_file" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Update CI via Gitea API
|
- name: Update CI via Gitea API
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
mapfile -t repos < "$VALID_REPOS_FILE"
|
mapfile -t repos < "$VALID_REPOS_FILE"
|
||||||
for repo_full in "${repos[@]}"; do
|
for repo_full in "${repos[@]}"; do
|
||||||
owner=${repo_full%%/*}
|
owner=${repo_full%%/*}
|
||||||
repo=${repo_full##*/}
|
repo=${repo_full##*/}
|
||||||
api="$GITEA_API/repos/$owner/$repo"
|
api="$GITEA_API/repos/$owner/$repo"
|
||||||
|
default_branch=$(curl -sSL --fail -H "Authorization: token $TOKEN" "$api" | jq -r '.default_branch')
|
||||||
default_branch=$(curl -sSL --fail -H "Authorization: token $TOKEN" \
|
latest_tag=$(curl -sSL --fail -H "Authorization: token $TOKEN" "$api/tags" | jq -r '.[0].name // empty')
|
||||||
"$api" | jq -r '.default_branch')
|
|
||||||
|
|
||||||
latest_tag=$(curl -sSL --fail -H "Authorization: token $TOKEN" \
|
|
||||||
"$api/tags" | jq -r '.[0].name // empty')
|
|
||||||
|
|
||||||
if [[ -n "$latest_tag" && "$latest_tag" != "v1.0.0" ]]; then
|
if [[ -n "$latest_tag" && "$latest_tag" != "v1.0.0" ]]; then
|
||||||
curl -sSL -X DELETE -H "Authorization: token $TOKEN" \
|
curl -sSL -X DELETE -H "Authorization: token $TOKEN" "$api/git/refs/tags/$latest_tag" || true
|
||||||
"$api/git/refs/tags/$latest_tag" \
|
|
||||||
&& echo "🗑 Deleted tag $latest_tag" \
|
|
||||||
|| true
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
url="$api/contents/$TEMPLATE_PATH"
|
url="$api/contents/$TEMPLATE_PATH"
|
||||||
sha=$(curl -sSL -H "Authorization: token $TOKEN" "$url" \
|
sha=$(curl -sSL -H "Authorization: token $TOKEN" "$url" | jq -r 'select(.sha != null).sha // empty' || true)
|
||||||
| jq -r 'select(.sha != null).sha // empty' || true)
|
|
||||||
|
|
||||||
if [[ -z "$sha" ]]; then
|
if [[ -z "$sha" ]]; then
|
||||||
action="Add"
|
action="Add"
|
||||||
msg="Add CI from skins-template"
|
msg="Add CI from skins-template"
|
||||||
payload=$(jq -nc \
|
payload=$(jq -nc --arg message "$msg" --arg content "$TEMPLATE_B64" --arg branch "$default_branch" '{message: $message, content: $content, branch: $branch}')
|
||||||
--arg message "$msg" \
|
|
||||||
--arg content "$TEMPLATE_B64" \
|
|
||||||
--arg branch "$default_branch" \
|
|
||||||
'{message: $message, content: $content, branch: $branch}')
|
|
||||||
else
|
else
|
||||||
action="Update"
|
action="Update"
|
||||||
msg="Update CI from skins-template"
|
msg="Update CI from skins-template"
|
||||||
payload=$(jq -nc \
|
payload=$(jq -nc --arg message "$msg" --arg content "$TEMPLATE_B64" --arg sha "$sha" --arg branch "$default_branch" '{message: $message, content: $content, sha: $sha, branch: $branch}')
|
||||||
--arg message "$msg" \
|
|
||||||
--arg content "$TEMPLATE_B64" \
|
|
||||||
--arg sha "$sha" \
|
|
||||||
--arg branch "$default_branch" \
|
|
||||||
'{message: $message, content: $content, sha: $sha, branch: $branch}')
|
|
||||||
fi
|
fi
|
||||||
|
if curl -sSL --fail -X PUT -H "Authorization: token $TOKEN" -H "Content-Type: application/json" -d "$payload" "$url" >/dev/null; then
|
||||||
if curl -sSL --fail -X PUT \
|
|
||||||
-H "Authorization: token $TOKEN" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "$payload" "$url" >/dev/null; then
|
|
||||||
echo "✅ $action $owner/$repo on branch $default_branch"
|
echo "✅ $action $owner/$repo on branch $default_branch"
|
||||||
else
|
else
|
||||||
echo "❌ $action failed for $owner/$repo → $url" >&2
|
echo "❌ $action failed for $owner/$repo → $url" >&2
|
||||||
|
|||||||
Reference in New Issue
Block a user