Skip to content

Commit a0fc562

Browse files
CCM-11942 Fixing cross repo workflows
1 parent 33f4774 commit a0fc562

5 files changed

Lines changed: 41 additions & 9 deletions

File tree

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@
1111
# --targetComponent <component> \
1212
# --targetAccountGroup <group> \
1313
# --terraformAction <action> \
14-
# --internalRef <ref>
14+
# --internalRef <ref> \
15+
# --overrides <overrides> \
16+
# --overrideProjectName <name> \
17+
# --overrideRoleName <name>
18+
1519
#
1620
# All arguments are required except terraformAction, and internalRef.
1721
# Example:
1822
# ./dispatch_internal_repo_workflow.sh \
19-
# --infraRepoName "nhs-notify-iam-webauth" \
23+
# --infraRepoName "nhs-notify-web-template-management" \
2024
# --releaseVersion "v1.2.3" \
2125
# --targetWorkflow "deploy.yaml" \
2226
# --targetEnvironment "prod" \
2327
# --targetComponent "web" \
2428
# --targetAccountGroup "core" \
2529
# --terraformAction "apply" \
26-
# --internalRef "main"
30+
# --internalRef "main" \
31+
# --overrides "tf_var=someString" \
32+
# --overrideProjectName nhs \
33+
# --overrideRoleName nhs-service-iam-role
2734

2835
set -e
2936

@@ -65,6 +72,14 @@ while [[ $# -gt 0 ]]; do
6572
overrides="$2"
6673
shift 2
6774
;;
75+
--overrideProjectName) # Override the project name (optional)
76+
overrideProjectName="$2"
77+
shift 2
78+
;;
79+
--overrideRoleName) # Override the role name (optional)
80+
overrideRoleName="$2"
81+
shift 2
82+
;;
6883
*)
6984
echo "[ERROR] Unknown argument: $1"
7085
exit 1
@@ -96,6 +111,9 @@ echo " targetAccountGroup: $targetAccountGroup"
96111
echo " terraformAction: $terraformAction"
97112
echo " internalRef: $internalRef"
98113
echo " overrides: $overrides"
114+
echo " overrideProjectName: $overrideProjectName"
115+
echo " overrideRoleName: $overrideRoleName"
116+
echo " targetProject: $targetProject"
99117

100118
DISPATCH_EVENT=$(jq -ncM \
101119
--arg infraRepoName "$infraRepoName" \
@@ -106,11 +124,17 @@ DISPATCH_EVENT=$(jq -ncM \
106124
--arg terraformAction "$terraformAction" \
107125
--arg targetWorkflow "$targetWorkflow" \
108126
--arg overrides "$overrides" \
127+
--arg overrideProjectName "$overrideProjectName" \
128+
--arg overrideRoleName "$overrideRoleName" \
129+
--arg targetProject "$targetProject" \
109130
'{
110131
"ref": "'"$internalRef"'",
111132
"inputs": (
112133
(if $infraRepoName != "" then { "infraRepoName": $infraRepoName } else {} end) +
113134
(if $terraformAction != "" then { "terraformAction": $terraformAction } else {} end) +
135+
(if $overrideProjectName != "" then { "overrideProjectName": $overrideProjectName } else {} end) +
136+
(if $overrideRoleName != "" then { "overrideRoleName": $overrideRoleName } else {} end) +
137+
(if $targetProject != "" then { "targetProject": $targetProject } else {} end) +
114138
{
115139
"releaseVersion": $releaseVersion,
116140
"targetEnvironment": $targetEnvironment,
@@ -123,7 +147,6 @@ DISPATCH_EVENT=$(jq -ncM \
123147

124148
echo "[INFO] Triggering workflow '$targetWorkflow' in nhs-notify-internal..."
125149

126-
set -x
127150
trigger_response=$(curl -s -L \
128151
--fail \
129152
-X POST \
@@ -132,7 +155,6 @@ trigger_response=$(curl -s -L \
132155
-H "X-GitHub-Api-Version: 2022-11-28" \
133156
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/$targetWorkflow/dispatches" \
134157
-d "$DISPATCH_EVENT" 2>&1)
135-
set +x
136158

137159
if [[ $? -ne 0 ]]; then
138160
echo "[ERROR] Failed to trigger workflow. Response: $trigger_response"
@@ -147,6 +169,7 @@ sleep 10 # Wait a few seconds before checking for the presence of the api to acc
147169
workflow_run_url=""
148170

149171
for _ in {1..18}; do
172+
150173
response=$(curl -s -L \
151174
-H "Accept: application/vnd.github+json" \
152175
-H "Authorization: Bearer ${PR_TRIGGER_PAT}" \

.github/workflows/pr_closed.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ jobs:
6060
--targetEnvironment "main" \
6161
--targetAccountGroup "nhs-notify-supplier-api-dev" \
6262
--targetComponent "${{ matrix.component }}" \
63-
--terraformAction "apply"
63+
--terraformAction "apply" \
64+
--overrideProjectName "nhs" \
65+
--overrideRoleName "nhs-main-acct-supplier-api-github-deploy"

.github/workflows/pr_create_dynamic_env.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ jobs:
3131
--targetEnvironment "pr${{ github.event.number }}" \
3232
--targetComponent "api" \
3333
--targetAccountGroup "nhs-notify-supplier-api-dev" \
34-
--terraformAction "apply"
34+
--terraformAction "apply" \
35+
--overrideProjectName "nhs" \
36+
--overrideRoleName "nhs-main-acct-supplier-api-github-deploy"

.github/workflows/pr_destroy_dynamic_env.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ jobs:
2727
--targetWorkflow "dispatch-deploy-dynamic-env.yaml" \
2828
--targetEnvironment "pr${{ github.event.number }}" \
2929
--targetComponent "api" \
30-
--targetAccountGroup "nhs-notify-supplier-api-dev"
30+
--targetAccountGroup "nhs-notify-supplier-api-dev" \
31+
--terraformAction "destroy" \
32+
--overrideProjectName "nhs" \
33+
--overrideRoleName "nhs-main-acct-supplier-api-github-deploy"

.github/workflows/release_created.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ jobs:
3636
--targetEnvironment "main" \
3737
--targetAccountGroup "nhs-notify-supplier-api-nonprod" \
3838
--targetComponent "${{ matrix.component }}" \
39-
--terraformAction "apply"
39+
--terraformAction "apply" \
40+
--overrideProjectName "nhs" \
41+
--overrideRoleName "nhs-main-acct-supplier-api-github-deploy"

0 commit comments

Comments
 (0)