Skip to content

Commit 44a4b09

Browse files
Feature/CCM-10193 Use GitHub app token to trigger deployment pipeline (#734)
Signed-off-by: Tim Ireland <[email protected]> Co-authored-by: Mark Ramsden <[email protected]>
1 parent bb39004 commit 44a4b09

File tree

7 files changed

+69
-8
lines changed

7 files changed

+69
-8
lines changed

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,60 @@ while [[ $# -gt 0 ]]; do
8686
;;
8787
esac
8888
done
89+
# Validate required parameters
90+
if [[ -z "$APP_PEM_FILE" ]]; then
91+
echo "[ERROR] PEM_FILE environment variable is not set or is empty."
92+
exit 1
93+
fi
94+
95+
if [[ -z "$APP_CLIENT_ID" ]]; then
96+
echo "[ERROR] CLIENT_ID environment variable is not set or is empty."
97+
exit 1
98+
fi
99+
100+
now=$(date +%s)
101+
iat=$((${now} - 60)) # Issues 60 seconds in the past
102+
exp=$((${now} + 600)) # Expires 10 minutes in the future
103+
104+
b64enc() { openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n'; }
105+
106+
header_json='{
107+
"typ":"JWT",
108+
"alg":"RS256"
109+
}'
110+
# Header encode
111+
header=$( echo -n "${header_json}" | b64enc )
112+
113+
payload_json="{
114+
\"iat\":${iat},
115+
\"exp\":${exp},
116+
\"iss\":\"${APP_CLIENT_ID}\"
117+
}"
118+
# Payload encode
119+
payload=$( echo -n "${payload_json}" | b64enc )
120+
121+
# Signature
122+
header_payload="${header}"."${payload}"
123+
signature=$(
124+
openssl dgst -sha256 -sign <(echo -n "${APP_PEM_FILE}") \
125+
<(echo -n "${header_payload}") | b64enc
126+
)
127+
128+
# Create JWT
129+
JWT="${header_payload}"."${signature}"
130+
131+
INSTALLATION_ID=$(curl -X GET \
132+
-H "Accept: application/vnd.github+json" \
133+
-H "Authorization: Bearer ${JWT}" \
134+
-H "X-GitHub-Api-Version: 2022-11-28" \
135+
--url "https://api.github.com/app/installations" | jq -r '.[0].id')
136+
137+
PR_TRIGGER_PAT=$(curl --request POST \
138+
--url "https://api.github.com/app/installations/${INSTALLATION_ID}/access_tokens" \
139+
-H "Accept: application/vnd.github+json" \
140+
-H "Authorization: Bearer ${JWT}" \
141+
-H "X-GitHub-Api-Version: 2022-11-28" | jq -r '.token')
142+
89143

90144
# Set default values if not provided
91145
if [[ -z "$PR_TRIGGER_PAT" ]]; then

.github/workflows/pr_closed.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ jobs:
5252

5353
- name: Updating Main Environment
5454
env:
55-
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
55+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
56+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
5657
run: |
5758
bash .github/scripts/dispatch_internal_repo_workflow.sh \
5859
--releaseVersion "main" \

.github/workflows/pr_create_dynamic_env.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ jobs:
2020
- uses: actions/[email protected]
2121
- name: Trigger dynamic environment creation
2222
env:
23-
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
23+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
24+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
2425
shell: bash
2526
run: |
2627
.github/scripts/dispatch_internal_repo_workflow.sh \

.github/workflows/pr_destroy_dynamic_env.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121

2222
- name: Trigger dynamic environment destruction
2323
env:
24-
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
24+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
25+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
2526
shell: bash
2627
run: |
2728
.github/scripts/dispatch_internal_repo_workflow.sh \
@@ -42,7 +43,8 @@ jobs:
4243
- name: Trigger sandbox environment destruction
4344
shell: bash
4445
env:
45-
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
46+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
47+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
4648
run: |
4749
.github/scripts/dispatch_internal_repo_workflow.sh \
4850
--infraRepoName "nhs-notify-web-template-management" \

.github/workflows/release_created.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ jobs:
2828

2929
- name: Deploy Nonprod Environment
3030
env:
31-
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
31+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
32+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
3233
run: |
3334
bash .github/scripts/dispatch_internal_repo_workflow.sh \
3435
--releaseVersion "${{ github.event.release.tag_name }}" \

.github/workflows/stage-4-acceptance.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jobs:
2222
- name: Trigger Sandbox Environment Build
2323
shell: bash
2424
env:
25-
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
25+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
26+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
2627
run: |
2728
.github/scripts/dispatch_internal_repo_workflow.sh \
2829
--infraRepoName "nhs-notify-web-template-management" \
@@ -36,7 +37,8 @@ jobs:
3637
- name: Trigger Acceptance Tests
3738
shell: bash
3839
env:
39-
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
40+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
41+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
4042
run: |
4143
.github/scripts/dispatch_internal_repo_workflow.sh \
4244
--infraRepoName "nhs-notify-web-template-management" \

tests/test-team/template-mgmt-routing-component-tests/message-plans.routing-component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function createRoutingConfigs(): Promise<MessagePlansPageData> {
2626
draftNew: RoutingConfigFactory.create(user).dbEntry,
2727
draftOld: {
2828
...RoutingConfigFactory.create(user).dbEntry,
29-
createdAt: new Date('2020-10-09T00:00:00.000Z').toISOString(),
29+
updatedAt: new Date('2020-10-09T00:00:00.000Z').toISOString(),
3030
},
3131
production: RoutingConfigFactory.create(user, { status: 'COMPLETED' })
3232
.dbEntry,

0 commit comments

Comments
 (0)