5050 [--overrideProjectName <name>] \
5151 [--overrideRoleName <name>]
5252EOF
53+ return 0
5354}
5455
5556require_arg () {
@@ -61,6 +62,8 @@ require_arg() {
6162 usage
6263 exit 1
6364 fi
65+
66+ return 0
6467}
6568
6669while [[ $# -gt 0 ]]; do
@@ -110,7 +113,7 @@ while [[ $# -gt 0 ]]; do
110113 shift 2
111114 ;;
112115 * )
113- echo " [ERROR] Unknown argument: $1 "
116+ echo " [ERROR] Unknown argument: $1 " >&2
114117 exit 1
115118 ;;
116119 esac
@@ -124,20 +127,23 @@ require_arg "--targetComponent" "${targetComponent:-}"
124127require_arg " --targetAccountGroup" " ${targetAccountGroup:- } "
125128
126129if [[ -z " $APP_PEM_FILE " ]]; then
127- echo " [ERROR] PEM_FILE environment variable is not set or is empty."
130+ echo " [ERROR] PEM_FILE environment variable is not set or is empty." >&2
128131 exit 1
129132fi
130133
131134if [[ -z " $APP_CLIENT_ID " ]]; then
132- echo " [ERROR] CLIENT_ID environment variable is not set or is empty."
135+ echo " [ERROR] CLIENT_ID environment variable is not set or is empty." >&2
133136 exit 1
134137fi
135138
136139now=$( date +%s)
137140iat=$(( ${now} - 60 )) # Issues 60 seconds in the past
138141exp=$(( ${now} + 600 )) # Expires 10 minutes in the future
139142
140- b64enc () { openssl base64 | tr -d ' =' | tr ' /+' ' _-' | tr -d ' \n' ; }
143+ b64enc () {
144+ openssl base64 | tr -d ' =' | tr ' /+' ' _-' | tr -d ' \n'
145+ return 0
146+ }
141147
142148header_json=' {
143149 "typ":"JWT",
@@ -178,7 +184,7 @@ PR_TRIGGER_PAT=$(curl --request POST \
178184
179185# Set default values if not provided
180186if [[ -z " $PR_TRIGGER_PAT " ]]; then
181- echo " [ERROR] PR_TRIGGER_PAT environment variable is not set or is empty."
187+ echo " [ERROR] PR_TRIGGER_PAT environment variable is not set or is empty." >&2
182188 exit 1
183189fi
184190
@@ -244,7 +250,7 @@ trigger_response=$(curl -s -L \
244250 -d " $DISPATCH_EVENT " 2>&1 )
245251
246252if [[ $? -ne 0 ]]; then
247- echo " [ERROR] Failed to trigger workflow. Response: $trigger_response "
253+ echo " [ERROR] Failed to trigger workflow. Response: $trigger_response " >&2
248254 exit 1
249255fi
250256
@@ -264,8 +270,8 @@ for _ in {1..18}; do
264270 " https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch" )
265271
266272 if ! echo " $response " | jq empty 2> /dev/null; then
267- echo " [ERROR] Invalid JSON response from GitHub API during workflow polling:"
268- echo " $response "
273+ echo " [ERROR] Invalid JSON response from GitHub API during workflow polling:" >&2
274+ echo " $response " >&2
269275 exit 1
270276 fi
271277
@@ -303,7 +309,7 @@ for _ in {1..18}; do
303309done
304310
305311if [[ -z " $workflow_run_url " || " $workflow_run_url " == null ]]; then
306- echo " [ERROR] Failed to get the workflow run url. Exiting."
312+ echo " [ERROR] Failed to get the workflow run url. Exiting." >&2
307313 exit 1
308314fi
309315
@@ -318,21 +324,21 @@ while true; do
318324 status=$( echo " $response " | jq -r ' .status' )
319325 echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] Workflow status: $status "
320326
321- if [ " $status " == " completed" ]; then
327+ if [[ " $status " == " completed" ] ]; then
322328 conclusion=$( echo " $response " | jq -r ' .conclusion' )
323329 echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] Workflow conclusion: $conclusion "
324330
325- if [ -z " $conclusion " ] || [ " $conclusion " == " null" ]; then
331+ if [[ -z " $conclusion " || " $conclusion " == " null" ] ]; then
326332 echo " [WARN] Workflow marked completed but conclusion not yet available, retrying..."
327333 sleep 5
328334 continue
329335 fi
330336
331- if [ " $conclusion " == " success" ]; then
337+ if [[ " $conclusion " == " success" ] ]; then
332338 echo " [SUCCESS] Workflow completed successfully!"
333339 exit 0
334340 else
335- echo " [FAIL] Workflow failed with conclusion: $conclusion "
341+ echo " [FAIL] Workflow failed with conclusion: $conclusion " >&2
336342 exit 1
337343 fi
338344 fi
0 commit comments