@@ -68,15 +68,15 @@ while [[ $# -gt 0 ]]; do
6868 shift 2
6969 ;;
7070 * )
71- echo " Unknown argument: $1 "
71+ echo " [ERROR] Unknown argument: $1 "
7272 exit 1
7373 ;;
7474 esac
7575done
7676
7777# Set default values if not provided
7878if [[ -z " $PR_TRIGGER_PAT " ]]; then
79- echo " Error: PR_TRIGGER_PAT environment variable is not set or is empty."
79+ echo " [ERROR] PR_TRIGGER_PAT environment variable is not set or is empty."
8080 exit 1
8181fi
8282
@@ -92,6 +92,17 @@ if [[ -z "$internalRef" ]]; then
9292 internalRef=" main"
9393fi
9494
95+ echo " ==================== Workflow Dispatch Parameters ===================="
96+ echo " jobName: $jobName "
97+ echo " infraRepoName: $infraRepoName "
98+ echo " releaseVersion: $releaseVersion "
99+ echo " targetWorkflow: $targetWorkflow "
100+ echo " targetEnvironment: $targetEnvironment "
101+ echo " targetComponent: $targetComponent "
102+ echo " targetAccountGroup: $targetAccountGroup "
103+ echo " terraformAction: $terraformAction "
104+ echo " internalRef: $internalRef "
105+ echo " ==============================================================="
95106
96107callerRunId=" ${GITHUB_RUN_ID} -${jobName} -${GITHUB_RUN_ATTEMPT} "
97108
@@ -120,18 +131,22 @@ DISPATCH_EVENT=$(jq -ncM \
120131 )
121132 }' )
122133
123- # Trigger the workflow
124- curl -L \
134+ echo " [INFO] Triggering workflow '$targetWorkflow ' in nhs-notify-internal..."
135+
136+ trigger_response=$( curl -L \
125137 --fail \
126138 --silent \
127139 -X POST \
128140 -H " Accept: application/vnd.github+json" \
129141 -H " Authorization: Bearer ${PR_TRIGGER_PAT} " \
130142 -H " X-GitHub-Api-Version: 2022-11-28" \
131143 " https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/$targetWorkflow /dispatches" \
132- -d " $DISPATCH_EVENT "
133-
134- echo " Workflow triggered. Waiting for the workflow to complete.."
144+ -d " $DISPATCH_EVENT " 2>&1 )
145+ if [[ $? -ne 0 ]]; then
146+ echo " [ERROR] Failed to trigger workflow. Response: $trigger_response "
147+ exit 1
148+ fi
149+ echo " [INFO] Workflow trigger request sent successfully, waiting for completion..."
135150
136151# Poll GitHub API to check the workflow status
137152workflow_run_url=" "
@@ -165,16 +180,16 @@ for _ in {1..18}; do
165180 if [[ -n " $workflow_run_url " && " $workflow_run_url " != null ]]; then
166181 ui_url=${workflow_run_url/ api./ }
167182 ui_url=${ui_url/ \/ repos/ }
168- echo " Found workflow run url: $ui_url "
183+ echo " [INFO] Found workflow run url: $ui_url "
169184 break
170185 fi
171186
172- echo " Waiting for workflow to start..."
187+ echo " [ $( date ' +%Y-%m-%d %H:%M:%S ' ) ] Waiting for workflow to start..."
173188 sleep 10
174189done
175190
176191if [[ -z " $workflow_run_url " || " $workflow_run_url " == null ]]; then
177- echo " Failed to get the workflow run url. Exiting."
192+ echo " [ERROR] Failed to get the workflow run url. Exiting."
178193 exit 1
179194fi
180195
@@ -187,24 +202,26 @@ while true; do
187202 " $workflow_run_url " )
188203
189204 status=$( echo " $response " | jq -r ' .status' )
205+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] Workflow status: $status "
206+
190207 conclusion=$( echo " $response " | jq -r ' .conclusion' )
208+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] Workflow conclusion: $conclusion "
191209
192210 if [ " $status " == " completed" ]; then
193211 if [ -z " $conclusion " ] || [ " $conclusion " == " null" ]; then
194- echo " Workflow marked completed but conclusion not yet available, retrying..."
212+ echo " [WARN] Workflow marked completed but conclusion not yet available, retrying..."
195213 sleep 5
196214 continue
197215 fi
198216
199217 if [ " $conclusion " == " success" ]; then
200- echo " Workflow completed successfully. "
218+ echo " [SUCCESS] Workflow completed successfully! "
201219 exit 0
202220 else
203- echo " Workflow failed with conclusion: $conclusion "
221+ echo " [FAIL] Workflow failed with conclusion: $conclusion "
204222 exit 1
205223 fi
206224 fi
207225
208- echo " Workflow still running..."
209- sleep 20
226+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] Workflow still running..."
210227done
0 commit comments