-
Notifications
You must be signed in to change notification settings - Fork 9
276 lines (235 loc) · 9.52 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
name: 111 Adaptor Build Workflow
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- master
push:
branches:
- master
jobs:
checkstyle:
name: Checkstyle
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Java 21 LTS
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Checkstyle
run: |
./gradlew checkStyleMain checkstyleTest checkstyleIntegrationTest --parallel
working-directory: ./service
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
cp -r ./service/build/reports ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'Checkstyle Reports'
path: ./artifacts/**
compression-level: 9
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
spotbugs:
name: Spotbugs
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Java 21 LTS
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Spotbugs
run: |
./gradlew spotbugsMain spotbugsTest spotbugsIntegrationTest --parallel
working-directory: ./service
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
cp -r ./service/build/reports ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'Spotbugs Reports'
path: ./artifacts/**
compression-level: 9
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
needs: [ checkstyle, spotbugs ]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Java 21 LTS
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Execute Unit Tests
run: ./gradlew test jacocoTestReport --parallel --build-cache
working-directory: ./service
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
cp -r ./service/build/reports ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'Unit Test Reports'
path: ./artifacts/**
compression-level: 9
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: [ checkstyle, spotbugs ]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Java 21 LTS
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Start Docker Dependencies
env:
PEM111_AMQP_BROKER: "amqp://activemq:5672"
PEM111_AMQP_PORT: "5672"
PEM111_ITK_EXTERNAL_CONFIGURATION_URL: "http://wiremock:8080/configuration/ods-dos"
LOG_LEVEL: DEBUG
run: |
docker network create 111network
docker compose build
docker compose up activemq wiremock --detach
working-directory: ./docker
- name: Execute Integration Tests
run: ./gradlew integrationTest
working-directory: ./service
- name: Dump Docker Logs
if: always()
run: ./dump_docker_logs.sh
working-directory: ./scripts
shell: bash
- name: Collect Artifacts
if: always()
run: |
mkdir -p artifacts
cp -r ./service/build/reports ./artifacts
cp -r ./scripts/logs ./artifacts
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: 'Integration Test Reports & Docker Logs'
path: ./artifacts/**
compression-level: 9
- name: Stop Docker Dependencies
if: always()
run: |
docker compose down --rmi=local --volumes --remove-orphans
docker compose rm
docker network rm 111network
working-directory: ./docker
- name: Temporary Artifacts Cleanup
run: rm -rf ./artifacts
generate-build-id:
name: Generate Build ID
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests]
outputs:
build-id: ${{ steps.generate.outputs.buildId }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- id: generate
working-directory: ./scripts
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
GIT_BRANCH=PR
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/master" ]]; then
GIT_BRANCH=master
fi
BUILD_ID=$(./create_build_id.sh $GIT_BRANCH ${{ github.run_number }} ${{ github.sha }})
echo "Generated the build tag: $BUILD_ID"
echo "buildId=$BUILD_ID" >> $GITHUB_OUTPUT
build-and-publish-docker-images:
name: Build & Publish Docker Images
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests, generate-build-id]
permissions:
id-token: write
contents: read
strategy:
matrix:
config:
- directory: service
repository: 111
build-context: .
- directory: nginx
repository: 111-nginx
build-context: .
if: github.actor != 'dependabot[bot]'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: 111_github_action_build_workflow
aws-region: ${{ secrets.AWS_REGION || 'eu-west-2' }}
- name: Build Docker Image
run: |
# Create Docker Tag
DOCKER_REGISTRY="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
DOCKER_TAG="$DOCKER_REGISTRY/${{ matrix.config.repository }}:${{ needs.generate-build-id.outputs.build-id }}"
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
# Build Image
docker build -f ./docker/${{ matrix.config.directory }}/Dockerfile -t $DOCKER_TAG ${{ matrix.config.build-context }}
- name: Login to AWS ECR
run: |
DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin $DOCKER_REGISTRY
- name: Publish image to ECR
run: docker push $DOCKER_TAG
- name: Logout of AWS ECR (Clean up Credentials)
if: always()
run: |
DOCKER_REGISTRY="https://${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
docker logout $DOCKER_REGISTRY
comment:
if: github.event_name == 'pull_request'
name: "Create Build ID Comment"
needs: [generate-build-id]
continue-on-error: true
permissions: write-all
runs-on: [ ubuntu-latest ]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Comment PR
uses: thollander/actions-comment-pull-request@v3
with:
message: |
Images built and published to ECR using a Build Id of ${{ needs.generate-build-id.outputs.build-id }}
comment_tag: images-built
mode: upsert