Skip to content

Commit 8423643

Browse files
committed
fix(action): correct input validation script behavior
The input validation script was failing silently and incorrectly when exactly one authentication method was provided. This was due to the interaction between 'set -e' and the exit code of Bash arithmetic evaluation. The post-increment expression 'auth_methods++' evaluates to 0 when auth_methods is 0. In Bash, an arithmetic expression that evaluates to 0 returns an exit code of 1. With 'set -e' enabled, this non-zero exit code caused the script to exit as if an error had occurred. This commit changes the post-increment to a pre-increment '++auth_methods'. This ensures the expression always evaluates to a non-zero value (1, 2, or 3), resulting in a 0 exit code and preventing the script from failing. Additionally, the '-x' flag has been added to the 'set' command to enable xtrace, which will print commands as they are executed. This improves the debuggability of the script.
1 parent 10952a8 commit 8423643

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

action.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ runs:
8484
id: 'validate_inputs'
8585
shell: 'bash'
8686
run: |-
87-
set -euo pipefail
87+
set -exuo pipefail
8888
8989
# Emit a clear warning in three places without failing the step
9090
warn() {
@@ -102,9 +102,9 @@ runs:
102102
103103
# Validate the count of authentication methods
104104
auth_methods=0
105-
if [[ "${INPUT_GEMINI_API_KEY_PRESENT:-false}" == "true" ]]; then ((auth_methods++)); fi
106-
if [[ "${INPUT_GOOGLE_API_KEY_PRESENT:-false}" == "true" ]]; then ((auth_methods++)); fi
107-
if [[ "${INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT:-false}" == "true" ]]; then ((auth_methods++)); fi
105+
if [[ "${INPUT_GEMINI_API_KEY_PRESENT:-false}" == "true" ]]; then ((++auth_methods)); fi
106+
if [[ "${INPUT_GOOGLE_API_KEY_PRESENT:-false}" == "true" ]]; then ((++auth_methods)); fi
107+
if [[ "${INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT:-false}" == "true" ]]; then ((++auth_methods)); fi
108108
109109
if [[ ${auth_methods} -eq 0 ]]; then
110110
warn "No authentication method provided. Please provide one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."

0 commit comments

Comments
 (0)