Skip to content

Commit 41f88d8

Browse files
Moving validate logic to Typescript
related to #373 related to #375
1 parent 87c4941 commit 41f88d8

File tree

9 files changed

+2419
-79
lines changed

9 files changed

+2419
-79
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ gha-creds-*.json
6868

6969
# Ignore local secrets file for act
7070
.secrets
71+
junit.xml

action.yml

Lines changed: 26 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -103,77 +103,34 @@ outputs:
103103
runs:
104104
using: 'composite'
105105
steps:
106-
- name: 'Validate Inputs'
107-
id: 'validate_inputs'
106+
- name: 'Install pnpm'
107+
if: ${{ inputs.use_pnpm == 'true' }}
108+
uses: 'pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061' # ratchet:pnpm/action-setup@v4
109+
with:
110+
version: 10
111+
cache: true
112+
- name: 'Install node dependencies'
108113
shell: 'bash'
109-
run: |-
110-
set -exuo pipefail
111-
112-
# Emit a clear warning in three places without failing the step
113-
warn() {
114-
local msg="$1"
115-
echo "WARNING: ${msg}" >&2
116-
echo "::warning title=Input validation::${msg}"
117-
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
118-
{
119-
echo "### Input validation warnings"
120-
echo
121-
echo "- ${msg}"
122-
} >> "${GITHUB_STEP_SUMMARY}"
123-
fi
124-
}
125-
126-
# Validate the count of authentication methods
127-
auth_methods=0
128-
if [[ "${INPUT_GEMINI_API_KEY_PRESENT:-false}" == "true" ]]; then ((++auth_methods)); fi
129-
if [[ "${INPUT_GOOGLE_API_KEY_PRESENT:-false}" == "true" ]]; then ((++auth_methods)); fi
130-
if [[ "${INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT:-false}" == "true" ]]; then ((++auth_methods)); fi
131-
132-
if [[ ${auth_methods} -eq 0 ]]; then
133-
warn "No authentication method provided. Please provide one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
134-
fi
135-
136-
if [[ ${auth_methods} -gt 1 ]]; then
137-
warn "Multiple authentication methods provided. Please use only one of 'gemini_api_key', 'google_api_key', or 'gcp_workload_identity_provider'."
138-
fi
139-
140-
# Validate Workload Identity Federation inputs
141-
if [[ "${INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT:-false}" == "true" ]]; then
142-
if [[ "${INPUT_GCP_PROJECT_ID_PRESENT:-false}" != "true" ]]; then
143-
warn "When using Workload Identity Federation ('gcp_workload_identity_provider'), you must also provide 'gcp_project_id'."
144-
fi
145-
# Service account is required when using token_format (default behavior)
146-
# Only optional when explicitly set to empty for direct WIF
147-
if [[ "${INPUT_GCP_TOKEN_FORMAT}" != "" && "${INPUT_GCP_SERVICE_ACCOUNT_PRESENT:-false}" != "true" ]]; then
148-
warn "When using Workload Identity Federation with token generation ('gcp_token_format'), you must also provide 'gcp_service_account'. To use direct WIF without a service account, explicitly set 'gcp_token_format' to an empty string."
149-
fi
150-
if [[ "${INPUT_USE_VERTEX_AI:-false}" == "${INPUT_USE_GEMINI_CODE_ASSIST:-false}" ]]; then
151-
warn "When using Workload Identity Federation, you must set exactly one of 'use_vertex_ai' or 'use_gemini_code_assist' to 'true'."
152-
fi
153-
fi
154-
155-
# Validate Vertex AI API Key
156-
if [[ "${INPUT_GOOGLE_API_KEY_PRESENT:-false}" == "true" ]]; then
157-
if [[ "${INPUT_USE_VERTEX_AI:-false}" != "true" ]]; then
158-
warn "When using 'google_api_key', you must set 'use_vertex_ai' to 'true'."
159-
fi
160-
if [[ "${INPUT_USE_GEMINI_CODE_ASSIST:-false}" == "true" ]]; then
161-
warn "When using 'google_api_key', 'use_gemini_code_assist' cannot be 'true'."
162-
fi
114+
working-directory: '${{ github.action_path }}'
115+
run: |
116+
if [[ "${{ inputs.use_pnpm }}" == "true" ]]; then
117+
pnpm install --silent --no-audit --prefer-offline
118+
else
119+
npm ci --silent --no-audit
163120
fi
164121
165-
# Validate Gemini API Key
166-
if [[ "${INPUT_GEMINI_API_KEY_PRESENT:-false}" == "true" ]]; then
167-
if [[ "${INPUT_USE_VERTEX_AI:-false}" == "true" || "${INPUT_USE_GEMINI_CODE_ASSIST:-false}" == "true" ]]; then
168-
warn "When using 'gemini_api_key', both 'use_vertex_ai' and 'use_gemini_code_assist' must be 'false'."
169-
fi
170-
fi
122+
- name: 'Validate Inputs'
123+
id: 'validate_inputs'
124+
working-directory: '${{ github.action_path }}'
125+
shell: 'bash'
126+
run: |
127+
npx ts-node src/validate_inputs.ts
171128
env:
172-
INPUT_GEMINI_API_KEY_PRESENT: "${{ inputs.gemini_api_key != '' }}"
173-
INPUT_GOOGLE_API_KEY_PRESENT: "${{ inputs.google_api_key != '' }}"
174-
INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER_PRESENT: "${{ inputs.gcp_workload_identity_provider != '' }}"
175-
INPUT_GCP_PROJECT_ID_PRESENT: "${{ inputs.gcp_project_id != '' }}"
176-
INPUT_GCP_SERVICE_ACCOUNT_PRESENT: "${{ inputs.gcp_service_account != '' }}"
129+
INPUT_GEMINI_API_KEY: '${{ inputs.gemini_api_key }}'
130+
INPUT_GOOGLE_API_KEY: '${{ inputs.google_api_key }}'
131+
INPUT_GCP_WORKLOAD_IDENTITY_PROVIDER: '${{ inputs.gcp_workload_identity_provider }}'
132+
INPUT_GCP_PROJECT_ID: '${{ inputs.gcp_project_id }}'
133+
INPUT_GCP_SERVICE_ACCOUNT: '${{ inputs.gcp_service_account }}'
177134
INPUT_GCP_TOKEN_FORMAT: '${{ inputs.gcp_token_format }}'
178135
INPUT_USE_VERTEX_AI: '${{ inputs.use_vertex_ai }}'
179136
INPUT_USE_GEMINI_CODE_ASSIST: '${{ inputs.use_gemini_code_assist }}'
@@ -218,13 +175,6 @@ runs:
218175
token_format: '${{ inputs.gcp_token_format }}'
219176
access_token_scopes: '${{ inputs.gcp_access_token_scopes }}'
220177

221-
- name: 'Install pnpm'
222-
if: |-
223-
${{ inputs.use_pnpm == 'true' }}
224-
uses: 'pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061' # ratchet:pnpm/action-setup@v4
225-
with:
226-
version: 10
227-
228178
- name: 'Install Gemini CLI'
229179
id: 'install'
230180
env:
@@ -294,14 +244,14 @@ runs:
294244
if [[ "${GEMINI_DEBUG}" = true ]]; then
295245
echo "::warning::Gemini CLI debug logging is enabled. This will stream responses, which could reveal sensitive information if processed with untrusted inputs."
296246
echo "::: Start Gemini CLI STDOUT :::"
297-
if ! gemini --debug --yolo --prompt "${PROMPT}" --output-format json 2> >(tee "${TEMP_STDERR}" >&2) | tee "${TEMP_STDOUT}"; then
247+
if ! gemini --debug --yolo --prompt "${PROMPT}" 2> >(tee "${TEMP_STDERR}" >&2) | tee "${TEMP_STDOUT}"; then
298248
FAILED=true
299249
fi
300250
# Wait for async stderr logging to complete. This is because process substitution in Bash is async so let tee finish writing to ${TEMP_STDERR}
301251
sleep 1
302252
echo "::: End Gemini CLI STDOUT :::"
303253
else
304-
if ! gemini --yolo --prompt "${PROMPT}" --output-format json 2> "${TEMP_STDERR}" 1> "${TEMP_STDOUT}"; then
254+
if ! gemini --yolo --prompt "${PROMPT}" 2> "${TEMP_STDERR}" 1> "${TEMP_STDOUT}"; then
305255
FAILED=true
306256
fi
307257
fi

0 commit comments

Comments
 (0)