Skip to content

Commit

Permalink
CCM-5836 adding Pr workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenvaines-bjss committed Jul 22, 2024
1 parent 608550d commit 36b2105
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/pr_create_dynamic_env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: PR Create Environment

on:
pull_request:
types: [labeled, opened, synchronize, reopened, unlabeled, edited]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
create-dynamic-environment:
name: Create Dynamic Environment
runs-on: ubuntu-latest

steps:
- name: Trigger nhs-notify-internal dynamic environment workflow
shell: bash
run: |
set -x
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
DISPATCH_EVENT=$(jq -ncM \
--arg infraRepoName "${this_repo_name}" \
--arg releaseVersion "${{ github.ref_name }}" \
--arg targetEnvironment "pr${{ github.event.number }}" \
--arg targetAccountGroup "nhs-notify-iam-dev" \
--arg targetComponent "branch" \
--arg terraformAction "apply" \
--arg overrides "branch_name=${{ github.ref_name }}" \
'{ "ref": "main",
"inputs": {
"infraRepoName": $infraRepoName,
"releaseVersion", $releaseVersion,
"targetEnvironment", $targetEnvironment,
"targetAccountGroup", $targetAccountGroup,
"targetComponent", $targetComponent,
"terraformAction", $terraformAction,
"overrides", $overrides,
}
}')
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \
-d "${DISPATCH_EVENT}"
85 changes: 85 additions & 0 deletions .github/workflows/pr_merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: PR Merged

on:
pull_request:
types: [closed]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
destroy-dynamic-environment:
name: Destroy Dynamic Environment
runs-on: ubuntu-latest

steps:
- name: Trigger nhs-notify-internal dynamic environment workflow
shell: bash
run: |
set -x
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
DISPATCH_EVENT=$(jq -ncM \
--arg infraRepoName "${this_repo_name}" \
--arg releaseVersion "${{ github.ref_name }}" \
--arg targetEnvironment "pr${{ github.event.number }}" \
--arg targetAccountGroup "nhs-notify-iam-dev" \
--arg targetComponent "branch" \
--arg terraformAction "destroy" \
--arg overrides "branch_name=${{ github.ref_name }}" \
'{ "ref": "main",
"inputs": {
"infraRepoName": $infraRepoName,
"releaseVersion", $releaseVersion,
"targetEnvironment", $targetEnvironment,
"targetAccountGroup", $targetAccountGroup,
"targetComponent", $targetComponent,
"terraformAction", $terraformAction,
"overrides", $overrides,
}
}')
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \
-d "${DISPATCH_EVENT}"
deploy-main:
name: Deploy changes to main
runs-on: ubuntu-latest
steps:
- name: Trigger nhs-notify-internal static environment workflow deployment
shell: bash
run: |
set -x
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
DISPATCH_EVENT=$(jq -ncM \
--arg infraRepoName "${this_repo_name}" \
--arg releaseVersion "main" \
--arg targetEnvironment "main" \
--arg targetAccountGroup "nhs-notify-iam-dev" \
--arg targetComponent "branch" \
--arg terraformAction "apply" \
'{ "ref": "main",
"inputs": {
"infraRepoName": $infraRepoName,
"releaseVersion", $releaseVersion,
"targetEnvironment", $targetEnvironment,
"targetAccountGroup", $targetAccountGroup,
"targetComponent", $targetComponent,
"terraformAction", $terraformAction
}
}')
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-static-env.yaml/dispatches \
-d "${DISPATCH_EVENT}"

0 comments on commit 36b2105

Please sign in to comment.