From 5dc0b850d89352cb4807f6d6da0aeba77f35175d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Feb 2026 06:50:17 +0000 Subject: [PATCH 1/5] Initial plan From 5711546e5a9479bd0b58ae2a9ea8d4b7bc973237 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Feb 2026 06:51:37 +0000 Subject: [PATCH 2/5] Fix grep error handling to distinguish no matches from real failures Co-authored-by: liyu-ma <17180634+liyu-ma@users.noreply.github.com> --- .github/workflows/terraform-validation.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform-validation.yml b/.github/workflows/terraform-validation.yml index fcd66e90c0..ffdd32eeb8 100644 --- a/.github/workflows/terraform-validation.yml +++ b/.github/workflows/terraform-validation.yml @@ -200,11 +200,26 @@ jobs: # Longest Azure region name: 18 (e.g., australiasoutheast) MAX_AKS_NAME_LENGTH=40 - aks_names=$(grep -oP 'aks_name\s*=\s*"\K[^"]+' "$TERRAFORM_INPUT_FILE" || true) - if [ -z "$aks_names" ]; then + # Check if file is readable first + if [ ! -r "$TERRAFORM_INPUT_FILE" ]; then + echo "::error::Cannot read file: $TERRAFORM_INPUT_FILE" + exit 1 + fi + + # Run grep and capture exit code + aks_names=$(grep -oP 'aks_name\s*=\s*"\K[^"]+' "$TERRAFORM_INPUT_FILE") || grep_exit_code=$? + + # Exit code 1 means no matches found (skip validation) + if [ "${grep_exit_code:-0}" -eq 1 ]; then echo "No aks_name found in $TERRAFORM_INPUT_FILE, skipping validation." exit 0 fi + + # Any other non-zero exit code is a real error + if [ "${grep_exit_code:-0}" -ne 0 ]; then + echo "::error::grep failed with exit code ${grep_exit_code}" + exit 1 + fi failed=false while IFS= read -r name; do From c3ba86b8433e5f738dea4419908ab3ce2a403584 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Feb 2026 06:52:20 +0000 Subject: [PATCH 3/5] Improve grep exit code handling with explicit if-elif-else structure Co-authored-by: liyu-ma <17180634+liyu-ma@users.noreply.github.com> --- .github/workflows/terraform-validation.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/terraform-validation.yml b/.github/workflows/terraform-validation.yml index ffdd32eeb8..f889aa6e99 100644 --- a/.github/workflows/terraform-validation.yml +++ b/.github/workflows/terraform-validation.yml @@ -206,17 +206,22 @@ jobs: exit 1 fi - # Run grep and capture exit code - aks_names=$(grep -oP 'aks_name\s*=\s*"\K[^"]+' "$TERRAFORM_INPUT_FILE") || grep_exit_code=$? + # Run grep and capture exit code explicitly + set +e + aks_names=$(grep -oP 'aks_name\s*=\s*"\K[^"]+' "$TERRAFORM_INPUT_FILE") + grep_exit_code=$? + set -e - # Exit code 1 means no matches found (skip validation) - if [ "${grep_exit_code:-0}" -eq 1 ]; then + # Handle grep exit codes + if [ "$grep_exit_code" -eq 0 ]; then + # Matches found, proceed with validation + : + elif [ "$grep_exit_code" -eq 1 ]; then + # No matches found, skip validation echo "No aks_name found in $TERRAFORM_INPUT_FILE, skipping validation." exit 0 - fi - - # Any other non-zero exit code is a real error - if [ "${grep_exit_code:-0}" -ne 0 ]; then + else + # Real error (e.g., grep syntax error) echo "::error::grep failed with exit code ${grep_exit_code}" exit 1 fi From 33cfb3886bab37f2af59361d24430c495378a708 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Feb 2026 06:52:44 +0000 Subject: [PATCH 4/5] Clarify comment for exit code 0 case Co-authored-by: liyu-ma <17180634+liyu-ma@users.noreply.github.com> --- .github/workflows/terraform-validation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform-validation.yml b/.github/workflows/terraform-validation.yml index f889aa6e99..81698907a4 100644 --- a/.github/workflows/terraform-validation.yml +++ b/.github/workflows/terraform-validation.yml @@ -214,7 +214,7 @@ jobs: # Handle grep exit codes if [ "$grep_exit_code" -eq 0 ]; then - # Matches found, proceed with validation + # Matches found, proceed with validation below : elif [ "$grep_exit_code" -eq 1 ]; then # No matches found, skip validation From 86258f23c36946a443e736a7e58a7099c6413418 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Feb 2026 23:21:34 +0000 Subject: [PATCH 5/5] Revert grep error handling changes per maintainer feedback Co-authored-by: liyu-ma <17180634+liyu-ma@users.noreply.github.com> --- .github/workflows/terraform-validation.yml | 24 ++-------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/.github/workflows/terraform-validation.yml b/.github/workflows/terraform-validation.yml index 81698907a4..fcd66e90c0 100644 --- a/.github/workflows/terraform-validation.yml +++ b/.github/workflows/terraform-validation.yml @@ -200,30 +200,10 @@ jobs: # Longest Azure region name: 18 (e.g., australiasoutheast) MAX_AKS_NAME_LENGTH=40 - # Check if file is readable first - if [ ! -r "$TERRAFORM_INPUT_FILE" ]; then - echo "::error::Cannot read file: $TERRAFORM_INPUT_FILE" - exit 1 - fi - - # Run grep and capture exit code explicitly - set +e - aks_names=$(grep -oP 'aks_name\s*=\s*"\K[^"]+' "$TERRAFORM_INPUT_FILE") - grep_exit_code=$? - set -e - - # Handle grep exit codes - if [ "$grep_exit_code" -eq 0 ]; then - # Matches found, proceed with validation below - : - elif [ "$grep_exit_code" -eq 1 ]; then - # No matches found, skip validation + aks_names=$(grep -oP 'aks_name\s*=\s*"\K[^"]+' "$TERRAFORM_INPUT_FILE" || true) + if [ -z "$aks_names" ]; then echo "No aks_name found in $TERRAFORM_INPUT_FILE, skipping validation." exit 0 - else - # Real error (e.g., grep syntax error) - echo "::error::grep failed with exit code ${grep_exit_code}" - exit 1 fi failed=false