This repository has been archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
303 lines (268 loc) · 9.43 KB
/
merge-main.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
name: Merge to Main
on:
push:
branches:
- main
paths-ignore:
- ".github/ISSUE_TEMPLATE/*"
- "**.md"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
codeql:
name: Semantic Code Analysis
runs-on: ubuntu-22.04
permissions:
actions: read
contents: read
security-events: write
steps:
- uses: actions/checkout@v3
- name: Initialize
uses: github/codeql-action/init@v2
with:
debug: true
languages: java
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
# SonarCloud runs in the main branch are needed to compare against PRs
sonarcloud:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.m2
key: ${{ runner.os }}-maven-test-${{ hashFiles('**/backend/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-test-
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Unit Tests
run: mvn --no-transfer-progress test --file backend/pom.xml
- name: Integration Tests
run: mvn --no-transfer-progress verify -P integration-test --file backend/pom.xml
- name: Code Coverage
run: mvn --no-transfer-progress clean verify -P all-tests --file backend/pom.xml
- name: Generate JaCoCo Badge
uses: cicirello/jacoco-badge-generator@v2
id: jacoco
with:
generate-branches-badge: true
jacoco-csv-file: backend/target/coverage-reports/merged-test-report/jacoco.csv
- name: Log coverage percentage
run: |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"
- name: Commit the badge (if it changed)
run: |
if [[ `git status --porcelain` ]]; then
git config --global user.name 'CI Bot'
git config --global user.email '[email protected]'
git add -A
git commit -m "ci: autogenerated JaCoCo coverage badge"
git push
fi
- name: Upload JaCoCo coverage report
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: backend/target/coverage-reports/merged-test-report/
- name: SonarCloud Scan
run: mvn --no-transfer-progress clean verify package -P all-tests sonar:sonar -Dsonar.projectKey=bcgov_nr-spar-backend -Dsonar.coverage.jacoco.xmlReportPaths=target/coverage-reports/merged-test-report/jacoco.xml --file backend/pom.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# Generate release notes and update new version
release:
name: Release Notes
runs-on: ubuntu-latest
outputs:
version: ${{ steps.changelog.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
- uses: actions/cache@v3
with:
path: |
~/.m2
key: ${{ runner.os }}-maven-test-${{ hashFiles('**/backend/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-test-
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Conventional Changelog Update
continue-on-error: true
uses: TriPSs/conventional-changelog-action@v3
id: changelog
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
output-file: 'CHANGELOG.md'
skip-version-file: 'true'
skip-commit: 'true'
git-push: 'false'
skip-on-empty: 'false'
- name: Set new version
run: |
echo "::set-output name=version::${{ steps.changelog.outputs.version }}"
mvn versions:set -DnewVersion='${{ steps.changelog.outputs.version }}' -f backend/pom.xml -DskipTests -Dtests.skip=true -Dskip.unit.tests=true
- name: Update POM
run: mvn versions:commit --file backend/pom.xml
- name: Commit pom and changelog
uses: EndBug/add-and-commit@v9
with:
author_name: Ci Bot
author_email: [email protected]
message: 'doc: updating pom to ${{ steps.changelog.outputs.version }} [ci skip]'
add: '["backend/pom.xml","CHANGELOG.md"]'
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
tag_name: ${{ steps.changelog.outputs.tag }}
release_name: ${{ steps.changelog.outputs.tag }}
body: ${{ steps.changelog.outputs.clean_changelog }}
deploy-test:
name: TEST Deployment
needs:
- codeql
- sonarcloud
- release
environment: test
runs-on: ubuntu-22.04
strategy:
matrix:
name: [ init, database, backend ]
include:
- name: init
file: common/openshift.init.yml
overwrite: false
- name: database
file: database/openshift.deploy.yml
overwrite: false
- name: backend
file: backend/openshift.deploy.yml
overwrite: true
parameters: -p MIN_REPLICAS=1 -p MAX_REPLICAS=2 -p BUILD=test-${{ needs.release.outputs.version }}
steps:
- uses: bcgov-nr/[email protected]
with:
file: ${{ matrix.file }}
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_server: ${{ secrets.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: ${{ matrix.overwrite }}
penetration_test: false
verification_path: "actuator/health"
parameters:
-p ZONE=test -p NAME=${{ github.event.repository.name }}
-p PROMOTE=${{ github.repository }}/${{ matrix.name }}:test
${{ matrix.parameters }}
api-tests:
name: Newman API tests runner
needs:
- deploy-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install newman
run: |
npm install -g newman
npm install -g newman-reporter-htmlextra
- name: Make Directory for Test Results
run: mkdir -p testArtifacts
- name: Run Postman Collection
run: |
newman run test/postman/starting-api.postman_collection.json -e test/postman/starting-api.postman_environment.json \
--env-var "releaseVer=test=${{ env.NR_SPAR_BACKEND_VERSION }}" \
--env-var "authServer=${{ secrets.KEYCLOAK_SERVER_REALM }}" \
--env-var "authClient=${{ secrets.KC_SERVICE_ACCOUNT_NAME }}" \
--env-var "authClient=${{ secrets.KC_SERVICE_ACCOUNT_PASS }}" \
--suppress-exit-code -r htmlextra --reporter-htmlextra-export testArtifacts/api-tests-report.html
- name: Output the results
uses: actions/upload-artifact@v3
with:
name: API test report
path: testArtifacts
deploy-prod:
name: PROD Deployment
needs:
- api-tests
environment: prod
runs-on: ubuntu-22.04
strategy:
matrix:
name: [ init, database, backend ]
include:
- name: init
file: common/openshift.init.yml
overwrite: false
- name: database
file: database/openshift.deploy.yml
overwrite: false
- name: backend
file: backend/openshift.deploy.yml
overwrite: true
parameters: -p BUILD=prod-${{ needs.release.outputs.version }}
steps:
- uses: bcgov-nr/[email protected]
with:
file: ${{ matrix.file }}
oc_namespace: ${{ secrets.OC_NAMESPACE }}
oc_server: ${{ secrets.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: ${{ matrix.overwrite }}
penetration_test: false
verification_path: "actuator/health"
parameters:
-p ZONE=prod -p NAME=${{ github.event.repository.name }}
-p PROMOTE=${{ github.repository }}/${{ matrix.name }}:test
${{ matrix.parameters }}
image-promotions:
name: Promote Images to PROD
needs:
- deploy-prod
runs-on: ubuntu-22.04
strategy:
matrix:
component: [backend, database]
steps:
- uses: shrink/actions-docker-registry-tag@v3
with:
registry: ghcr.io
repository: ${{ github.repository }}/${{ matrix.component }}
target: test
tags: prod