generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
286 lines (267 loc) · 9.73 KB
/
stage-1-commit.yaml
File metadata and controls
286 lines (267 loc) · 9.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
name: "Commit 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
jobs:
scan-secrets:
name: "Scan secrets"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
with:
fetch-depth: 0 # Full history is needed to scan all commits
- name: "Scan secrets"
uses: ./.github/actions/scan-secrets
check-file-format:
name: "Check file format"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
with:
fetch-depth: 0 # Full history is needed to compare branches
- name: "Check file format"
uses: ./.github/actions/check-file-format
check-markdown-format:
name: "Check Markdown format"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
with:
fetch-depth: 0 # Full history is needed to compare branches
- name: "Check Markdown format"
uses: ./.github/actions/check-markdown-format
terraform-docs:
name: "Run terraform-docs"
runs-on: ubuntu-latest
needs: detect-terraform-changes
if: needs.detect-terraform-changes.outputs.terraform_changed == 'true'
permissions:
contents: write
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
with:
fetch-depth: 0 # Full history is needed to compare branches
- name: "Check to see if Terraform Docs are up-to-date"
run: |
make terraform-docs
- name: "Stage changes"
run: |
git add infrastructure/terraform/**/*.md
- name: "Check for changes in Terraform Docs"
run: |
if git diff --cached --name-only | grep -qE '\.md$'; then
echo "Markdown files have changed. Please run 'make terraform-docs' and commit the changes."
exit 1
fi
check-english-usage:
name: "Check English usage"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
with:
fetch-depth: 0 # Full history is needed to compare branches
- name: "Check English usage"
uses: ./.github/actions/check-english-usage
check-todo-usage:
name: "Check TODO usage"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
with:
fetch-depth: 0 # Full history is needed to compare branches
- name: "Check TODO usage"
uses: ./.github/actions/check-todo-usage
detect-terraform-changes:
name: "Detect Terraform Changes"
runs-on: ubuntu-latest
outputs:
terraform_changed: ${{ steps.check.outputs.terraform_changed }}
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Check for Terraform changes"
id: check
run: |
git fetch origin main || true # Ensure you have the latest main branch
CHANGED_FILES=$(git diff --name-only HEAD origin/main)
echo "Changed files: $CHANGED_FILES"
if echo "$CHANGED_FILES" | grep -qE '\.tf$'; then
echo "Terraform files have changed."
echo "terraform_changed=true" >> $GITHUB_OUTPUT
else
echo "No Terraform changes detected."
echo "terraform_changed=false" >> $GITHUB_OUTPUT
fi
lint-terraform:
name: "Lint Terraform"
runs-on: ubuntu-latest
timeout-minutes: 5
needs: detect-terraform-changes
if: needs.detect-terraform-changes.outputs.terraform_changed == 'true'
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Lint Terraform"
uses: ./.github/actions/lint-terraform
trivy:
name: "Trivy Scan"
runs-on: ubuntu-latest
timeout-minutes: 5
needs: detect-terraform-changes
if: needs.detect-terraform-changes.outputs.terraform_changed == 'true'
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Setup ASDF"
uses: asdf-vm/actions/setup@v4
- name: "Perform Setup"
uses: ./.github/actions/setup
- name: "Trivy Scan"
uses: ./.github/actions/trivy
count-lines-of-code:
name: "Count lines of code"
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Count lines of code"
uses: ./.github/actions/create-lines-of-code-report
with:
build_datetime: "${{ inputs.build_datetime }}"
build_timestamp: "${{ inputs.build_timestamp }}"
idp_aws_report_upload_account_id: "${{ secrets.IDP_AWS_REPORT_UPLOAD_ACCOUNT_ID }}"
idp_aws_report_upload_region: "${{ secrets.IDP_AWS_REPORT_UPLOAD_REGION }}"
idp_aws_report_upload_role_name: "${{ secrets.IDP_AWS_REPORT_UPLOAD_ROLE_NAME }}"
idp_aws_report_upload_bucket_endpoint: "${{ secrets.IDP_AWS_REPORT_UPLOAD_BUCKET_ENDPOINT }}"
scan-dependencies:
name: "Scan dependencies"
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
timeout-minutes: 5
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Scan dependencies"
uses: ./.github/actions/scan-dependencies
with:
build_datetime: "${{ inputs.build_datetime }}"
build_timestamp: "${{ inputs.build_timestamp }}"
idp_aws_report_upload_account_id: "${{ secrets.IDP_AWS_REPORT_UPLOAD_ACCOUNT_ID }}"
idp_aws_report_upload_region: "${{ secrets.IDP_AWS_REPORT_UPLOAD_REGION }}"
idp_aws_report_upload_role_name: "${{ secrets.IDP_AWS_REPORT_UPLOAD_ROLE_NAME }}"
idp_aws_report_upload_bucket_endpoint: "${{ secrets.IDP_AWS_REPORT_UPLOAD_BUCKET_ENDPOINT }}"
detect-event-schema-package-changes:
name: "Check for changes to event schema package compared to main branch"
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
changed: ${{ steps.check.outputs.changed }}
main_version: ${{ steps.check.outputs.main_version }}
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect package changes and current version
id: check
run: |
git fetch origin main
if git diff --quiet origin/main...HEAD -- packages/event-schemas; then
echo "No changes in event schemas package"
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in event schemas"
echo "changed=true" >> $GITHUB_OUTPUT
fi
if content=$(git show origin/main:packages/event-schemas/package.json 2>/dev/null); then
version=$(jq -r .version <<< $content);
else
version=null;
fi
echo "Detected package version $version in main branch"
echo "main_version=$version" >> $GITHUB_OUTPUT
check-schemas-generated:
name: Check event schemas have been regenerated
needs: detect-event-schema-package-changes
if: needs.detect-event-schema-package-changes.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Restore node_modules from cache"
uses: ./.github/actions/node-modules-cache
with:
node_version: "${{ inputs.nodejs_version }}"
- name: Re-generate schemas
run: npm --workspace packages/event-schemas run generate-json-schemas
- name: Check for schema changes
run: git diff --quiet packages/event-schemas/schemas
check-schema-version-change:
name: Check event schema version has been updated
needs: detect-event-schema-package-changes
if: needs.detect-event-schema-package-changes.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check schema versions
run: |
source scripts/is_valid_increment.sh
main_version="${{ needs.detect-event-schema-package-changes.outputs.main_version }}"
echo "Main version: ${{ needs.detect-event-schema-package-changes.outputs.main_version }}"
local_version=$(jq -r '.version' packages/event-schemas/package.json)
echo "Local version: $local_version"
if ! is_valid_increment "$main_version" "$local_version" ; then
echo "Error: Event Schema package has changed, but new version ($local_version) is not a valid increment from latest version on main branch ($main_version)."
exit 1
fi