name: Reload Gitainer Stack on: workflow_call: inputs: stack_name: required: true type: string delayed_silent: description: Delay the webhook call using a detached container and always succeed. Used when rebuilding the runner executing the webhook. required: false type: boolean default: false runs_on_label: description: The runner label to execute this workflow on. required: false type: string default: ubuntu-22.04 webhook_timeout: description: Maximum time in seconds that curl will allow the Gitainer API webhook to take before failing. required: false type: number default: 300 jobs: deploy-gitainer: runs-on: ${{ inputs.runs_on_label }} steps: - name: Check status step id: check-step if: success() run: echo "Workflow successful" - name: Call Gitainer stack webhooks 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 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