generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
223 lines (208 loc) · 6.73 KB
/
stage-2-test.yaml
File metadata and controls
223 lines (208 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: "Test stage"
on:
workflow_call:
inputs:
build_datetime:
description: "Build datetime, set by the CI/CD pipeline workflow"
required: true
type: string
build_timestamp:
description: "Build timestamp, set by the CI/CD pipeline workflow"
required: true
type: string
build_epoch:
description: "Build epoch, set by the CI/CD pipeline workflow"
required: true
type: string
nodejs_version:
description: "Node.js version, set by the CI/CD pipeline workflow"
required: true
type: string
python_version:
description: "Python version, set by the CI/CD pipeline workflow"
required: true
type: string
terraform_version:
description: "Terraform version, set by the CI/CD pipeline workflow"
required: true
type: string
version:
description: "Version of the software, set by the CI/CD pipeline workflow"
required: true
type: string
env:
AWS_REGION: eu-west-2
TERM: xterm-256color
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
discover-workspaces:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-workspaces.outputs.matrix }}
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Get workspaces"
id: "get-workspaces"
run: |
echo "matrix=$(jq -c '.workspaces' package.json)" >> "$GITHUB_OUTPUT"
check-generated-dependencies:
name: "Check generated dependencies"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Restore node_modules from cache"
uses: ./.github/actions/node-modules-cache
with:
node_version: "${{ inputs.nodejs_version }}"
- name: "Generate dependencies"
run: |
npm run generate-dependencies --workspaces --if-present
git diff --exit-code
test-unit:
name: "Unit tests"
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [discover-workspaces]
strategy:
fail-fast: false
matrix:
workspace: ${{ fromJSON(needs.discover-workspaces.outputs.matrix) }}
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Restore node_modules from cache"
uses: ./.github/actions/node-modules-cache
with:
node_version: "${{ inputs.nodejs_version }}"
- name: "Generate dependencies"
run: |
npm run generate-dependencies --workspaces --if-present
- name: "Run unit test suite"
run: |
WORKSPACE=${{ matrix.workspace }} make test-unit
- name: Compute safe artifact names
id: names
shell: bash
run: |
echo "safe=$(echo '${{ matrix.workspace }}' | tr '/' '-_')" >> "$GITHUB_OUTPUT"
- name: "Save the result of test suite"
uses: actions/upload-artifact@v4
with:
name: unit-tests-${{ steps.names.outputs.safe }}
path: "${{ matrix.workspace }}/.reports/unit"
include-hidden-files: true
if-no-files-found: ignore
if: always()
- name: "Save the result of code coverage"
uses: actions/upload-artifact@v4
with:
name: code-coverage-${{ steps.names.outputs.safe }}
path: "${{ matrix.workspace }}/.reports/unit/coverage/lcov.info"
if-no-files-found: ignore
if: always()
test-lint:
name: "Linting"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Restore node_modules from cache"
uses: ./.github/actions/node-modules-cache
with:
node_version: "${{ inputs.nodejs_version }}"
- name: "Generate dependencies"
run: |
npm run generate-dependencies --workspaces --if-present
- name: "Run linting"
run: |
make test-lint
test-typecheck:
name: "Typecheck"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Restore node_modules from cache"
uses: ./.github/actions/node-modules-cache
with:
node_version: "${{ inputs.nodejs_version }}"
- name: "Generate dependencies"
run: |
npm run generate-dependencies --workspaces --if-present
- name: "Run typecheck"
run: |
make test-typecheck
test-contract-provider:
name: "Test contracts (provider)"
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Restore node_modules from cache"
uses: ./.github/actions/node-modules-cache
with:
node_version: "${{ inputs.nodejs_version }}"
- name: "Run provider contract tests"
run: make test-contract-provider
env:
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
merge-coverage:
name: "Merge coverage"
runs-on: ubuntu-latest
needs: [test-unit]
steps:
- uses: actions/checkout@v5
- name: Download coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: code-coverage-*
merge-multiple: false
path: ./_cov_parts
- name: Merge LCOV files
run: |
set -euo pipefail
mkdir -p .reports
npx --yes lcov-result-merger \
"./_cov_parts/**/lcov.info" \
".reports/lcov.info" \
--ignore "node_modules" \
--prepend-source-files \
--prepend-path-fix "../../"
- name: Upload merged LCOV
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: .reports/lcov.info
perform-static-analysis:
name: "Perform static analysis"
needs: [test-unit, merge-coverage]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
with:
fetch-depth: 0 # Full history is needed to improving relevancy of reporting
- name: "Download coverage report for SONAR"
uses: actions/download-artifact@v5
with:
name: code-coverage-report
- name: "Perform static analysis"
uses: ./.github/actions/perform-static-analysis
with:
sonar_organisation_key: "${{ vars.SONAR_ORGANISATION_KEY }}"
sonar_project_key: "${{ vars.SONAR_PROJECT_KEY }}"
sonar_token: "${{ secrets.SONAR_TOKEN }}"