Skip to content

Commit 64ece87

Browse files
stevebuxmasl2
andauthored
Feature/ccm 13428 trigger proxy deploy (#310)
* CCM-13419 Refactor build steps * CCM-13419 Generate specification variants on build * CCM-13428 OnRelease workflow triggers proxy deploy --------- Co-authored-by: Mark Slowey <113013138+masl2@users.noreply.github.com>
1 parent b3ab7b5 commit 64ece87

File tree

7 files changed

+202
-76
lines changed

7 files changed

+202
-76
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: "Build OAS Spec"
2+
description: "Build OAS Spec"
3+
4+
inputs:
5+
version:
6+
description: "Version number"
7+
required: true
8+
apimEnv:
9+
description: "APIM environment"
10+
required: true
11+
buildSandbox:
12+
description: "Whether to build the sandbox OAS spec"
13+
required: false
14+
default: false
15+
nodejs_version:
16+
description: "Node.js version, set by the CI/CD pipeline workflow"
17+
required: true
18+
NODE_AUTH_TOKEN:
19+
description: "Token for access to github package registry"
20+
required: true
21+
22+
runs:
23+
using: composite
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
- uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ inputs.nodejs_version }}
31+
registry-url: 'https://npm.pkg.github.com'
32+
33+
- name: "Cache node_modules"
34+
uses: actions/cache@v4
35+
with:
36+
path: |
37+
**/node_modules
38+
key: ${{ runner.os }}-node-${{ inputs.nodejs_version }}-${{ hashFiles('**/package-lock.json') }}
39+
restore-keys: |
40+
${{ runner.os }}-node-${{ inputs.nodejs_version }}-
41+
42+
- name: Npm install
43+
working-directory: .
44+
env:
45+
NODE_AUTH_TOKEN: ${{ inputs.NODE_AUTH_TOKEN }}
46+
run: npm ci
47+
shell: bash
48+
49+
- name: Build ${{ inputs.apimEnv }} oas
50+
working-directory: .
51+
env:
52+
APIM_ENV: ${{ inputs.apimEnv }}
53+
shell: bash
54+
run: |
55+
if [ ${{ env.APIM_ENV }} == "internal-dev-sandbox" ] && [ ${{ inputs.buildSandbox }} == true ]
56+
then
57+
echo "Building sandbox OAS spec"
58+
make build-json-oas-spec APIM_ENV=sandbox
59+
else
60+
echo "Building env specific OAS spec"
61+
make build-json-oas-spec APIM_ENV=${{ env.APIM_ENV }}
62+
fi
63+
64+
- name: Upload API OAS specification artifact
65+
uses: actions/upload-artifact@v4
66+
with:
67+
path: "build"
68+
name: api-oas-specification-${{ inputs.apimEnv }}${{ inputs.version != '' && format('-{0}', inputs.version) || '' }}

.github/actions/build-proxies/action.yml

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ inputs:
88
releaseVersion:
99
description: "Release, tag, branch, or commit ID to be used for deployment"
1010
required: true
11+
isRelease:
12+
description: "True if releaseVersion is a release tag (if set, downloads from release assets instead of workflow artifacts)"
13+
required: false
14+
default: false
1115
environment:
1216
description: "Deployment environment"
1317
required: true
@@ -25,39 +29,33 @@ inputs:
2529
description: "Name of the Component to deploy"
2630
required: true
2731
default: 'api'
28-
nodejs_version:
29-
description: "Node.js version, set by the CI/CD pipeline workflow"
30-
required: true
31-
NODE_AUTH_TOKEN:
32-
description: "Token for access to github package registry"
33-
required: true
3432

3533
runs:
3634
using: composite
3735

3836
steps:
39-
- name: Checkout
40-
uses: actions/checkout@v4
41-
- uses: actions/setup-node@v4
37+
- name: Download OAS Spec artifact from workflow
38+
if: ${{ inputs.isRelease == 'false' }}
39+
uses: actions/download-artifact@v4
4240
with:
43-
node-version: ${{ inputs.nodejs_version }}
44-
registry-url: 'https://npm.pkg.github.com'
45-
46-
- name: "Cache node_modules"
47-
uses: actions/cache@v4
48-
with:
49-
path: |
50-
**/node_modules
51-
key: ${{ runner.os }}-node-${{ inputs.nodejs_version }}-${{ hashFiles('**/package-lock.json') }}
52-
restore-keys: |
53-
${{ runner.os }}-node-${{ inputs.nodejs_version }}-
41+
name: api-oas-specification-${{ inputs.apimEnv }}${{ inputs.version != '' && format('-{0}', inputs.version) || '' }}
42+
path: ./build
5443

55-
- name: Npm install
56-
working-directory: .
57-
env:
58-
NODE_AUTH_TOKEN: ${{ inputs.NODE_AUTH_TOKEN }}
59-
run: npm ci
44+
- name: Download OAS Spec artifact from release
45+
if: ${{ inputs.isRelease == 'true' }}
6046
shell: bash
47+
run: |
48+
mkdir ./build
49+
ASSET_PATTERN="api-oas-specification-${{ inputs.apimEnv }}-*.zip"
50+
gh release download "${{ inputs.releaseVersion }}" \
51+
--pattern "$ASSET_PATTERN" \
52+
--dir ./build
53+
# Unzip the downloaded file (there should be exactly one match)
54+
ASSET_FILE=$(ls ./build/api-oas-specification-${{ inputs.apimEnv }}-*.zip)
55+
unzip "$ASSET_FILE" -d ./build
56+
rm "$ASSET_FILE"
57+
env:
58+
GH_TOKEN: ${{ github.token }}
6159

6260
- name: Setup Proxy Name and target
6361
shell: bash
@@ -87,21 +85,10 @@ runs:
8785
echo "MTLS_NAME=notify-supplier-mtls-pr$PR_NUMBER" >> $GITHUB_ENV
8886
fi
8987
90-
- name: Build ${{ inputs.apimEnv }} oas
91-
working-directory: .
92-
env:
93-
APIM_ENV: ${{ inputs.apimEnv }}
88+
- name: Set APIM_ENV
9489
shell: bash
9590
run: |
96-
if [ ${{ env.APIM_ENV }} == "internal-dev-sandbox" ] && [ ${{ inputs.buildSandbox }} == true ]
97-
then
98-
echo "Building sandbox OAS spec"
99-
make build-json-oas-spec APIM_ENV=sandbox
100-
else
101-
echo "Building env specific OAS spec"
102-
make build-json-oas-spec APIM_ENV=${{ env.APIM_ENV }}
103-
fi
104-
91+
APIM_ENV="${{ inputs.apimEnv }}"
10592
if [[ $APIM_ENV == *-pr ]]; then
10693
echo "Removing pr suffix from APIM_ENV after building OAS and calling proxygen"
10794
APIM_ENV=$(echo "$APIM_ENV" | sed 's/-pr$//')

.github/actions/build-sdk/action.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ runs:
5555
run: |
5656
make build VERSION="${{ inputs.version }}"
5757
58-
- name: Upload API OAS specification artifact
59-
uses: actions/upload-artifact@v4
60-
with:
61-
path: "build"
62-
name: api-oas-specification-${{ inputs.version }}
63-
6458
- name: Upload html artifact
6559
uses: actions/upload-artifact@v4
6660
with:

.github/workflows/manual-proxy-environment-deploy.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ jobs:
7777
echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_ENV
7878
echo "APIM_ENV=$APIM_ENV" >> $GITHUB_ENV
7979
80+
- name: "Build OAS spec"
81+
uses: ./.github/actions/build-oas-spec
82+
with:
83+
apimEnv: "${{ env.APIM_ENV }}"
84+
buildSandbox: ${{ inputs.build_sandbox }}
85+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
8087
- name: "Build proxies"
8188
env:
8289
PROXYGEN_API_NAME: nhs-notify-supplier
@@ -90,4 +97,3 @@ jobs:
9097
runId: "${{ github.run_id }}"
9198
buildSandbox: ${{ inputs.build_sandbox }}
9299
releaseVersion: ${{ github.ref_name }}
93-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release_created.yaml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ jobs:
1717
id-token: write
1818
contents: read
1919

20-
strategy:
21-
max-parallel: 1
22-
matrix:
23-
component: [api]
24-
2520
steps:
2621
- name: Checkout repository
2722
uses: actions/checkout@v5
@@ -36,5 +31,32 @@ jobs:
3631
--targetWorkflow "dispatch-deploy-static-notify-supplier-api-env.yaml" \
3732
--targetEnvironment "main" \
3833
--targetAccountGroup "nhs-notify-supplier-api-nonprod" \
39-
--targetComponent "${{ matrix.component }}" \
34+
--targetComponent "api" \
4035
--terraformAction "apply"
36+
deploy-proxy:
37+
name: "Deploy proxy"
38+
runs-on: ubuntu-latest
39+
timeout-minutes: 10
40+
41+
permissions:
42+
id-token: write
43+
contents: read
44+
actions: read
45+
46+
env:
47+
PROXYGEN_API_NAME: nhs-notify-supplier
48+
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
49+
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
50+
51+
steps:
52+
- name: "Checkout code"
53+
uses: actions/checkout@v5
54+
55+
- name: "Build proxies"
56+
uses: ./.github/actions/build-proxies
57+
with:
58+
environment: "main"
59+
apimEnv: "int"
60+
runId: "${{ github.run_id }}"
61+
releaseVersion: "${{ github.event.release.tag_name }}"
62+
isRelease: true

.github/workflows/stage-3-build.yaml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,47 @@ jobs:
5555
version: "${{ inputs.version }}"
5656
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5757

58+
artefact-oas-spec:
59+
name: "Build OAS spec (${{ matrix.apimEnv }})"
60+
runs-on: ubuntu-latest
61+
needs: [artefact-jekyll-docs]
62+
timeout-minutes: 10
63+
strategy:
64+
matrix:
65+
apimEnv: [internal-dev-pr, internal-dev, int, ref, prod]
66+
steps:
67+
- name: "Checkout code"
68+
uses: actions/checkout@v5
69+
- name: "Build OAS spec"
70+
uses: ./.github/actions/build-oas-spec
71+
with:
72+
version: "${{ inputs.version }}"
73+
apimEnv: "${{ matrix.apimEnv }}"
74+
buildSandbox: false
75+
nodejs_version: ${{ inputs.nodejs_version }}
76+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
78+
artefact-oas-spec-sandbox:
79+
name: "Build OAS spec for sandbox"
80+
runs-on: ubuntu-latest
81+
needs: [artefact-jekyll-docs]
82+
timeout-minutes: 10
83+
steps:
84+
- name: "Checkout code"
85+
uses: actions/checkout@v5
86+
- name: "Build proxies"
87+
uses: ./.github/actions/build-oas-spec
88+
with:
89+
version: "${{ inputs.version }}"
90+
apimEnv: "internal-dev-sandbox"
91+
buildSandbox: true
92+
nodejs_version: ${{ inputs.nodejs_version }}
93+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
5895
artefact-sdks:
5996
name: "Build SDKs"
6097
runs-on: ubuntu-latest
98+
needs: [artefact-oas-spec]
6199
timeout-minutes: 10
62100
steps:
63101
- name: "Checkout code"
@@ -94,6 +132,7 @@ jobs:
94132
pr-create-dynamic-environment:
95133
name: Create Dynamic Environment
96134
runs-on: ubuntu-latest
135+
if: inputs.pr_number != ''
97136
steps:
98137
- uses: actions/checkout@v5
99138
- name: Trigger dynamic environment creation
@@ -117,7 +156,8 @@ jobs:
117156
artefact-proxies:
118157
name: "Build proxies"
119158
runs-on: ubuntu-latest
120-
needs: [pr-create-dynamic-environment]
159+
if: inputs.pr_number != ''
160+
needs: [artefact-oas-spec-sandbox, pr-create-dynamic-environment]
121161
timeout-minutes: 10
122162
env:
123163
PROXYGEN_API_NAME: nhs-notify-supplier
@@ -136,5 +176,3 @@ jobs:
136176
runId: "${{ github.run_id }}"
137177
buildSandbox: true
138178
releaseVersion: ${{ github.head_ref || github.ref_name }}
139-
nodejs_version: ${{ inputs.nodejs_version }}
140-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/stage-5-publish.yaml

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
name: "Publish packages"
4141
runs-on: ubuntu-latest
4242
timeout-minutes: 10
43+
outputs:
44+
release_id: ${{ steps.create_release.outputs.id }}
45+
upload_url: ${{ steps.create_release.outputs.upload_url }}
4346

4447
steps:
4548
- name: "Checkout code"
@@ -87,12 +90,6 @@ jobs:
8790
path: ./artifacts/sdk-csharp-${{ inputs.version }}
8891
name: sdk-csharp-${{ inputs.version }}
8992

90-
- name: "Get the artefacts 8"
91-
uses: actions/download-artifact@v6
92-
with:
93-
path: ./artifacts/api-oas-specification-${{ inputs.version }}
94-
name: api-oas-specification-${{ inputs.version }}
95-
9693
# Take out for now - might add again in the future
9794
# - name: "Get the artefacts 9"
9895
# uses: actions/download-artifact@v6
@@ -207,22 +204,6 @@ jobs:
207204
asset_name: sdk-csharp-${{ inputs.version }}.zip
208205
asset_content_type: "application/gzip"
209206

210-
- name: "zip api OAS specification release asset"
211-
# GitHub pages needs a single tar called artifact inside the zip.
212-
working-directory: ./artifacts/api-oas-specification-${{ inputs.version }}
213-
run: zip -r ../api-oas-specification-${{ inputs.version }}.zip .
214-
shell: bash
215-
216-
- name: "Upload api OAS specification release asset"
217-
uses: actions/upload-release-asset@v1
218-
env:
219-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
220-
with:
221-
upload_url: "${{ steps.create_release.outputs.upload_url }}"
222-
asset_path: ./artifacts/api-oas-specification-${{ inputs.version }}.zip
223-
asset_name: api-oas-specification-${{ inputs.version }}.zip
224-
asset_content_type: "application/gzip"
225-
226207
# Take out for now - might add again in the future
227208
# - name: "zip csharp server release asset"
228209
# # GitHub pages needs a single tar called artifact inside the zip.
@@ -241,6 +222,36 @@ jobs:
241222
# asset_name: server-csharp-${{ inputs.version }}.zip
242223
# asset_content_type: "application/gzip"
243224

225+
publish-oas-specs:
226+
name: "Publish OAS spec (${{ matrix.apimEnv }})"
227+
runs-on: ubuntu-latest
228+
needs: [publish]
229+
timeout-minutes: 10
230+
strategy:
231+
matrix:
232+
apimEnv: [internal-dev, int, ref, prod]
233+
steps:
234+
- name: "Download OAS spec artifact"
235+
uses: actions/download-artifact@v6
236+
with:
237+
path: ./artifacts/api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}
238+
name: api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}
239+
240+
- name: "Zip OAS specification"
241+
working-directory: ./artifacts/api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}
242+
run: zip -r ../api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}.zip .
243+
shell: bash
244+
245+
- name: "Upload OAS specification release asset"
246+
uses: actions/upload-release-asset@v1
247+
env:
248+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
249+
with:
250+
upload_url: ${{ needs.publish.outputs.upload_url }}
251+
asset_path: ./artifacts/api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}.zip
252+
asset_name: api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}.zip
253+
asset_content_type: "application/zip"
254+
244255
# Take out for now - might add again in the future
245256
# ### PUBLISH DOCKER - THIS NEEDS CHANGING TO DO THE DOCKER BUILD IN THE BUILD STAGE AND ARTIFACT IT. SEE publishlibhostdocker below how how and the buildlibs action.
246257
# publishdocker:

0 commit comments

Comments
 (0)