Skip to content

Commit 8b65045

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

8 files changed

Lines changed: 2346 additions & 80 deletions

File tree

.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: 19 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -103,80 +103,29 @@ outputs:
103103
runs:
104104
using: 'composite'
105105
steps:
106+
- name: 'Install pnpm'
107+
if: |-
108+
${{ inputs.use_pnpm == 'true' }}
109+
uses: 'pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061' # ratchet:pnpm/action-setup@v4
110+
with:
111+
version: 10
112+
cache: true
113+
- name: 'Install node dependencies'
114+
shell: 'bash'
115+
run: |
116+
cd "${{ github.action_path }}"
117+
if [[ "${{ inputs.use_pnpm }}" == "true" ]]; then
118+
pnpm install --silent --no-audit --prefer-offline
119+
else
120+
npm ci
121+
fi
122+
106123
- name: 'Validate Inputs'
107124
id: 'validate_inputs'
108125
shell: 'bash'
109126
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
163-
fi
164-
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
171-
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 != '' }}"
177-
INPUT_GCP_TOKEN_FORMAT: '${{ inputs.gcp_token_format }}'
178-
INPUT_USE_VERTEX_AI: '${{ inputs.use_vertex_ai }}'
179-
INPUT_USE_GEMINI_CODE_ASSIST: '${{ inputs.use_gemini_code_assist }}'
127+
cd "${{ github.action_path }}"
128+
npx ts-node src/validate_inputs.ts
180129
181130
- name: 'Sanitize workflow name'
182131
id: 'sanitize_workflow_name'
@@ -218,13 +167,6 @@ runs:
218167
token_format: '${{ inputs.gcp_token_format }}'
219168
access_token_scopes: '${{ inputs.gcp_access_token_scopes }}'
220169

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-
228170
- name: 'Install Gemini CLI'
229171
id: 'install'
230172
env:

0 commit comments

Comments
 (0)