-
Notifications
You must be signed in to change notification settings - Fork 1
299 lines (253 loc) · 9.04 KB
/
build_test_package.yml
File metadata and controls
299 lines (253 loc) · 9.04 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
name: Build, Test and Package
on:
workflow_dispatch:
push:
branches:
- main
tags:
- '*'
- '!*-test'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- 'main'
- 'release/**'
- 'feature/**'
jobs:
build:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request_target'
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '23'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-version: '8.14'
cache-disabled: true
- name: Build with Gradle
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >
./gradlew
clean
build
spotlessApply
detekt
-x test
-x integrationTest
--no-build-cache
--rerun-tasks
--refresh-dependencies
controller_tests:
runs-on: ubuntu-latest
needs:
- build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions: read-all
if: github.event_name != 'pull_request_target'
strategy:
fail-fast: false
matrix:
service:
- testPrefix: Organization
packageName: .organization
- testPrefix: Workspace
packageName: .workspace
- testPrefix: Solution
packageName: .solution
- testPrefix: Dataset
packageName: .dataset
- testPrefix: Runner
packageName: .runner
- testPrefix: Run
packageName: .run
- testPrefix: Meta
packageName: ".meta"
- testPrefix: Home
packageName: ""
name: controller_tests - ${{ matrix.service.testPrefix }}
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '23'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-version: '8.14'
cache-disabled: true
- name: Run ${{ matrix.service.testPrefix }} controller tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :cosmotech-api:integrationTest --tests "com.cosmotech.api.home${{ matrix.service.packageName }}.${{ matrix.service.testPrefix }}ControllerTests" -x spotlessCheck -x openApiValidate
unit_tests:
runs-on: ubuntu-latest
needs:
- build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions: read-all
if: github.event_name != 'pull_request_target'
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '23'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-version: '8.14'
cache-disabled: true
- name: Run unit tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew test -x spotlessCheck -x openApiValidate
integration_tests:
runs-on: ubuntu-latest
needs:
- build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions: read-all
if: github.event_name != 'pull_request_target'
strategy:
fail-fast: false
matrix:
service:
- testPrefix: Organization
packageName: organization
- testPrefix: Workspace
packageName: workspace
- testPrefix: Solution
packageName: solution
- testPrefix: Dataset
packageName: dataset
- testPrefix: Run
packageName: run
- testPrefix: Runner
packageName: runner
name: integration_tests - ${{ matrix.service.testPrefix }}
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '23'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-version: '8.14'
cache-disabled: true
- name: Run RBAC ${{ matrix.service.packageName }} integration tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :cosmotech-${{ matrix.service.packageName }}-api:integrationTest --tests "com.cosmotech.${{ matrix.service.packageName }}.service.${{ matrix.service.testPrefix }}ServiceRBACTest" -x spotlessCheck -x openApiValidate
if: ${{ matrix.service.packageName != 'run' }}
- name: Run ${{ matrix.service.packageName }} integration tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :cosmotech-${{ matrix.service.packageName }}-api:integrationTest --tests "com.cosmotech.${{ matrix.service.packageName }}.service.${{ matrix.service.testPrefix }}ServiceIntegrationTest" -x spotlessCheck -x openApiValidate
scan_and_push_container_images_to_registries:
runs-on: ubuntu-latest
needs:
- unit_tests
- integration_tests
- controller_tests
permissions:
packages: write
contents: read
security-events: write
env:
DOCKER_BUILDKIT: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
# Fetch all tags since Gradle project version is built upon SCM
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "23"
- name: Retrieve branch or tag name
id: refvar
run: echo "gitRefName=${GITHUB_REF#refs/*/}" >> "${GITHUB_OUTPUT}"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-version: '8.14'
cache-disabled: true
- name: Build local Container Image for scanning
run: >
./gradlew
:cosmotech-api:jibDockerBuild
-Djib.to.image=com.cosmotech/cosmotech-api:${{ github.sha }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.30.0
id: scan
# Add TRIVY_DB_REPOSITORY due to ratelimit issue
# https://github.com/aquasecurity/trivy-action/issues/389
env:
DOCKLE_HOST: "unix:///var/run/docker.sock"
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2
TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1
# TODO For now, do not block if the container scan action returns issues
continue-on-error: true
with:
image-ref: com.cosmotech/cosmotech-api:${{ github.sha }}
format: "sarif"
severity: "CRITICAL,HIGH"
output: "trivy-results.sarif"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
- name: Archive container image scan report
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: container-image-scan-report
path: "trivy-results.sarif"
retention-days: 3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3.4.0
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push API Container Image (sha) to GitHub Container Registry
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
run: |
docker image tag com.cosmotech/cosmotech-api:${{github.sha}} \
ghcr.io/cosmo-tech/cosmotech-api:${{github.sha}}
docker image push ghcr.io/cosmo-tech/cosmotech-api:${{github.sha}}
- name: Push API Container Image (tag) to GitHub Container Registry
if: startsWith(github.ref, 'refs/tags/')
run: |
docker image tag com.cosmotech/cosmotech-api:${{github.sha}} \
ghcr.io/cosmo-tech/cosmotech-api:${{ steps.refvar.outputs.gitRefName }}
docker image push ghcr.io/cosmo-tech/cosmotech-api:${{ steps.refvar.outputs.gitRefName }}
- name: Push API Container Image (latest) to GitHub Container Registry
if: github.ref == 'refs/heads/main'
run: |
docker image tag com.cosmotech/cosmotech-api:${{github.sha}} \
ghcr.io/cosmo-tech/cosmotech-api:latest
docker image push ghcr.io/cosmo-tech/cosmotech-api:latest
curl --request POST \
--url "https://api.github.com/repos/cosmo-tech/helm-charts/actions/workflows/api_restart.yml/dispatches" \
--header "Accept: application/vnd.github.v3+json" \
--header "Authorization: Bearer ${{ secrets.TRIGGER_HELM_CHARTS_WORKFLOW_PAT }}" \
--data '{ "ref": "main" }'