From 6a88a5d1f4de34159926aa324b9e227a896f5071 Mon Sep 17 00:00:00 2001 From: Martin Dimitrov Date: Tue, 7 Jul 2026 20:35:06 -0700 Subject: [PATCH] refine gitainer deploy to error out if we get err json --- .gitea/workflows/gitainer-deploy.yaml | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/gitainer-deploy.yaml b/.gitea/workflows/gitainer-deploy.yaml index 1a8d363..3f5fe5a 100644 --- a/.gitea/workflows/gitainer-deploy.yaml +++ b/.gitea/workflows/gitainer-deploy.yaml @@ -32,12 +32,40 @@ jobs: run: echo "Workflow successful" - name: Call Gitainer stack webhooks - continue-on-error: true + continue-on-error: ${{ inputs.delayed_silent }} run: | if [ "${{ inputs.delayed_silent }}" = "true" ]; then echo "Delaying the webhook call by 10s using a detached container." echo "This gives the runner time to report job completion and clean up before it restarts." docker run --rm -d alpine sh -c "apk add --no-cache curl && sleep 10 && curl --max-time ${{ inputs.webhook_timeout }} --request POST 'http://gitainer.local.chromart.cc/api/stacks/${{ inputs.stack_name }}?pretty'" else - curl --max-time ${{ inputs.webhook_timeout }} --request POST "http://gitainer.local.chromart.cc/api/stacks/${{ inputs.stack_name }}?pretty" + if ! RESPONSE=$(curl --max-time ${{ inputs.webhook_timeout }} \ + --write-out "\n%{http_code}" \ + --silent \ + --show-error \ + --request POST \ + "http://gitainer.local.chromart.cc/api/stacks/${{ inputs.stack_name }}?pretty"); then + echo "Error: curl command failed." + exit 1 + fi + + HTTP_CODE=$(echo "$RESPONSE" | tail -n1) + RESPONSE_BODY=$(echo "$RESPONSE" | sed '$d') + + echo "HTTP Status Code: $HTTP_CODE" + echo "Response Body:" + echo "$RESPONSE_BODY" + + if echo "$RESPONSE_BODY" | jq -e . >/dev/null 2>&1; then + if echo "$RESPONSE_BODY" | jq -e '(.err != null and .err != false) or (.error != null and .error != false)' >/dev/null 2>&1; then + ERR_MSG=$(echo "$RESPONSE_BODY" | jq -r 'if .err != null and .err != false then .err else .error end') + echo "Error: Gitainer deploy failed with message: $ERR_MSG" + exit 1 + fi + fi + + if [ "$HTTP_CODE" -ne 200 ]; then + echo "Error: Gitainer deploy failed with HTTP status code $HTTP_CODE" + exit 1 + fi fi