@@ -3,6 +3,23 @@ name: "2. CD - Deploy"
33on :
44 workflow_dispatch :
55 inputs :
6+ source_type :
7+ description : " Deployment source type"
8+ type : choice
9+ required : true
10+ default : release
11+ options :
12+ - release
13+ - branch
14+ source_value :
15+ description : " Release tag or branch name"
16+ type : string
17+ required : true
18+ deploy_backend :
19+ description : " Deploy backend infrastructure"
20+ type : boolean
21+ required : false
22+ default : true
623 backend_account_group :
724 description : " Target backend account group"
825 type : choice
1229 - dev
1330 - nonprod
1431 - prod
15- backend_environment :
16- description : " Target backend environment "
17- type : string
18- required : true
19- default : main
32+ deploy_proxy :
33+ description : " Deploy APIM proxy "
34+ type : boolean
35+ required : false
36+ default : true
2037 apim_environment :
2138 description : " Target APIM environment"
2239 type : choice
2643 - internal-dev
2744 - int
2845 - prod
29- source_type :
30- description : " Deployment source type"
31- type : choice
32- required : true
33- default : release
34- options :
35- - release
36- - branch
37- - pr
38- source_value :
39- description : " Release tag, branch name, or PR number"
40- type : string
41- required : true
46+ build_sandbox :
47+ description : " Build sandbox container"
48+ type : boolean
49+ required : false
50+ default : false
4251
4352run-name : >-
44- Deploy backend=${{ inputs.backend_account_group }}/ ${{ inputs.backend_environment }}
45- apim =${{ inputs.apim_environment }}
46- source=${{ inputs.source_type }}:${{ inputs.source_value }} by @${{ github.actor }}
53+ Deploy backend=${{ inputs.backend_account_group }} apim= ${{
54+ inputs.apim_environment }} source =${{ inputs.source_type }}:${{
55+ inputs.source_value }} by @${{ github.actor }}
4756
4857permissions :
4958 id-token : write
5059 contents : read
5160 packages : read
5261
5362jobs :
54- validate :
55- name : Validate deployment request
56- runs-on : ubuntu-latest
57- timeout-minutes : 5
58- outputs :
59- release_version : ${{ steps.validate.outputs.release_version }}
60- is_release : ${{ steps.validate.outputs.is_release }}
61- build_artifact_version : ${{ steps.validate.outputs.build_artifact_version }}
62- target_account_group : ${{ steps.validate.outputs.target_account_group }}
63- target_environment : ${{ steps.validate.outputs.target_environment }}
64- apim_environment : ${{ steps.validate.outputs.apim_environment }}
65- steps :
66- - name : Validate inputs and resolve source
67- id : validate
68- shell : bash
69- env :
70- GH_TOKEN : ${{ github.token }}
71- run : |
72- set -euo pipefail
73-
74- backend_account_group="${{ inputs.backend_account_group }}"
75- backend_environment="${{ inputs.backend_environment }}"
76- apim_environment="${{ inputs.apim_environment }}"
77- source_type="${{ inputs.source_type }}"
78- source_value="${{ inputs.source_value }}"
79-
80- if [[ -z "$source_value" ]]; then
81- echo "[ERROR] source_value cannot be empty."
82- exit 1
83- fi
84-
85- if [[ "$backend_account_group" == "prod" && "$apim_environment" != "prod" ]]; then
86- echo "[ERROR] PROD backend and PROD APIM can only be deployed together."
87- exit 1
88- fi
89-
90- if [[ "$apim_environment" == "prod" && "$backend_account_group" != "prod" ]]; then
91- echo "[ERROR] PROD backend and PROD APIM can only be deployed together."
92- exit 1
93- fi
94-
95- is_release="false"
96- release_version="$source_value"
97-
98- if [[ "$source_type" == "release" ]]; then
99- if [[ ! "$source_value" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+([-.+][0-9A-Za-z.-]+)?$ ]]; then
100- echo "[ERROR] Release tags must be semantic versions, for example v1.2.3."
101- exit 1
102- fi
103-
104- gh release view "$source_value" --repo "$GITHUB_REPOSITORY" >/dev/null
105-
106- oas_asset="api-oas-specification-${apim_environment}-${source_value}.zip"
107- gh release view "$source_value" --repo "$GITHUB_REPOSITORY" --json assets \
108- --jq '.assets[].name' | grep -x "$oas_asset" >/dev/null
109-
110- is_release="true"
111- elif [[ "$source_type" == "branch" ]]; then
112- if [[ "$backend_account_group" != "dev" ]]; then
113- echo "[ERROR] Branch deployments are only allowed for dev backend deployments."
114- exit 1
115- fi
116-
117- branch_matches=$(gh api "repos/${GITHUB_REPOSITORY}/git/matching-refs/heads/${source_value}" --jq 'length')
118- if [[ "$branch_matches" -eq 0 ]]; then
119- echo "[ERROR] Branch '$source_value' not found in repository."
120- exit 1
121- fi
122- elif [[ "$source_type" == "pr" ]]; then
123- if [[ "$backend_account_group" != "dev" ]]; then
124- echo "[ERROR] PR deployments are only allowed for dev backend deployments."
125- exit 1
126- fi
127-
128- if [[ ! "$source_value" =~ ^[0-9]+$ ]]; then
129- echo "[ERROR] PR source_value must be a numeric PR number."
130- exit 1
131- fi
132-
133- release_version=$(gh pr view "$source_value" --repo "$GITHUB_REPOSITORY" --json headRefName --jq '.headRefName')
134- if [[ -z "$release_version" || "$release_version" == "null" ]]; then
135- echo "[ERROR] PR #$source_value was not found."
136- exit 1
137- fi
138- else
139- echo "[ERROR] Unsupported source type '$source_type'."
140- exit 1
141- fi
142-
143- if [[ "$backend_account_group" == "nonprod" || "$backend_account_group" == "prod" ]]; then
144- if [[ "$is_release" != "true" ]]; then
145- echo "[ERROR] Only tagged releases can be deployed to NONPROD and PROD backends."
146- exit 1
147- fi
148- fi
149-
150- case "$backend_account_group" in
151- dev)
152- target_account_group="nhs-notify-supplier-api-dev"
153- ;;
154- nonprod)
155- target_account_group="nhs-notify-supplier-api-nonprod"
156- ;;
157- prod)
158- target_account_group="nhs-notify-supplier-api-prod"
159- ;;
160- *)
161- echo "[ERROR] Unsupported backend account group '$backend_account_group'."
162- exit 1
163- ;;
164- esac
165-
166- build_artifact_version=""
167- if [[ "$is_release" != "true" ]]; then
168- build_artifact_version="manual"
169- fi
170-
171- echo "release_version=$release_version" >> "$GITHUB_OUTPUT"
172- echo "is_release=$is_release" >> "$GITHUB_OUTPUT"
173- echo "build_artifact_version=$build_artifact_version" >> "$GITHUB_OUTPUT"
174- echo "target_account_group=$target_account_group" >> "$GITHUB_OUTPUT"
175- echo "target_environment=$backend_environment" >> "$GITHUB_OUTPUT"
176- echo "apim_environment=$apim_environment" >> "$GITHUB_OUTPUT"
177-
178- deploy-backend :
179- name : Deploy backend
180- runs-on : ubuntu-latest
181- timeout-minutes : 30
182- needs : validate
183- steps :
184- - name : Checkout repository
185- uses : actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
186-
187- - name : Deploy backend environment
188- env :
189- APP_CLIENT_ID : ${{ secrets.APP_CLIENT_ID }}
190- APP_PEM_FILE : ${{ secrets.APP_PEM_FILE }}
191- run : |
192- bash .github/scripts/dispatch_internal_repo_workflow.sh \
193- --releaseVersion "${{ needs.validate.outputs.release_version }}" \
194- --targetWorkflow "dispatch-deploy-static-notify-supplier-api-env.yaml" \
195- --targetEnvironment "${{ needs.validate.outputs.target_environment }}" \
196- --targetAccountGroup "${{ needs.validate.outputs.target_account_group }}" \
197- --targetComponent "api" \
198- --terraformAction "apply"
199-
200- deploy-proxy :
201- name : Deploy proxy
202- runs-on : ubuntu-latest
203- timeout-minutes : 30
204- needs : [validate, deploy-backend]
205- steps :
206- - name : Build OAS spec for non-release source
207- if : ${{ needs.validate.outputs.is_release != 'true' }}
208- uses : ./.github/actions/build-oas-spec
209- with :
210- version : ${{ needs.validate.outputs.build_artifact_version }}
211- apimEnv : ${{ needs.validate.outputs.apim_environment }}
212- nodejs_version : " 22.22.0"
213- NODE_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
214-
215- - name : Deploy proxy
216- env :
217- PROXYGEN_API_NAME : nhs-notify-supplier
218- APP_CLIENT_ID : ${{ secrets.APP_CLIENT_ID }}
219- APP_PEM_FILE : ${{ secrets.APP_PEM_FILE }}
220- uses : ./.github/actions/build-proxies
221- with :
222- targetComponent : api
223- environment : ${{ needs.validate.outputs.target_environment }}
224- apimEnv : ${{ needs.validate.outputs.apim_environment }}
225- runId : " ${{ github.run_id }}"
226- releaseVersion : ${{ needs.validate.outputs.release_version }}
227- isRelease : ${{ needs.validate.outputs.is_release }}
228- version : ${{ needs.validate.outputs.build_artifact_version }}
63+ deploy :
64+ uses : ./.github/workflows/deploy-supplier-api.yaml
65+ secrets : inherit
66+ with :
67+ backend_account_group : ${{ inputs.backend_account_group }}
68+ apim_environment : ${{ inputs.apim_environment }}
69+ source_type : ${{ inputs.source_type }}
70+ source_value : ${{ inputs.source_value }}
71+ deploy_backend : ${{ inputs.deploy_backend }}
72+ deploy_proxy : ${{ inputs.deploy_proxy }}
73+ build_sandbox : ${{ inputs.build_sandbox }}
0 commit comments