-
Notifications
You must be signed in to change notification settings - Fork 2
193 lines (176 loc) · 6.69 KB
/
workflow_pr.yml
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
name: "[Workflow] PR"
on:
pull_request:
branches:
- main
permissions:
actions: none
checks: none
contents: write
deployments: none
id-token: write
issues: write
packages: none
pull-requests: write
repository-projects: none
security-events: write
statuses: none
defaults:
run:
shell: bash
jobs:
detect_changes:
name: Detect Changes
uses: ./.github/workflows/detect_changes_to_app_job.yml
create_tags:
name: Create Tags
needs: detect_changes
uses: ./.github/workflows/tags_job.yml
with:
changes_detected: ${{ needs.detect_changes.outputs.changes_detected }}
go_unit_tests:
name: Run Go unit tests
if: needs.detect_changes.outputs.changes_detected == 'true'
needs: create_tags
uses: ./.github/workflows/go-unit-tests.yml
with:
tag: ${{ needs.create_tags.outputs.version_tag }}
commit_sha: ${{ github.event.pull_request.head.sha }}
branch: ${{ github.head_ref }}
secrets:
pact_broker_password: ${{ secrets.PACT_BROKER_PASSWORD }}
codecov_token: ${{ secrets.CODECOV_TOKEN }}
docker_build_scan_push:
name: Docker Build, Scan and Push
if: needs.detect_changes.outputs.changes_detected == 'true' &&
(needs.go_unit_tests.result == 'success' || needs.go_unit_tests.result == 'skipped')
uses: ./.github/workflows/docker_job.yml
needs: [
go_unit_tests,
create_tags
]
with:
tag: ${{ needs.create_tags.outputs.version_tag }}
branch_name: ${{ github.head_ref }}
terraform_account_workflow_development:
name: TF Plan Dev Account
uses: ./.github/workflows/terraform_account_job.yml
with:
workspace_name: development
secrets:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
pagerduty_api_key: ${{ secrets.PAGERDUTY_API_KEY }}
terraform_account_workflow_preproduction:
name: TF Plan Preprod Account
needs: terraform_account_workflow_development
uses: ./.github/workflows/terraform_account_job.yml
with:
workspace_name: preproduction
secrets:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
pagerduty_api_key: ${{ secrets.PAGERDUTY_API_KEY }}
terraform_account_workflow_production:
name: TF Plan Prod Account
needs: terraform_account_workflow_development
uses: ./.github/workflows/terraform_account_job.yml
with:
workspace_name: production
secrets:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
pagerduty_api_key: ${{ secrets.PAGERDUTY_API_KEY }}
ui_tests_image:
name: Run Cypress UI Tests On Images
if: needs.detect_changes.outputs.changes_detected == 'true' &&
(needs.docker_build_scan_push.result == 'success' || needs.docker_build_scan_push.result == 'skipped')
uses: ./.github/workflows/ui_test_job.yml
needs: [
docker_build_scan_push,
create_tags
]
with:
run_against_image: true
tag: ${{ needs.create_tags.outputs.version_tag }}
specs: 'cypress/e2e/**/*.cy.js'
secrets:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
cypress_record_key: ${{ secrets.CYPRESS_RECORD_KEY }}
github_access_token: ${{ secrets.GITHUB_TOKEN }}
pr_deploy:
name: PR Environment Deploy
if: always() &&
(needs.go_unit_tests.result == 'success' || needs.go_unit_tests.result == 'skipped') &&
(needs.docker_build_scan_push.result == 'success' || needs.docker_build_scan_push.result == 'skipped') &&
(needs.ui_tests_image.result == 'success' || needs.ui_tests_image.result == 'skipped')
needs: [
create_tags,
go_unit_tests,
docker_build_scan_push,
ui_tests_image
]
uses: ./.github/workflows/terraform_environment_job.yml
with:
workspace_name: ${{ needs.create_tags.outputs.environment_workspace_name }}
version_tag: ${{ needs.create_tags.outputs.version_tag }}
s3_av_scanner_zip_tag: ${{ needs.create_tags.outputs.s3_av_scanner_zip_tag }}
secrets:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
ssh_deploy_key: ${{ secrets.OPG_MODERNISING_LPA_DEPLOY_KEY_PRIVATE_KEY }}
github_access_token: ${{ secrets.GITHUB_TOKEN }}
pagerduty_api_key: ${{ secrets.PAGERDUTY_API_KEY }}
ui_tests_pr_env:
name: Run Cypress UI Tests On PR Environment
if: always() &&
needs.pr_deploy.result == 'success'
uses: ./.github/workflows/ui_test_job.yml
needs: [
pr_deploy,
create_tags
]
with:
run_against_image: false
base_url: "https://${{ needs.pr_deploy.outputs.url }}"
tag: ${{ needs.create_tags.outputs.version_tag }}
environment_config_json: ${{ needs.pr_deploy.outputs.environment_config_json }}
specs: 'cypress/smoke/*.cy.js'
secrets:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
cypress_record_key: ${{ secrets.CYPRESS_RECORD_KEY }}
github_access_token: ${{ secrets.GITHUB_TOKEN }}
always_remove_ingress:
name: Remove CI ingress from environment
if: always()
uses: ./.github/workflows/remove_ingress_job.yml
needs: [ui_tests_pr_env, pr_deploy]
with:
environment_config_json: ${{ needs.pr_deploy.outputs.environment_config_json }}
secrets:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
end_of_pr_workflow:
name: End of PR Workflow
runs-on: ubuntu-latest
if: always()
environment:
name: "dev_${{ needs.create_tags.outputs.environment_workspace_name }}"
url: "https://${{ needs.pr_deploy.outputs.url }}"
needs: [pr_deploy, create_tags, ui_tests_pr_env]
steps:
- name: End of PR Workflow
run: |
echo "${{ needs.pr_deploy.outputs.terraform_workspace_name }} PR environment tested, built and deployed"
echo "Tag Deployed: ${{ needs.pr_deploy.outputs.terraform_container_version }}"
echo "URL: https://${{ needs.pr_deploy.outputs.url }}"
if ${{ contains(needs.ui_tests_pr_env.result,'success') }}
then
echo "PR environment tested, built and deployed"
exit 0
else
echo "PR environment tested, built and deployed but UI tests failed"
exit 1
fi