Skip to content

Commit af6cb68

Browse files
authored
fix(validate-inputs): surface errors in logs, annotation, and step summary (#299)
Introduce error() helper to: - write to stderr for log visibility - emit a titled ::error:: annotation for Checks - append to GITHUB_STEP_SUMMARY for run summary Replace ad-hoc echo+exit paths with error() across all validation branches.
1 parent ff81ee2 commit af6cb68

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

scripts/validate-inputs.sh

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
#!/bin/bash
22
set -euo pipefail
33

4+
# Emit a clear error in three places:
5+
# - STDERR (visible in step logs)
6+
# - GitHub annotation with a title (more visible in Checks)
7+
# - Step summary (always shown in the job summary)
8+
error() {
9+
local msg="$1"
10+
echo "ERROR: ${msg}" >&2
11+
echo "::error title=Input validation failed::${msg}"
12+
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
13+
{
14+
echo "### Input validation failed"
15+
echo
16+
echo "- ${msg}"
17+
} >> "${GITHUB_STEP_SUMMARY}"
18+
fi
19+
exit 1
20+
}
21+
422
# Auth inputs (as boolean presence flags)
523
gemini_api_key_present="${INPUT_GEMINI_API_KEY_PRESENT:-false}"
624
google_api_key_present="${INPUT_GOOGLE_API_KEY_PRESENT:-false}"
@@ -19,47 +37,39 @@ if [[ "${google_api_key_present}" == "true" ]]; then ((auth_methods++)); fi
1937
if [[ "${gcp_workload_identity_provider_present}" == "true" ]]; then ((auth_methods++)); fi
2038

2139
if [[ ${auth_methods} -eq 0 ]]; then
22-
echo "::error::No authentication method provided. Please provide one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
23-
exit 1
40+
error "No authentication method provided. Please provide one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
2441
fi
2542

2643
if [[ ${auth_methods} -gt 1 ]]; then
27-
echo "::error::Multiple authentication methods provided. Please use only one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
28-
exit 1
44+
error "Multiple authentication methods provided. Please use only one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
2945
fi
3046

3147
# WIF validation
3248
if [[ "${gcp_workload_identity_provider_present}" == "true" ]]; then
3349
if [[ "${gcp_project_id_present}" != "true" || "${gcp_service_account_present}" != "true" ]]; then
34-
echo "::error::When using Workload Identity Federation ('gcp_workload_identity_provider'), you must also provide 'gcp_project_id' and 'gcp_service_account'."
35-
exit 1
50+
error "When using Workload Identity Federation ('gcp_workload_identity_provider'), you must also provide 'gcp_project_id' and 'gcp_service_account'."
3651
fi
3752
if [[ "${use_vertex_ai}" != "true" && "${use_gemini_code_assist}" != "true" ]]; then
38-
echo "::error::When using Workload Identity Federation, you must set either 'use_vertex_ai' or 'use_gemini_code_assist' to 'true'. Both are set to 'false', please choose one."
39-
exit 1
53+
error "When using Workload Identity Federation, you must set either 'use_vertex_ai' or 'use_gemini_code_assist' to 'true'. Both are set to 'false', please choose one."
4054
fi
4155
if [[ "${use_vertex_ai}" == "true" && "${use_gemini_code_assist}" == "true" ]]; then
42-
echo "::error::When using Workload Identity Federation, 'use_vertex_ai' and 'use_gemini_code_assist' cannot both be 'true'. Both are set to 'true', please choose one."
43-
exit 1
56+
error "When using Workload Identity Federation, 'use_vertex_ai' and 'use_gemini_code_assist' cannot both be 'true'. Both are set to 'true', please choose one."
4457
fi
4558
fi
4659

4760
# Vertex AI API Key validation
4861
if [[ "${google_api_key_present}" == "true" ]]; then
4962
if [[ "${use_vertex_ai}" != "true" ]]; then
50-
echo "::error::When using 'google_api_key', you must set 'use_vertex_ai' to 'true'."
51-
exit 1
63+
error "When using 'google_api_key', you must set 'use_vertex_ai' to 'true'."
5264
fi
5365
if [[ "${use_gemini_code_assist}" == "true" ]]; then
54-
echo "::error::When using 'google_api_key', 'use_gemini_code_assist' cannot be 'true'."
55-
exit 1
66+
error "When using 'google_api_key', 'use_gemini_code_assist' cannot be 'true'."
5667
fi
5768
fi
5869

5970
# Gemini API Key validation
6071
if [[ "${gemini_api_key_present}" == "true" ]]; then
6172
if [[ "${use_vertex_ai}" == "true" || "${use_gemini_code_assist}" == "true" ]]; then
62-
echo "::error::When using 'gemini_api_key', both 'use_vertex_ai' and 'use_gemini_code_assist' must be 'false'."
63-
exit 1
73+
error "When using 'gemini_api_key', both 'use_vertex_ai' and 'use_gemini_code_assist' must be 'false'."
6474
fi
6575
fi

0 commit comments

Comments
 (0)