Skip to content

Commit cbbd317

Browse files
committed
CCM-10294: review
1 parent 4bd8a44 commit cbbd317

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

.github/workflows/pr_closed.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: PR Closed
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [closed]
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: false
13+
14+
jobs:
15+
check-merge-or-workflow-dispatch:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
deploy: ${{ steps.check.outputs.deploy }}
19+
steps:
20+
- name: Check if PR was merged or workflow is triggered by workflow_dispatch
21+
id: check
22+
run: |
23+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
24+
echo "deploy=true" >> $GITHUB_OUTPUT
25+
echo "Job triggered by workflow_dispatch - running 'deploy-main'"
26+
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
27+
echo "deploy=true" >> $GITHUB_OUTPUT
28+
echo "Job triggered by Merged PR - running 'deploy-main'"
29+
else
30+
echo "deploy=false" >> $GITHUB_OUTPUT
31+
echo "Job not triggered by workflow_dispatch or Merged PR - Skipping 'deploy-main'"
32+
fi
33+
34+
deploy-main:
35+
needs: check-merge-or-workflow-dispatch
36+
name: Deploy changes to main in dev AWS account
37+
if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
38+
39+
permissions:
40+
id-token: write
41+
contents: read
42+
43+
strategy:
44+
max-parallel: 1
45+
matrix:
46+
component: [acct, app]
47+
48+
uses: ./.github/workflows/reusable_internal_repo_build.yaml
49+
secrets: inherit
50+
with:
51+
releaseVersion: main
52+
targetWorkflow: "dispatch-deploy-static-notify-web-template-management-env.yaml"
53+
targetEnvironment: "main"
54+
targetAccountGroup: "nhs-notify-template-management-dev"
55+
targetComponent: ${{ matrix.component }}
56+
terraformAction: "apply"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
name: PR Create Environment
3+
4+
on:
5+
pull_request:
6+
types: [labeled, opened, synchronize, reopened, unlabeled, edited]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: false
11+
12+
jobs:
13+
create-dynamic-environment:
14+
name: Create Dynamic Environment
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Trigger nhs-notify-internal dynamic environment workflow
19+
shell: bash
20+
run: |
21+
set -x
22+
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
23+
24+
DISPATCH_EVENT=$(jq -ncM \
25+
--arg infraRepoName "${this_repo_name}" \
26+
--arg releaseVersion "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
27+
--arg targetEnvironment "pr${{ github.event.number }}" \
28+
--arg targetAccountGroup "nhs-notify-template-management-dev" \
29+
--arg targetComponent "branch" \
30+
--arg terraformAction "apply" \
31+
--arg overrides "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \
32+
'{ "ref": "main",
33+
"inputs": {
34+
"infraRepoName": $infraRepoName,
35+
"releaseVersion", $releaseVersion,
36+
"targetEnvironment", $targetEnvironment,
37+
"targetAccountGroup", $targetAccountGroup,
38+
"targetComponent", $targetComponent,
39+
"terraformAction", $terraformAction,
40+
"overrides", $overrides,
41+
}
42+
}')
43+
44+
curl --fail -L \
45+
-X POST \
46+
-H "Accept: application/vnd.github+json" \
47+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
48+
-H "X-GitHub-Api-Version: 2022-11-28" \
49+
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \
50+
-d "${DISPATCH_EVENT}"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: PR Destroy Environment
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
create-dynamic-environment:
13+
name: Destroy Dynamic Environment
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Trigger nhs-notify-internal dynamic environment destruction
18+
shell: bash
19+
run: |
20+
set -x
21+
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
22+
23+
DISPATCH_EVENT=$(jq -ncM \
24+
--arg infraRepoName "${this_repo_name}" \
25+
--arg releaseVersion "main" \
26+
--arg targetEnvironment "pr${{ github.event.number }}" \
27+
--arg targetAccountGroup "nhs-notify-template-management-dev" \
28+
--arg targetComponent "branch" \
29+
--arg terraformAction "destroy" \
30+
'{ "ref": "main",
31+
"inputs": {
32+
"infraRepoName": $infraRepoName,
33+
"releaseVersion", $releaseVersion,
34+
"targetEnvironment", $targetEnvironment,
35+
"targetAccountGroup", $targetAccountGroup,
36+
"targetComponent", $targetComponent,
37+
"terraformAction", $terraformAction,
38+
}
39+
}')
40+
41+
curl --fail -L \
42+
-X POST \
43+
-H "Accept: application/vnd.github+json" \
44+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
45+
-H "X-GitHub-Api-Version: 2022-11-28" \
46+
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \
47+
-d "${DISPATCH_EVENT}"

0 commit comments

Comments
 (0)