diff --git a/Taskfile.yaml b/Taskfile.yaml index 4bfe8a5..f990aae 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -17,11 +17,11 @@ tasks: Example: task init cmds: - | - PROJECT_ID="${1:-{{.DEFAULT_PROJECT_ID}}}" + PROJECT_ID="${1:-{{ .DEFAULT_PROJECT_ID }}}" gcloud auth login --update-adc gcloud config set project "$PROJECT_ID" - gcloud config set compute/region {{.REGION}} - gcloud config set compute/zone {{.REGION}}-c + gcloud config set compute/region {{ .REGION }} + gcloud config set compute/zone {{ .REGION }}-c gcloud auth application-default set-quota-project "$PROJECT_ID" setup: @@ -40,9 +40,9 @@ tasks: Example: task deploy cmds: - | - gcloud run deploy {{.SERVICE_NAME}} \ + gcloud run deploy {{ .SERVICE_NAME }} \ --source . \ - --region {{.REGION}} \ + --region {{ .REGION }} \ --allow-unauthenticated map-domain: @@ -55,9 +55,9 @@ tasks: cmds: - | gcloud beta run domain-mappings create \ - --service {{.SERVICE_NAME }} \ + --service {{ .SERVICE_NAME }} \ --domain {{ .SERVICE_NAME }}.{{ .DOMAIN }} \ - --region {{.REGION}} + --region {{ .REGION }} logs: desc: Tail the real-time logs for the service @@ -68,8 +68,8 @@ tasks: Example: task logs cmds: - | - gcloud beta run services logs tail {{.SERVICE_NAME}} \ - --region {{.REGION}} + gcloud beta run services logs tail {{ .SERVICE_NAME }} \ + --region {{ .REGION }} test: desc: Test the deployed service @@ -83,21 +83,29 @@ tasks: - | function test_service() { local path="$1" + local url="https://{{.SERVICE_NAME}}.{{.DOMAIN}}/$path" - # Use curl to capture both HTTP status code and response body - local response=$(curl -s -w "%{http_code}" https://{{.SERVICE_NAME}}.{{.DOMAIN}}/$path) - + # Use curl to capture response body and append the http_code at the end. + # Using `|| true` prevents Task from failing if curl encounters a network error. + local response=$(curl -s -w "%{http_code}" "$url") || true + # Extract status code (last 3 chars) and body (everything else) local status_code="${response:${#response}-3}" + local status_text="ERROR" local body="${response:0:${#response}-3}" - - if [ "$status_code" -lt 399 ]; then - printf "GET /%s -> [SUCCESS] Status: %s, Body: %s\n" "$path" "$status_code" "$body" - else - printf "GET /%s -> [FAILURE] Status: %s, Body: %s\n" "$path" "$status_code" "$body" + + # Check if curl failed completely (e.g. DNS failure), resulting in empty output + if [ -z "$response" ] || [ "${response:${#response}-3}" = "000" ]; then + body="[Network failure or unresolvable host]" fi + + # Status code in the 200-399 range is considered a successful response + if [ "$status_code" -ge 200 ] && [ "$status_code" -lt 400 ]; then + status_text="SUCCESS" + fi + + printf "GET /%s -> [%s] Status: %s, Body: %s\n" "$path" "$status_text" "$status_code" "$body" - # Explicitly return 0 so the task does not fail if a test fails return 0 }