-
Notifications
You must be signed in to change notification settings - Fork 0
282 lines (248 loc) · 8.82 KB
/
build.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
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
name: Test & Build
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
defaults:
run:
shell: bash
jobs:
identify:
name: Identify version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Define commit SHA and branch
id: commit_branch
run: |
if [ "${{ github.head_ref }}" == "" ]; then
echo "COMMIT=${{github.sha}}" >> $GITHUB_OUTPUT
echo "BRANCH=main" >> $GITHUB_OUTPUT
else
echo "COMMIT=${{github.event.pull_request.head.sha}}" >> $GITHUB_OUTPUT
echo "BRANCH=${{github.head_ref}}" >> $GITHUB_OUTPUT
fi
- name: Bump version
id: bump_version
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INITIAL_VERSION: 1.0.0
DEFAULT_BRANCH: main
DEFAULT_BUMP: minor
PRERELEASE: true
PRERELEASE_SUFFIX: ${{ steps.commit_branch.outputs.BRANCH }}
RELEASE_BRANCHES: main
WITH_V: true
outputs:
commit: ${{ steps.commit_branch.outputs.COMMIT }}
branch: ${{ steps.commit_branch.outputs.BRANCH }}
tag: ${{ steps.bump_version.outputs.tag }}
build:
name: Build LPA Dashboard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache Images
uses: actions/cache@v4
with:
path: /tmp/images
key: ${{ runner.os }}-images-${{ github.run_id }}-${{ github.run_number }}
- name: Build Images
run: |
make build-ci
mkdir -p /tmp/images
docker save -o /tmp/images/app.tar 311462405659.dkr.ecr.eu-west-1.amazonaws.com/sirius/sirius-lpa-dashboard:latest
docker save -o /tmp/images/pact-stub.tar pact-stub:latest
test:
name: Unit Tests
runs-on: ubuntu-latest
needs: [identify]
steps:
- uses: actions/checkout@v4
- uses: unfor19/install-aws-cli-action@v1
- name: Cache Go Dependencies
uses: actions/cache@v4
with:
path: .gocache
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Tests
run: make unit-test
- name: Publish pacts
run: |
docker compose run --rm pact pact-broker publish ./pacts/sirius-lpa-dashboard-sirius.json \
--consumer-app-version ${{ needs.identify.outputs.commit }} \
--branch ${{ needs.identify.outputs.branch }} \
--tag ${{ needs.identify.outputs.tag }} \
--broker-base-url https://pact-broker.api.opg.service.justice.gov.uk \
--broker-username admin \
--broker-password ${{ secrets.PACT_BROKER_PASSWORD }}
- name: Upload Code Coverage
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: test-results/test-coverage.txt
fail_ci_if_error: true
verbose: true
- name: Persist Pacts
uses: actions/upload-artifact@v4
with:
name: pacts
path: |
./pacts/sirius-lpa-dashboard-sirius.json
./pacts/ignored-ignored.json
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run linting
run: make lint
acceptance-test:
name: Acceptance Tests
runs-on: ubuntu-latest
needs:
- build
- test
steps:
- uses: actions/checkout@v4
- name: Cache Images
uses: actions/cache@v4
with:
path: /tmp/images
key: ${{ runner.os }}-images-${{ github.run_id }}-${{ github.run_number }}
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: pacts
path: ./pacts
- name: Restore images
run: |
docker load -i /tmp/images/app.tar
docker load -i /tmp/images/pact-stub.tar
- name: Run pa11y
run: make pa11y
- name: Run Lighthouse
run: make lighthouse
cypress:
name: Cypress
runs-on: ubuntu-latest
needs:
- build
- test
steps:
- uses: actions/checkout@v4
- name: Cache Images
uses: actions/cache@v4
with:
path: /tmp/images
key: ${{ runner.os }}-images-${{ github.run_id }}-${{ github.run_number }}
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: pacts
path: ./pacts
- name: Restore images
run: |
docker load -i /tmp/images/app.tar
docker load -i /tmp/images/pact-stub.tar
- name: Start app
run: make cypress
- name: Upload Cypress screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
push:
name: "Build & Push Containers"
runs-on: ubuntu-latest
needs: [identify, "build", "test", "lint", "acceptance-test", "cypress"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Extract branch name
run: |
if [ "${{ github.head_ref }}" == "" ]; then
echo BRANCH_NAME=main >> $GITHUB_ENV
else
echo BRANCH_NAME=$(echo ${{ github.head_ref }} | sed 's/\//-/g') >> $GITHUB_ENV
fi
id: extract_branch
- uses: unfor19/install-aws-cli-action@v1
- name: Cache Images
uses: actions/cache@v4
with:
path: /tmp/images
key: ${{ runner.os }}-images-${{ github.run_id }}-${{ github.run_number }}
- name: Restore Image
run: docker load -i /tmp/images/app.tar
- name: Run Trivy
run: make scan
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'test-results/trivy.sarif'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
aws-region: eu-west-1
role-to-assume: arn:aws:iam::311462405659:role/sirius-actions-ci
role-duration-seconds: 3600
role-session-name: GitHubActions
- name: ECR Login
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registries: 311462405659
- name: Push Container
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: sirius/sirius-lpa-dashboard
run: |
docker tag 311462405659.dkr.ecr.eu-west-1.amazonaws.com/sirius/sirius-lpa-dashboard:latest $ECR_REGISTRY/$ECR_REPOSITORY:${{ needs.identify.outputs.tag }}
if [ "${{ needs.identify.outputs.branch }}" == "main" ]; then
docker tag 311462405659.dkr.ecr.eu-west-1.amazonaws.com/sirius/sirius-lpa-dashboard:latest $ECR_REGISTRY/$ECR_REPOSITORY:main-${{ needs.identify.outputs.tag }}
docker tag 311462405659.dkr.ecr.eu-west-1.amazonaws.com/sirius/sirius-lpa-dashboard:latest $ECR_REGISTRY/$ECR_REPOSITORY:main-${{ needs.identify.outputs.tag }}-$(date +"%Y%m%d%H%M%S")
# We want all of the tags pushed
docker push --all-tags $ECR_REGISTRY/$ECR_REPOSITORY
else
docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{ needs.identify.outputs.tag }}
fi
push-tags:
runs-on: ubuntu-latest
needs: [identify, push]
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_ACTIONS }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ACTIONS }}
aws-region: eu-west-1
role-to-assume: arn:aws:iam::997462338508:role/sirius-actions-ci
role-duration-seconds: 3600
role-session-name: GitHubActions
- name: Install AWS CLI
id: install-aws-cli
uses: unfor19/install-aws-cli-action@v1
- name: Push Tag to Parameter Store
run: |
aws ssm put-parameter --name "opg-sirius-lpa-dashboard-latest-green-build" --type "String" --value "${{ needs.identify.outputs.tag }}" --overwrite --region=eu-west-1
- name: Trigger Dev Deploy
shell: bash
run: curl -u ${{ secrets.JENKINS_API_USER }}:${{ secrets.JENKINS_API_TOKEN }} "https://${{ secrets.JENKINS_URL }}/job/Sirius/job/Deploy_to_Development/build?token=${{ secrets.JENKINS_API_TOKEN_NAME }}&cause=Triggered+by+opg-sirius-lpa-dashboard"