Skip to content

Commit 3e099d1

Browse files
stevebuxmasl2
andauthored
CCM-13419 Generate Specification Variants on Build (#301)
* CCM-13419 Refactor build steps * CCM-13419 Generate specification variants on build * Add permissions * Post review comment * Only build OAS variants if push is to main --------- Co-authored-by: Mark Slowey <[email protected]>
1 parent f413c3f commit 3e099d1

File tree

6 files changed

+159
-72
lines changed

6 files changed

+159
-72
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: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,16 @@ inputs:
2525
description: "Name of the Component to deploy"
2626
required: true
2727
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
3428

3529
runs:
3630
using: composite
3731

3832
steps:
39-
- name: Checkout
40-
uses: actions/checkout@v4
41-
- uses: actions/setup-node@v4
42-
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
33+
- name: Download OAS Spec artifact
34+
uses: actions/download-artifact@v4
4835
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 }}-
54-
55-
- name: Npm install
56-
working-directory: .
57-
env:
58-
NODE_AUTH_TOKEN: ${{ inputs.NODE_AUTH_TOKEN }}
59-
run: npm ci
60-
shell: bash
36+
name: api-oas-specification-${{ inputs.apimEnv }}${{ inputs.version != '' && format('-{0}', inputs.version) || '' }}
37+
path: ./build
6138

6239
- name: Setup Proxy Name and target
6340
shell: bash
@@ -87,21 +64,10 @@ runs:
8764
echo "MTLS_NAME=notify-supplier-mtls-pr$PR_NUMBER" >> $GITHUB_ENV
8865
fi
8966
90-
- name: Build ${{ inputs.apimEnv }} oas
91-
working-directory: .
92-
env:
93-
APIM_ENV: ${{ inputs.apimEnv }}
67+
- name: Set APIM_ENV
9468
shell: bash
9569
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-
70+
APIM_ENV="${{ inputs.apimEnv }}"
10571
if [[ $APIM_ENV == *-pr ]]; then
10672
echo "Removing pr suffix from APIM_ENV after building OAS and calling proxygen"
10773
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/stage-3-build.yaml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,48 @@ 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+
if: (github.event_name == 'push' && github.ref == 'refs/heads/main')
61+
runs-on: ubuntu-latest
62+
needs: [artefact-jekyll-docs]
63+
timeout-minutes: 10
64+
strategy:
65+
matrix:
66+
apimEnv: [internal-dev-pr, internal-dev, int, ref, prod]
67+
steps:
68+
- name: "Checkout code"
69+
uses: actions/checkout@v5
70+
- name: "Build OAS spec"
71+
uses: ./.github/actions/build-oas-spec
72+
with:
73+
version: "${{ inputs.version }}"
74+
apimEnv: "${{ matrix.apimEnv }}"
75+
buildSandbox: false
76+
nodejs_version: ${{ inputs.nodejs_version }}
77+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
79+
artefact-oas-spec-sandbox:
80+
name: "Build OAS spec for sandbox"
81+
runs-on: ubuntu-latest
82+
needs: [artefact-jekyll-docs]
83+
timeout-minutes: 10
84+
steps:
85+
- name: "Checkout code"
86+
uses: actions/checkout@v5
87+
- name: "Build proxies"
88+
uses: ./.github/actions/build-oas-spec
89+
with:
90+
version: "${{ inputs.version }}"
91+
apimEnv: "internal-dev-sandbox"
92+
buildSandbox: true
93+
nodejs_version: ${{ inputs.nodejs_version }}
94+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
5896
artefact-sdks:
5997
name: "Build SDKs"
6098
runs-on: ubuntu-latest
99+
needs: [artefact-oas-spec]
61100
timeout-minutes: 10
62101
steps:
63102
- name: "Checkout code"
@@ -94,6 +133,7 @@ jobs:
94133
pr-create-dynamic-environment:
95134
name: Create Dynamic Environment
96135
runs-on: ubuntu-latest
136+
if: inputs.pr_number != ''
97137
steps:
98138
- uses: actions/checkout@v5
99139
- name: Trigger dynamic environment creation
@@ -117,7 +157,8 @@ jobs:
117157
artefact-proxies:
118158
name: "Build proxies"
119159
runs-on: ubuntu-latest
120-
needs: [pr-create-dynamic-environment]
160+
if: inputs.pr_number != ''
161+
needs: [artefact-oas-spec-sandbox, pr-create-dynamic-environment]
121162
timeout-minutes: 10
122163
env:
123164
PROXYGEN_API_NAME: nhs-notify-supplier
@@ -136,5 +177,3 @@ jobs:
136177
runId: "${{ github.run_id }}"
137178
buildSandbox: true
138179
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: 36 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,39 @@ 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+
permissions:
230+
id-token: write # This is required for requesting the JWT
231+
contents: read # This is required for actions/checkout
232+
timeout-minutes: 10
233+
strategy:
234+
matrix:
235+
apimEnv: [internal-dev, int, ref, prod]
236+
steps:
237+
- name: "Download OAS spec artifact"
238+
uses: actions/download-artifact@v6
239+
with:
240+
path: ./artifacts/api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}
241+
name: api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}
242+
243+
- name: "Zip OAS specification"
244+
working-directory: ./artifacts/api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}
245+
run: zip -r ../api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}.zip .
246+
shell: bash
247+
248+
- name: "Upload OAS specification release asset"
249+
uses: actions/upload-release-asset@v1
250+
env:
251+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
252+
with:
253+
upload_url: ${{ needs.publish.outputs.upload_url }}
254+
asset_path: ./artifacts/api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}.zip
255+
asset_name: api-oas-specification-${{ matrix.apimEnv }}-${{ inputs.version }}.zip
256+
asset_content_type: "application/zip"
257+
244258
# Take out for now - might add again in the future
245259
# ### 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.
246260
# publishdocker:

0 commit comments

Comments
 (0)