Skip to content

Commit e42cf33

Browse files
committed
CCM-13419 Refactor build steps
1 parent c8a3e39 commit e42cf33

File tree

5 files changed

+106
-50
lines changed

5 files changed

+106
-50
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
if [[ $APIM_ENV == *-pr ]]; then
65+
echo "Removing pr suffix from APIM_ENV after building OAS and calling proxygen"
66+
APIM_ENV=$(echo "$APIM_ENV" | sed 's/-pr$//')
67+
fi
68+
echo "APIM_ENV=$APIM_ENV" >> $GITHUB_ENV
69+
70+
- name: Upload API OAS specification artifact
71+
uses: actions/upload-artifact@v4
72+
with:
73+
path: "build"
74+
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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,27 @@ jobs:
5555
version: "${{ inputs.version }}"
5656
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5757

58+
artefact-oas-spec:
59+
name: "Build OAS spec"
60+
runs-on: ubuntu-latest
61+
needs: [artefact-jekyll-docs]
62+
timeout-minutes: 10
63+
steps:
64+
- name: "Checkout code"
65+
uses: actions/checkout@v5
66+
- name: "Build proxies"
67+
uses: ./.github/actions/build-oas-spec
68+
with:
69+
version: "${{ inputs.version }}"
70+
apimEnv: "internal-dev-sandbox"
71+
buildSandbox: true
72+
nodejs_version: ${{ inputs.nodejs_version }}
73+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
5875
artefact-sdks:
5976
name: "Build SDKs"
6077
runs-on: ubuntu-latest
78+
needs: [artefact-oas-spec]
6179
timeout-minutes: 10
6280
steps:
6381
- name: "Checkout code"
@@ -117,7 +135,7 @@ jobs:
117135
artefact-proxies:
118136
name: "Build proxies"
119137
runs-on: ubuntu-latest
120-
needs: [pr-create-dynamic-environment]
138+
needs: [artefact-oas-spec, pr-create-dynamic-environment]
121139
timeout-minutes: 10
122140
env:
123141
PROXYGEN_API_NAME: nhs-notify-supplier
@@ -136,5 +154,3 @@ jobs:
136154
runId: "${{ github.run_id }}"
137155
buildSandbox: true
138156
releaseVersion: ${{ github.head_ref || github.ref_name }}
139-
nodejs_version: ${{ inputs.nodejs_version }}
140-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)