From efacc4e5d16f01226d5802187b05c84e46fbd70e Mon Sep 17 00:00:00 2001 From: Arlind Sulejmani Date: Sun, 8 Jun 2025 17:10:31 +0200 Subject: [PATCH] add bash as shell --- .gitea/workflows/deploy-ci.yaml | 46 ++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/deploy-ci.yaml b/.gitea/workflows/deploy-ci.yaml index f473ffc..77b4439 100644 --- a/.gitea/workflows/deploy-ci.yaml +++ b/.gitea/workflows/deploy-ci.yaml @@ -72,6 +72,8 @@ jobs: - name: Update CI via Gitea API shell: bash run: | + set -eo pipefail + mapfile -t repos < "$VALID_REPOS_FILE" for idx in "${!repos[@]}"; do repo_full=${repos[$idx]} @@ -79,22 +81,46 @@ jobs: repo=${repo_full##*/} url="$GITEA_API/repos/$owner/$repo/contents/$TEMPLATE_PATH" - tags_resp=$(curl -sSL -H "Authorization: token $TOKEN" "$GITEA_API/repos/$owner/$repo/tags") - latest_tag=$(echo "$tags_resp" | jq -r '.[0].name // ""') - if [ -n "$latest_tag" ] && [ "$latest_tag" != "v1.0.0" ]; then - curl -sSL -X DELETE -H "Authorization: token $TOKEN" "$GITEA_API/repos/$owner/$repo/git/refs/tags/$latest_tag" + latest_tag=$(curl -sSL --fail -H "Authorization: token $TOKEN" \ + "$GITEA_API/repos/$owner/$repo/tags" \ + | jq -r '.[0].name // empty' ) + + if [[ -n "$latest_tag" && "$latest_tag" != "v1.0.0" ]]; then + curl -sSL --fail -X DELETE \ + -H "Authorization: token $TOKEN" \ + "$GITEA_API/repos/$owner/$repo/git/refs/tags/$latest_tag" \ + >/dev/null fi - resp=$(curl -sSL -H "Authorization: token $TOKEN" "$url") - sha=$(echo "$resp" | jq -r 'if (type=="object" and .sha!=null) then .sha else "" end') + sha=$(curl -sSL --fail -H "Authorization: token $TOKEN" "$url" \ + | jq -r 'select(.sha != null).sha // empty') - if [ -z "$sha" ]; then - payload=$(jq -n --arg m "Add CI from skins-template" --arg c "$TEMPLATE_B64" '{message: $m, content: $c, branch: "main"}') + if [[ -z "$sha" ]]; then + msg="Add CI from skins-template" + payload=$(jq -nc \ + --arg message "$msg" \ + --arg content "$TEMPLATE_B64" \ + '{message: $message, content: $content, 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"}') + msg="Update CI from skins-template" + payload=$(jq -nc \ + --arg message "$msg" \ + --arg content "$TEMPLATE_B64" \ + --arg sha "$sha" \ + '{message: $message, content: $content, sha: $sha, branch: "main"}') + fi + + if curl -sSL --fail -X PUT \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + -d "$payload" \ + "$url" \ + >/dev/null; then + echo "✅ $owner/$repo" + else + echo "❌ $owner/$repo" >&2 fi - curl -sSL -X PUT -H "Authorization: token $TOKEN" -H "Content-Type: application/json" -d "$payload" "$url" done - name: Cleanup