add bash as shell
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:
@@ -75,50 +75,63 @@ jobs:
|
|||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
mapfile -t repos < "$VALID_REPOS_FILE"
|
mapfile -t repos < "$VALID_REPOS_FILE"
|
||||||
for idx in "${!repos[@]}"; do
|
for repo_full in "${repos[@]}"; do
|
||||||
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"
|
api="$GITEA_API/repos/$owner/$repo"
|
||||||
|
|
||||||
|
# 1) figure out the default branch
|
||||||
|
default_branch=$(curl -sSL --fail -H "Authorization: token $TOKEN" \
|
||||||
|
"$api" \
|
||||||
|
| jq -r '.default_branch')
|
||||||
|
|
||||||
|
# 2) delete the latest non-v1.0.0 tag (but ignore if none)
|
||||||
latest_tag=$(curl -sSL --fail -H "Authorization: token $TOKEN" \
|
latest_tag=$(curl -sSL --fail -H "Authorization: token $TOKEN" \
|
||||||
"$GITEA_API/repos/$owner/$repo/tags" \
|
"$api/tags" \
|
||||||
| jq -r '.[0].name // empty' )
|
| 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 --fail -X DELETE \
|
curl -sSL -X DELETE -H "Authorization: token $TOKEN" \
|
||||||
-H "Authorization: token $TOKEN" \
|
"$api/git/refs/tags/$latest_tag" \
|
||||||
"$GITEA_API/repos/$owner/$repo/git/refs/tags/$latest_tag" \
|
&& echo "🗑 Deleted tag $latest_tag" \
|
||||||
>/dev/null
|
|| true # ignore 404 / failures here
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sha=$(curl -sSL --fail -H "Authorization: token $TOKEN" "$url" \
|
# 3) fetch existing file SHA (if any)
|
||||||
| jq -r 'select(.sha != null).sha // empty')
|
url="$api/contents/$TEMPLATE_PATH"
|
||||||
|
sha=$(curl -sSL -H "Authorization: token $TOKEN" "$url" \
|
||||||
|
| jq -r 'select(.sha != null).sha // empty' || true)
|
||||||
|
|
||||||
|
# 4) build our payload
|
||||||
if [[ -z "$sha" ]]; then
|
if [[ -z "$sha" ]]; then
|
||||||
|
action="Add"
|
||||||
msg="Add CI from skins-template"
|
msg="Add CI from skins-template"
|
||||||
payload=$(jq -nc \
|
payload=$(jq -nc \
|
||||||
--arg message "$msg" \
|
--arg message "$msg" \
|
||||||
--arg content "$TEMPLATE_B64" \
|
--arg content "$TEMPLATE_B64" \
|
||||||
'{message: $message, content: $content, branch: "main"}')
|
--arg branch "$default_branch" \
|
||||||
|
'{message: $message, content: $content, branch: $branch}')
|
||||||
else
|
else
|
||||||
|
action="Update"
|
||||||
msg="Update CI from skins-template"
|
msg="Update CI from skins-template"
|
||||||
payload=$(jq -nc \
|
payload=$(jq -nc \
|
||||||
--arg message "$msg" \
|
--arg message "$msg" \
|
||||||
--arg content "$TEMPLATE_B64" \
|
--arg content "$TEMPLATE_B64" \
|
||||||
--arg sha "$sha" \
|
--arg sha "$sha" \
|
||||||
'{message: $message, content: $content, sha: $sha, branch: "main"}')
|
--arg branch "$default_branch" \
|
||||||
|
'{message: $message, content: $content, sha: $sha, branch: $branch}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 5) push it
|
||||||
if curl -sSL --fail -X PUT \
|
if curl -sSL --fail -X PUT \
|
||||||
-H "Authorization: token $TOKEN" \
|
-H "Authorization: token $TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "$payload" \
|
-d "$payload" \
|
||||||
"$url" \
|
"$url" \
|
||||||
>/dev/null; then
|
>/dev/null; then
|
||||||
echo "✅ $owner/$repo"
|
echo "✅ $action $owner/$repo on branch $default_branch"
|
||||||
else
|
else
|
||||||
echo "❌ $owner/$repo" >&2
|
echo "❌ $action failed for $owner/$repo → $url" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user