Skip to content

Commit 78a6b21

Browse files
Merge branch 'main' into feature/CCM-17208_Supplier_api_pact_tests
2 parents a47eb1d + 4c99b67 commit 78a6b21

7 files changed

Lines changed: 468 additions & 223 deletions

.github/workflows/cicd-3-deploy.yaml

Lines changed: 62 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,112 +3,72 @@ name: "2. CD - Deploy"
33
on:
44
workflow_dispatch:
55
inputs:
6-
include_prereleases:
6+
source_type:
7+
description: "Deployment source type"
78
type: choice
8-
description: "Include pre-releases"
9-
default: "true"
9+
required: true
10+
default: release
1011
options:
11-
- "true"
12-
- "false"
13-
version:
14-
type: string
15-
default: latest
16-
description: "Install specific version"
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
23+
backend_account_group:
24+
description: "Target backend account group"
25+
type: choice
26+
required: true
27+
default: dev
28+
options:
29+
- dev
30+
- nonprod
31+
- prod
32+
deploy_proxy:
33+
description: "Deploy APIM proxy"
34+
type: boolean
35+
required: false
36+
default: true
37+
apim_environment:
38+
description: "Target APIM environment"
39+
type: choice
40+
required: true
41+
default: internal-dev
42+
options:
43+
- internal-dev
44+
- int
45+
- prod
46+
build_sandbox:
47+
description: "Build sandbox container"
48+
type: boolean
49+
required: false
50+
default: false
51+
52+
run-name: >-
53+
Deploy ${{ inputs.deploy_backend && format('backend={0}',
54+
inputs.backend_account_group) || '' }} ${{ inputs.deploy_proxy &&
55+
format('apim={0}', inputs.apim_environment) || '' }} source=${{
56+
inputs.source_type }}:${{ inputs.source_value }} by @${{ github.actor }}
1757
18-
run-name: "Include prerelease: ${{ inputs.include_prereleases }} Version: ${{ inputs.version }} by @${{ github.actor }}"
1958
permissions:
20-
contents: read
21-
pages: write
2259
id-token: write
60+
contents: read
61+
packages: read
2362

2463
jobs:
25-
metadata:
26-
name: "Set CI/CD metadata"
27-
runs-on: ubuntu-latest
28-
timeout-minutes: 1
29-
outputs:
30-
build_datetime: ${{ steps.variables.outputs.build_datetime }}
31-
build_timestamp: ${{ steps.variables.outputs.build_timestamp }}
32-
build_epoch: ${{ steps.variables.outputs.build_epoch }}
33-
nodejs_version: ${{ steps.variables.outputs.nodejs_version }}
34-
python_version: ${{ steps.variables.outputs.python_version }}
35-
terraform_version: ${{ steps.variables.outputs.terraform_version }}
36-
version: ${{ steps.variables.outputs.version }}
37-
# tag: ${{ steps.variables.outputs.tag }}
38-
steps:
39-
- name: "Checkout code"
40-
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
41-
- name: "Set CI/CD variables"
42-
id: variables
43-
run: |
44-
datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z')
45-
echo "build_datetime=$datetime" >> $GITHUB_OUTPUT
46-
echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
47-
echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT
48-
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
49-
echo "python_version=$(grep "^python\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
50-
echo "terraform_version=$(grep "^terraform\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
51-
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT
52-
# echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
53-
- name: "List variables"
54-
run: |
55-
export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}"
56-
export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}"
57-
export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}"
58-
export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}"
59-
export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}"
60-
export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}"
61-
export VERSION="${{ steps.variables.outputs.version }}"
62-
# export TAG="${{ steps.variables.outputs.tag }}"
63-
make list-variables
64-
65-
deploy-jekyll:
66-
environment:
67-
name: github-pages
68-
url: ${{ steps.deployment.outputs.page_url }}
69-
runs-on: ubuntu-latest
70-
needs: metadata
71-
steps:
72-
- name: "Checkout code"
73-
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
74-
- name: "Get version"
75-
id: get-asset-version
76-
shell: bash
77-
env:
78-
GH_TOKEN: ${{ github.token }}
79-
run: |
80-
if [[ ${{inputs.include_prereleases}} == true ]]; then
81-
json=$(gh release list --json tagName --limit 1 --exclude-drafts)
82-
else
83-
json=$(gh release list --json tagName --limit 1 --exclude-drafts --exclude-pre-releases)
84-
fi
85-
86-
echo $json
87-
88-
release_version=$(echo $json | (jq -r '.[0].tagName'))
89-
if [[ $release_version == null ]]; then exit 1; else echo $release_version; fi
90-
91-
if [[ ${{inputs.version}} == latest ]]; then
92-
echo release_version=$(echo $release_version) >> $GITHUB_OUTPUT
93-
else
94-
echo release_version=$(echo ${{inputs.version}}) >> $GITHUB_OUTPUT
95-
fi
96-
97-
- name: "Get release version"
98-
id: download-asset
99-
shell: bash
100-
env:
101-
GH_TOKEN: ${{ github.token }}
102-
run: |
103-
gh release download ${{steps.get-asset-version.outputs.release_version}} -p jekyll-docs-*.tar --output artifact.tar
104-
105-
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
106-
with:
107-
name: jekyll-docs-${{steps.get-asset-version.outputs.release_version}}
108-
path: artifact.tar
109-
110-
- name: Deploy to GitHub Pages
111-
id: deployment
112-
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4
113-
with:
114-
artifact_name: jekyll-docs-${{steps.get-asset-version.outputs.release_version}}
64+
deploy:
65+
uses: ./.github/workflows/deploy-supplier-api.yaml
66+
secrets: inherit
67+
with:
68+
backend_account_group: ${{ inputs.backend_account_group }}
69+
apim_environment: ${{ inputs.apim_environment }}
70+
source_type: ${{ inputs.source_type }}
71+
source_value: ${{ inputs.source_value }}
72+
deploy_backend: ${{ inputs.deploy_backend }}
73+
deploy_proxy: ${{ inputs.deploy_proxy }}
74+
build_sandbox: ${{ inputs.build_sandbox }}
Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
name: Deploy proxy to environment
2-
run-name: Proxygen Deployment for ${{ inputs.proxy_environment }}
1+
name: Deploy dynamic PR environment proxy
2+
run-name: Deploy proxy for PR environment on internal-dev by @${{ github.actor }}
33

44
on:
55
workflow_dispatch:
66
inputs:
7-
proxy_environment:
8-
description: Name of the proxygen environment to deploy to
9-
required: true
10-
type: choice
11-
default: internal-dev
12-
options:
13-
- internal-dev
14-
- int
15-
- prod
167
build_sandbox:
178
description: Build sandbox container?
189
required: false
@@ -24,35 +15,33 @@ permissions:
2415
packages: read
2516

2617
jobs:
27-
deploy-environment:
18+
deploy-pr-proxy:
2819
runs-on: ubuntu-latest
29-
name: Deploy to Environment
20+
name: Deploy proxy to dynamic PR environment
3021
steps:
3122
- name: Checkout
3223
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
33-
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
34-
with:
35-
node-version: 22
3624

37-
- name: Npm install
25+
- name: Install dependencies
3826
uses: ./.github/actions/node-install
3927
with:
40-
node-version: 22
4128
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4229

43-
- name: "Check if pull request exists for this branch and set ENVIRONMENT/APIM_ENV"
30+
- name: Resolve nodejs version
31+
id: toolversions
32+
run: echo "nodejs_version=$(grep '^nodejs\s' .tool-versions | cut -f2 -d' ')" >>
33+
"$GITHUB_OUTPUT"
34+
35+
- name: "Check if pull request exists for this branch and set
36+
ENVIRONMENT/APIM_ENV"
4437
id: pr_exists
4538
env:
4639
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4740
run: |
4841
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
4942
echo "Current branch is '$branch_name'"
5043
51-
if [ -z "${{ inputs.proxy_environment }}" ]; then
52-
ENVIRONMENT="internal-dev"
53-
else
54-
ENVIRONMENT="${{ inputs.proxy_environment }}"
55-
fi
44+
ENVIRONMENT="internal-dev"
5645
5746
pr_json=$(gh pr list --head "$branch_name" --state open --json number --limit 1)
5847
pr_number=$(echo "$pr_json" | jq -r '.[0].number // empty')
@@ -62,36 +51,37 @@ jobs:
6251
echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT
6352
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
6453
APIM_ENV="$ENVIRONMENT-pr"
65-
echo "changing environment variable so that PR number is used in proxy pipeline for setting env vars"
54+
# changing environment variable so that PR number is used in proxy pipeline for setting env vars
6655
ENVIRONMENT="pr$pr_number"
6756
else
68-
echo "Pull request doesn't exist, setting target env to main"
69-
echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT
70-
echo "pr_number=" >> $GITHUB_OUTPUT
71-
APIM_ENV="$ENVIRONMENT"
72-
ENVIRONMENT="main"
57+
echo "[ERROR] Pull request $pr_number doesn't exist."
58+
exit 1
7359
fi
7460
7561
echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_ENV
7662
echo "APIM_ENV=$APIM_ENV" >> $GITHUB_ENV
7763
78-
- name: "Build OAS spec"
64+
- name: Build OAS spec
7965
uses: ./.github/actions/build-oas-spec
8066
with:
67+
version: "pr${{ steps.pr_exists.outputs.pr_number }}"
8168
apimEnv: "${{ env.APIM_ENV }}"
8269
buildSandbox: ${{ inputs.build_sandbox }}
70+
nodejs_version: ${{ steps.toolversions.outputs.nodejs_version }}
8371
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8472

85-
- name: "Build proxies"
73+
- name: Deploy proxy
8674
env:
8775
PROXYGEN_API_NAME: nhs-notify-supplier
8876
PR_NUMBER: ${{ steps.pr_exists.outputs.pr_number }}
8977
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
9078
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
9179
uses: ./.github/actions/build-proxies
9280
with:
81+
targetComponent: api
9382
environment: "${{ env.ENVIRONMENT }}"
9483
apimEnv: "${{ env.APIM_ENV }}"
9584
runId: "${{ github.run_id }}"
9685
buildSandbox: ${{ inputs.build_sandbox }}
9786
releaseVersion: ${{ github.ref_name }}
87+
version: "pr${{ steps.pr_exists.outputs.pr_number }}"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Deploy backend only
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
backend_account_group:
7+
description: "Target backend account group"
8+
type: choice
9+
required: true
10+
default: dev
11+
options:
12+
- dev
13+
- nonprod
14+
- prod
15+
source_type:
16+
description: "Deployment source type"
17+
type: choice
18+
required: true
19+
default: release
20+
options:
21+
- release
22+
- branch
23+
source_value:
24+
description: "Release tag or branch name"
25+
type: string
26+
required: true
27+
28+
run-name: >-
29+
Deploy backend=${{ inputs.backend_account_group }} source=${{
30+
inputs.source_type }}:${{ inputs.source_value }} by @${{ github.actor }}
31+
32+
permissions:
33+
id-token: write
34+
contents: read
35+
packages: read
36+
37+
jobs:
38+
deploy:
39+
uses: ./.github/workflows/deploy-supplier-api.yaml
40+
secrets: inherit
41+
with:
42+
backend_account_group: ${{ inputs.backend_account_group }}
43+
source_type: ${{ inputs.source_type }}
44+
source_value: ${{ inputs.source_value }}
45+
deploy_backend: true
46+
deploy_proxy: false
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy proxy only
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
apim_environment:
7+
description: "Target APIM environment"
8+
type: choice
9+
required: true
10+
default: internal-dev
11+
options:
12+
- internal-dev
13+
- int
14+
- prod
15+
source_type:
16+
description: "Deployment source type"
17+
type: choice
18+
required: true
19+
default: release
20+
options:
21+
- release
22+
- branch
23+
source_value:
24+
description: "Release tag or branch name"
25+
type: string
26+
required: true
27+
build_sandbox:
28+
description: "Build sandbox container"
29+
type: boolean
30+
required: false
31+
default: false
32+
33+
run-name: >-
34+
Deploy proxy apim=${{ inputs.apim_environment }} source=${{ inputs.source_type
35+
}}:${{ inputs.source_value }} by @${{ github.actor }}
36+
37+
permissions:
38+
id-token: write
39+
contents: read
40+
packages: read
41+
42+
jobs:
43+
deploy:
44+
uses: ./.github/workflows/deploy-supplier-api.yaml
45+
secrets: inherit
46+
with:
47+
apim_environment: ${{ inputs.apim_environment }}
48+
source_type: ${{ inputs.source_type }}
49+
source_value: ${{ inputs.source_value }}
50+
deploy_backend: false
51+
deploy_proxy: true
52+
build_sandbox: ${{ inputs.build_sandbox }}

0 commit comments

Comments
 (0)