Update .gitea/workflows/deploy-ci.yaml
All checks were successful
Update Community Skins README / Full CI/CD Pipeline (push) Successful in 4s
All checks were successful
Update Community Skins README / Full CI/CD Pipeline (push) Successful in 4s
This commit is contained in:
@@ -3,68 +3,80 @@ name: Sync CI from skins-template to Every User Repository
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
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:
|
jobs:
|
||||||
sync-all:
|
sync-all:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: ${{ vars.CONTAINER_REGISTRY }}/arlind/skins:latest
|
image: ${{ vars.CONTAINER_REGISTRY }}/arlind/skins:latest
|
||||||
|
env:
|
||||||
|
GITEA_API: https://${{ vars.CONTAINER_REGISTRY }}/api/v1
|
||||||
|
TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
TEMPLATE_PATH: .gitea/workflows/ci.yml
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Clone skins-template
|
- name: Fetch CI template via Gitea API
|
||||||
run: |
|
run: |
|
||||||
echo "Cloning skins-template..."
|
# get the template file (base64)
|
||||||
git clone --quiet "${{ env.TEMPLATE_REPO_URL }}" --depth 1 template-repo
|
resp=$(curl -sSL \
|
||||||
cd template-repo
|
-H "Authorization: token $TOKEN" \
|
||||||
git checkout --quiet HEAD -- "${{ env.TEMPLATE_REL_PATH }}"
|
"$GITEA_API/repos/osc/skins-template/contents/$TEMPLATE_PATH?ref=main")
|
||||||
echo "✓ Finished cloning osc/skins-template"
|
template_b64=$(echo "$resp" | jq -r .content)
|
||||||
|
echo "TEMPLATE_B64=$template_b64" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Fetch valid user repositories
|
- name: Fetch valid user repositories
|
||||||
id: fetch_repos
|
|
||||||
run: |
|
run: |
|
||||||
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 ${{ secrets.TOKEN }}" "${{ env.GITEA_API }}/admin/users" | jq 'length')
|
user_count_total=$(curl -sSL \
|
||||||
|
-H "Authorization: token $TOKEN" \
|
||||||
|
"$GITEA_API/admin/users" \
|
||||||
|
| jq 'length')
|
||||||
user_counter=1
|
user_counter=1
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
users_json=$(curl -sSL -H "Authorization: token ${{ secrets.TOKEN }}" "${{ env.GITEA_API }}/admin/users?limit=$per_page&page=$page")
|
users_json=$(curl -sSL \
|
||||||
|
-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 -H "Authorization: token ${{ secrets.TOKEN }}" "${{ env.GITEA_API }}/users/${user_login}/repos")
|
repos_json=$(curl -sSL \
|
||||||
|
-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 " ✖ User has no repositories."
|
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 ${{ secrets.TOKEN }}" "${{ env.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 "^gitea: none" && \
|
||||||
echo "$content" | grep -q "^include_toc: true" && \
|
echo "$content" | grep -q "^include_toc: true" && \
|
||||||
echo "$content" | grep -q "^# Skins"; then
|
echo "$content" | grep -q "^# Skins"; then
|
||||||
echo "$owner/$repo" >> "$valid_repos_file"
|
echo "$owner/$repo" >> "$valid_repos_file"
|
||||||
echo " ✓ Added $owner/$repo to update list"
|
echo " ✓ Added $owner/$repo"
|
||||||
repo_matched=true
|
repo_matched=true
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "$repo_matched" = false ] && echo " ✓ User has no repositories matching the criteria"
|
[ "$repo_matched" = false ] && \
|
||||||
|
echo " ✓ No matching repos for $user_login"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
user_counter=$((user_counter + 1))
|
user_counter=$((user_counter + 1))
|
||||||
@@ -73,63 +85,47 @@ jobs:
|
|||||||
page=$((page + 1))
|
page=$((page + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "valid_repos_file=$valid_repos_file" >> "$GITHUB_OUTPUT"
|
echo "VALID_REPOS_FILE=$valid_repos_file" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Update user repositories
|
- name: Update CI via Gitea API
|
||||||
run: |
|
run: |
|
||||||
valid_repos_file="${{ steps.fetch_repos.outputs.valid_repos_file }}"
|
mapfile -t repos < "$VALID_REPOS_FILE"
|
||||||
repo_total=$(wc -l < "$valid_repos_file")
|
total=${#repos[@]}
|
||||||
repo_counter=1
|
|
||||||
|
|
||||||
while read -r repo_full; do
|
for idx in "${!repos[@]}"; do
|
||||||
owner=$(echo "$repo_full" | cut -d'/' -f1)
|
repo_full=${repos[$idx]}
|
||||||
repo=$(echo "$repo_full" | cut -d'/' -f2)
|
owner=${repo_full%%/*}
|
||||||
echo "[$repo_counter/$repo_total] Processing Repository: $owner/$repo"
|
repo=${repo_full##*/}
|
||||||
|
url="$GITEA_API/repos/$owner/$repo/contents/$TEMPLATE_PATH"
|
||||||
|
|
||||||
tmpdir=$(mktemp -d)
|
echo "[$((idx+1))/$total] Fetching SHA for $owner/$repo…"
|
||||||
git clone --quiet "https://${{ secrets.TOKEN }}@${{ vars.CONTAINER_REGISTRY }}/${owner}/${repo}.git" "$tmpdir"
|
sha=$(curl -sSL \
|
||||||
cd "$tmpdir"
|
-H "Authorization: token $TOKEN" \
|
||||||
mkdir -p .gitea/workflows
|
"$url" \
|
||||||
cp "/workspace/osc/skins/template-repo/${{ env.TEMPLATE_REL_PATH }}" .gitea/workflows/ci.yml
|
| jq -r .sha // echo "")
|
||||||
git config user.email "arlind@sulej.ch"
|
|
||||||
git config user.name "ci-bot"
|
|
||||||
git add .gitea/workflows/ci.yml
|
|
||||||
|
|
||||||
if ! git diff --cached --quiet; then
|
if [ -z "$sha" ] || [ "$sha" = "null" ]; then
|
||||||
git fetch --tags >/dev/null 2>&1
|
payload=$(jq -n \
|
||||||
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || true)
|
--arg m "Add CI from skins-template" \
|
||||||
latest_tag=$(echo "$latest_tag" | xargs)
|
--arg c "$TEMPLATE_B64" \
|
||||||
echo "Latest tag detected: '$latest_tag'"
|
'{message: $m, content: $c, branch: "main"}')
|
||||||
if [ -n "$latest_tag" ]; then
|
|
||||||
if [ "$latest_tag" = "v1.0.0" ]; then
|
|
||||||
echo "Never delete v1.0.0"
|
|
||||||
else
|
|
||||||
echo "Deleting tag '$latest_tag' (not v1.0.0)..."
|
|
||||||
git push origin --delete tag "$latest_tag" >/dev/null 2>&1 || true
|
|
||||||
git tag -d "$latest_tag" >/dev/null 2>&1 || true
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "No tags found to consider for deletion."
|
|
||||||
fi
|
|
||||||
git commit -m "Update CI" --quiet
|
|
||||||
git push origin HEAD:main --tags --force >/dev/null 2>&1
|
|
||||||
echo " → Updated and pushed $owner/$repo"
|
|
||||||
else
|
else
|
||||||
echo " → No changes detected for $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"}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd - >/dev/null
|
echo "→ PUT $url"
|
||||||
rm -rf "$tmpdir"
|
curl -sSL -X PUT \
|
||||||
echo " ✓ Completed $owner/$repo"
|
-H "Authorization: token $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$payload" \
|
||||||
|
"$url" \
|
||||||
|
&& echo "✓ Updated $owner/$repo" \
|
||||||
|
|| echo "✖ Failed $owner/$repo"
|
||||||
|
done
|
||||||
|
|
||||||
repo_counter=$((repo_counter + 1))
|
- name: Cleanup
|
||||||
done < "$valid_repos_file"
|
run: rm -f "$VALID_REPOS_FILE"
|
||||||
|
|
||||||
rm "$valid_repos_file"
|
|
||||||
rm -rf "$tmpdir"
|
|
||||||
echo " ✓ Completed $owner/$repo"
|
|
||||||
|
|
||||||
repo_counter=$((repo_counter + 1))
|
|
||||||
done < "$valid_repos_file"
|
|
||||||
|
|
||||||
rm "$valid_repos_file"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user