66# ./dispatch_internal_repo_workflow.sh \
77# --infraRepoName <repo> \
88# --releaseVersion <version> \
9- # --targetWorkflow <workflow .yaml> \
9+ # --targetWorkflow "deploy .yaml" \
1010# --targetEnvironment <env> \
1111# --targetComponent <component> \
1212# --targetAccountGroup <group> \
1717# --overrideRoleName <name>
1818
1919#
20- # All arguments are required except terraformAction, and internalRef.
20+ # Required arguments are:
21+ # infraRepoName, releaseVersion, targetWorkflow, targetEnvironment, targetComponent, targetAccountGroup.
22+ #
23+ # All other arguments are optional.
24+ #
2125# Example:
2226# ./dispatch_internal_repo_workflow.sh \
2327# --infraRepoName "nhs-notify-web-template-management" \
3034# --internalRef "main" \
3135# --overrides "tf_var=someString" \
3236# --overrideProjectName nhs \
33- # --overrideRoleName nhs-service-iam-role
37+ # --overrideRoleName nhs-service-iam-role \
38+ # --extraSecretNames '["MY_API_KEY"]'
39+
3440
3541set -e
3642
@@ -104,6 +110,10 @@ while [[ $# -gt 0 ]]; do
104110 version=" $2 "
105111 shift 2
106112 ;;
113+ --extraSecretNames) # JSON array of secret names to fetch in the internal repo (optional)
114+ extraSecretNames=" $2 "
115+ shift 2
116+ ;;
107117 * )
108118 echo " [ERROR] Unknown argument: $1 "
109119 exit 1
@@ -202,6 +212,10 @@ if [[ -z "$version" ]]; then
202212 version=" "
203213fi
204214
215+ if [[ -z " $extraSecretNames " ]]; then
216+ extraSecretNames=" "
217+ fi
218+
205219echo " ==================== Workflow Dispatch Parameters ===================="
206220echo " infraRepoName: $infraRepoName "
207221echo " releaseVersion: $releaseVersion "
@@ -240,6 +254,7 @@ DISPATCH_EVENT=$(jq -ncM \
240254 --arg boundedContext " $boundedContext " \
241255 --arg targetDomain " $targetDomain " \
242256 --arg version " $version " \
257+ --argjson extraSecretNames " ${extraSecretNames:- null} " \
243258 ' {
244259 "ref": "' " $internalRef " ' ",
245260 "inputs": (
@@ -255,6 +270,7 @@ DISPATCH_EVENT=$(jq -ncM \
255270 (if $boundedContext != "" then { "boundedContext": $boundedContext } else {} end) +
256271 (if $targetDomain != "" then { "targetDomain": $targetDomain } else {} end) +
257272 (if $version != "" then { "version": $version } else {} end) +
273+ (if $extraSecretNames != null then { "extraSecretNames": ($extraSecretNames | tojson) } else {} end) +
258274 (if $targetAccountGroup != "" then { "targetAccountGroup": $targetAccountGroup } else {} end) +
259275 {
260276 "releaseVersion": $releaseVersion,
@@ -269,16 +285,22 @@ echo "[INFO] Triggering workflow '$targetWorkflow' in nhs-notify-internal..."
269285echo " [DEBUG] Dispatch event payload: $DISPATCH_EVENT "
270286
271287trigger_response=$( curl -s -L \
272- --fail \
288+ -w " \nHTTP_STATUS:%{http_code} " \
273289 -X POST \
274290 -H " Accept: application/vnd.github+json" \
275291 -H " Authorization: Bearer ${PR_TRIGGER_PAT} " \
276292 -H " X-GitHub-Api-Version: 2022-11-28" \
277293 " https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/$targetWorkflow /dispatches" \
278294 -d " $DISPATCH_EVENT " 2>&1 )
279295
280- if [[ $? -ne 0 ]]; then
281- echo " [ERROR] Failed to trigger workflow. Response: $trigger_response "
296+ http_status=$( echo " $trigger_response " | grep " HTTP_STATUS:" | cut -d: -f2)
297+ body=$( echo " $trigger_response " | grep -v " HTTP_STATUS:" )
298+
299+ echo " [DEBUG] HTTP status: $http_status "
300+ echo " [DEBUG] Response body: $body "
301+
302+ if [[ " $http_status " -lt 200 || " $http_status " -ge 300 ]]; then
303+ echo " [ERROR] Failed to trigger workflow. HTTP $http_status . Response: $body "
282304 exit 1
283305fi
284306
0 commit comments