-
Notifications
You must be signed in to change notification settings - Fork 2
426 lines (381 loc) Β· 14.7 KB
/
release-candidate.yml
File metadata and controls
426 lines (381 loc) Β· 14.7 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
name: "Create Release Candidate"
on:
workflow_dispatch:
inputs:
dev_tag:
description: "dev-* tag to promote (e.g., dev-20250115120000)"
required: true
type: string
deploy_to_test:
description: "Deploy to Test first (if not already done)?"
required: false
default: true
type: boolean
release_type:
description: "Version bump type for RC"
required: false
default: "rc"
type: choice
options:
- rc
- patch
- minor
- major
concurrency:
group: release-candidate-${{ inputs.dev_tag }}
cancel-in-progress: false
permissions:
contents: write
id-token: write
actions: read
jobs:
validate:
name: "Validate dev tag exists"
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
dev_tag: ${{ steps.validate.outputs.dev_tag }}
commit_sha: ${{ steps.validate.outputs.commit_sha }}
steps:
- name: "Checkout repository"
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: "Validate tag exists and get commit SHA"
id: validate
run: |
git fetch --tags --force
TAG="${{ inputs.dev_tag }}"
# Validate tag format
if [[ ! "$TAG" =~ ^dev-[0-9]{14}$ ]]; then
echo "β Invalid tag format. Expected dev-YYYYMMDDHHMMSS, got: $TAG" >&2
exit 1
fi
# Check if tag exists
if ! git rev-parse "$TAG" >/dev/null 2>&1; then
echo "β Tag $TAG does not exist in repository" >&2
exit 1
fi
# Get the commit SHA
COMMIT_SHA=$(git rev-parse "$TAG^{commit}")
echo "β
Found tag $TAG pointing to commit $COMMIT_SHA"
echo "dev_tag=$TAG" >> $GITHUB_OUTPUT
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
verify-artifact:
name: "Verify S3 artifact exists"
runs-on: ubuntu-latest
needs: [validate]
timeout-minutes: 10
permissions:
id-token: write
contents: read
environment: dev
outputs:
artifact_exists: ${{ steps.check.outputs.exists }}
s3_bucket: ${{ steps.bucket.outputs.name }}
steps:
- name: "Checkout at dev tag"
uses: actions/checkout@v6
with:
ref: ${{ needs.validate.outputs.dev_tag }}
- name: "Setup Terraform"
uses: hashicorp/setup-terraform@v3
with:
terraform_version: $(grep '^terraform' .tool-versions | cut -f2 -d' ')
- name: "Configure AWS Credentials (dev)"
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-api-deployment-role
aws-region: eu-west-2
- name: "Get S3 bucket name"
id: bucket
run: |
cd infrastructure
make terraform env=dev stack=api-layer tf-command=init workspace=default
BUCKET=$(terraform -chdir=./stacks/api-layer output -raw lambda_artifact_bucket)
echo "name=$BUCKET" >> $GITHUB_OUTPUT
echo "π¦ S3 Bucket: $BUCKET"
- name: "Check if artifact exists in S3"
id: check
run: |
TAG="${{ needs.validate.outputs.dev_tag }}"
BUCKET="${{ steps.bucket.outputs.name }}"
S3_KEY="artifacts/$TAG/lambda.zip"
if aws s3 ls "s3://$BUCKET/$S3_KEY" --region eu-west-2 >/dev/null 2>&1; then
echo "β
Artifact exists: s3://$BUCKET/$S3_KEY"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "β Artifact NOT found: s3://$BUCKET/$S3_KEY"
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: "Download artifact for workflow reuse"
if: steps.check.outputs.exists == 'true'
run: |
TAG="${{ needs.validate.outputs.dev_tag }}"
BUCKET="${{ steps.bucket.outputs.name }}"
mkdir -p ./dist
aws s3 cp \
"s3://$BUCKET/artifacts/$TAG/lambda.zip" \
./dist/lambda.zip \
--region eu-west-2
- name: "Upload lambda artifact"
if: steps.check.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: lambda-${{ needs.validate.outputs.dev_tag }}
path: dist/lambda.zip
if-no-files-found: error
rebuild-artifact:
name: "Rebuild and upload artifact (if missing)"
runs-on: ubuntu-latest
needs: [validate, verify-artifact]
if: needs.verify-artifact.outputs.artifact_exists == 'false'
timeout-minutes: 15
permissions:
id-token: write
contents: read
environment: dev
steps:
- name: "Checkout at dev tag"
uses: actions/checkout@v6
with:
ref: ${{ needs.validate.outputs.dev_tag }}
- name: "Set up Python"
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: "Build lambda artifact"
run: |
make dependencies install-python
make build
- name: "Configure AWS Credentials"
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-api-deployment-role
aws-region: eu-west-2
- name: "Upload to S3"
run: |
TAG="${{ needs.validate.outputs.dev_tag }}"
BUCKET="${{ needs.verify-artifact.outputs.s3_bucket }}"
aws s3 cp ./dist/lambda.zip \
"s3://$BUCKET/artifacts/$TAG/lambda.zip" \
--region eu-west-2
echo "β
Uploaded artifact to s3://$BUCKET/artifacts/$TAG/lambda.zip"
- name: "Upload lambda artifact"
uses: actions/upload-artifact@v4
with:
name: lambda-${{ needs.validate.outputs.dev_tag }}
path: dist/lambda.zip
if-no-files-found: error
deploy-to-test:
name: "Deploy to Test (optional)"
runs-on: ubuntu-latest
needs: [validate, verify-artifact, rebuild-artifact]
if: |
always() &&
inputs.deploy_to_test == true &&
(needs.verify-artifact.outputs.artifact_exists == 'true' || needs.rebuild-artifact.result == 'success')
timeout-minutes: 45
permissions:
id-token: write
contents: read
environment: test
steps:
- name: "Checkout at dev tag"
uses: actions/checkout@v6
with:
ref: ${{ needs.validate.outputs.dev_tag }}
- name: "Setup Terraform"
uses: hashicorp/setup-terraform@v3
with:
terraform_version: $(grep '^terraform' .tool-versions | cut -f2 -d' ')
- name: "Download lambda artifact"
uses: actions/download-artifact@v4
with:
name: lambda-${{ needs.validate.outputs.dev_tag }}
path: dist
- name: "Configure AWS Credentials (test)"
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-api-deployment-role
aws-region: eu-west-2
- name: "Terraform Apply (TEST)"
env:
ENVIRONMENT: test
WORKSPACE: "default"
TF_VAR_API_CA_CERT: ${{ secrets.API_CA_CERT }}
TF_VAR_API_CLIENT_CERT: ${{ secrets.API_CLIENT_CERT }}
TF_VAR_API_PRIVATE_KEY_CERT: ${{ secrets.API_PRIVATE_KEY_CERT }}
TF_VAR_SPLUNK_HEC_TOKEN: ${{ secrets.SPLUNK_HEC_TOKEN }}
TF_VAR_SPLUNK_HEC_ENDPOINT: ${{ secrets.SPLUNK_HEC_ENDPOINT }}
TF_VAR_OPERATOR_EMAILS: ${{ vars.SECRET_ROTATION_OPERATOR_EMAILS }}
TF_VAR_PROXYGEN_PRIVATE_KEY: ${{ secrets.PROXYGEN_PRIVATE_KEY_PROD }}
run: |
mkdir -p ./build
echo "π Deploying ${{ needs.validate.outputs.dev_tag }} to TEST"
make terraform env=$ENVIRONMENT stack=networking tf-command=apply workspace=$WORKSPACE
make terraform env=$ENVIRONMENT stack=api-layer tf-command=apply workspace=$WORKSPACE
working-directory: ./infrastructure
- name: "Validate Feature Toggles"
env:
ENV: test
run: |
pip install boto3
python scripts/feature_toggle/validate_toggles.py
- name: "Get test S3 bucket"
id: test_bucket
run: |
cd infrastructure
make terraform env=test stack=api-layer tf-command=init workspace=default
BUCKET=$(terraform -chdir=./stacks/api-layer output -raw lambda_artifact_bucket)
echo "name=$BUCKET" >> $GITHUB_OUTPUT
- name: "Upload lambda to test S3"
run: |
TAG="${{ needs.validate.outputs.dev_tag }}"
BUCKET="${{ steps.test_bucket.outputs.name }}"
aws s3 cp ./dist/lambda.zip \
"s3://$BUCKET/artifacts/$TAG/lambda.zip" \
--region eu-west-2
test-regression:
name: "Test Regression Tests"
needs: [deploy-to-test]
if: inputs.deploy_to_test == true
uses: ./.github/workflows/regression-tests.yml
with:
ENVIRONMENT: "test"
VERSION_NUMBER: "main"
secrets: inherit
deploy-to-preprod:
name: "Deploy to PreProd and create RC"
runs-on: ubuntu-latest
needs:
[
validate,
verify-artifact,
rebuild-artifact,
deploy-to-test,
test-regression,
]
if: |
always() &&
!cancelled() &&
(needs.deploy-to-test.result == 'success' || needs.deploy-to-test.result == 'skipped') &&
(needs.test-regression.result == 'success' || needs.test-regression.result == 'skipped') &&
(needs.verify-artifact.outputs.artifact_exists == 'true' || needs.rebuild-artifact.result == 'success')
timeout-minutes: 45
permissions:
id-token: write
contents: write
environment: preprod
outputs:
rc_tag: ${{ steps.release.outputs.rc_tag }}
steps:
- name: "Checkout at dev tag"
uses: actions/checkout@v6
with:
ref: ${{ needs.validate.outputs.dev_tag }}
fetch-depth: 0
- name: "Setup Terraform"
uses: hashicorp/setup-terraform@v3
with:
terraform_version: $(grep '^terraform' .tool-versions | cut -f2 -d' ')
- name: "Download lambda artifact"
uses: actions/download-artifact@v4
with:
name: lambda-${{ needs.validate.outputs.dev_tag }}
path: dist
- name: "Configure AWS Credentials (preprod)"
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-api-deployment-role
aws-region: eu-west-2
- name: "Terraform Apply (PREPROD)"
env:
ENVIRONMENT: preprod
WORKSPACE: "default"
TF_VAR_API_CA_CERT: ${{ secrets.API_CA_CERT }}
TF_VAR_API_CLIENT_CERT: ${{ secrets.API_CLIENT_CERT }}
TF_VAR_API_PRIVATE_KEY_CERT: ${{ secrets.API_PRIVATE_KEY_CERT }}
TF_VAR_SPLUNK_HEC_TOKEN: ${{ secrets.SPLUNK_HEC_TOKEN }}
TF_VAR_SPLUNK_HEC_ENDPOINT: ${{ secrets.SPLUNK_HEC_ENDPOINT }}
TF_VAR_OPERATOR_EMAILS: ${{ vars.SECRET_ROTATION_OPERATOR_EMAILS }}
run: |
mkdir -p ./build
echo "π Deploying ${{ needs.validate.outputs.dev_tag }} to PREPROD"
make terraform env=$ENVIRONMENT stack=networking tf-command=apply workspace=$WORKSPACE
make terraform env=$ENVIRONMENT stack=api-layer tf-command=apply workspace=$WORKSPACE
working-directory: ./infrastructure
- name: "Validate Feature Toggles"
env:
ENV: preprod
run: |
pip install boto3
python scripts/feature_toggle/validate_toggles.py
- name: "Create Release Candidate tag"
id: release
env:
DEV_TAG: ${{ needs.validate.outputs.dev_tag }}
INPUT_RELEASE_TYPE: ${{ inputs.release_type }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ENVIRONMENT: preprod
run: |
pip install requests
python scripts/workflow/tag_and_release.py
- name: "Capture RC tag"
id: rc_tag_file
run: |
RC_TAG=$(cat release_tag.txt)
echo "rc_tag=$RC_TAG" >> $GITHUB_OUTPUT
echo "β
Created release candidate: $RC_TAG"
- name: "Get preprod S3 bucket"
id: preprod_bucket
run: |
cd infrastructure
make terraform env=preprod stack=api-layer tf-command=init workspace=default
BUCKET=$(terraform -chdir=./stacks/api-layer output -raw lambda_artifact_bucket)
echo "name=$BUCKET" >> $GITHUB_OUTPUT
- name: "Upload lambda to preprod S3"
run: |
RC_TAG="${{ steps.rc_tag_file.outputs.rc_tag }}"
BUCKET="${{ steps.preprod_bucket.outputs.name }}"
aws s3 cp ./dist/lambda.zip \
"s3://$BUCKET/artifacts/$RC_TAG/lambda.zip" \
--region eu-west-2
echo "β
Artifact available for production deployment"
preprod-regression:
name: "PreProd Regression Tests"
needs: [deploy-to-preprod]
uses: ./.github/workflows/regression-tests.yml
with:
ENVIRONMENT: "preprod"
VERSION_NUMBER: "main"
secrets: inherit
summary:
name: "Deployment Summary"
runs-on: ubuntu-latest
needs: [validate, deploy-to-test, deploy-to-preprod, preprod-regression]
if: always()
steps:
- name: "Print summary"
run: |
echo "## π Release Candidate Pipeline Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Dev Tag:** \`${{ needs.validate.outputs.dev_tag }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${{ needs.validate.outputs.commit_sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Deployment Status" >> $GITHUB_STEP_SUMMARY
echo "- Test: ${{ needs.deploy-to-test.result || 'skipped' }}" >> $GITHUB_STEP_SUMMARY
echo "- PreProd: ${{ needs.deploy-to-preprod.result }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.deploy-to-preprod.result }}" == "success" ]]; then
echo "### β
Release Candidate Created" >> $GITHUB_STEP_SUMMARY
echo "\`${{ needs.deploy-to-preprod.outputs.rc_tag }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Ready for production deployment!**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To deploy to production, run:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "Workflow: 5. CD | Deploy to Prod" >> $GITHUB_STEP_SUMMARY
echo "RC Tag: ${{ needs.deploy-to-preprod.outputs.rc_tag }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
fi