-
Notifications
You must be signed in to change notification settings - Fork 0
336 lines (310 loc) · 9.99 KB
/
test-actions.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
name: Test actions
on:
pull_request:
branches: [trunk]
paths:
- '.github/workflows/test-actions.yml'
- '.github/test/**'
- '.github/test-go/**'
- '**/action.yml'
- '**/requirements.txt'
- '**/*.py'
- '!README.md'
workflow_dispatch:
inputs:
runner:
description: 'Runner'
required: true
default: 'elvia-runner'
type: 'string'
env:
APPLICATION_BASE_NAME: 'demo-api'
SYSTEM_NAME: 'core'
jobs:
set-matrices:
name: Set matrices
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrices.outputs.matrix }}
matrix-trivy: ${{ steps.set-matrices.outputs.matrix-trivy }}
matrix-build: ${{ steps.set-matrices.outputs.matrix-build }}
matrix-deploy: ${{ steps.set-matrices.outputs.matrix-deploy }}
steps:
- name: Set matrices
id: set-matrices
run: |
# Runner matrix
echo "matrix={\"runner\":[\"$RUNNER\"]}" >> "$GITHUB_OUTPUT"
# Trivy matrix
{
echo 'matrix-trivy<<EOF'
cat << EOF
{
"runner": ["$RUNNER","ubuntu-latest"]
}
EOF
echo EOF
} >> "$GITHUB_OUTPUT"
# Build matrix
{
echo 'matrix-build<<EOF'
cat << EOF
{
"runner": ["$RUNNER","ubuntu-latest"],
"project-file": [".github/test/src/core-demo-api.csproj",".github/test-go/go.mod",".github/test-go/Dockerfile"],
"registry": ["","ghcr.io/3lvia"],
"include": [
{
"application-name": "${{ env.APPLICATION_BASE_NAME }}-go",
},
{
"project-file": ".github/test/src/core-demo-api.csproj",
"application-name": "${{ env.APPLICATION_BASE_NAME }}",
}
]
}
EOF
echo EOF
} >> "$GITHUB_OUTPUT"
# Deploy matrix
{
echo 'matrix-deploy<<EOF'
cat << EOF
{
"runner": ["$RUNNER","ubuntu-latest"],
"application-name": ["${{ env.APPLICATION_BASE_NAME }}", "${{ env.APPLICATION_BASE_NAME }}-go"],
"include": [
{
"helm-values-path": ".github/test/deploy/values.yml"
},
{
"application-name": "${{ env.APPLICATION_BASE_NAME }}-go",
"helm-values-path": ".github/test-go/deploy/values.yml"
}
]
}
EOF
echo EOF
} >> "$GITHUB_OUTPUT"
env:
RUNNER: ${{ github.event_name == 'workflow_dispatch' && inputs.runner || 'elvia-runner' }}
unit-tests:
name: Unit Tests
needs: [set-matrices]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-unit-tests'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
permissions:
contents: read
checks: write
issues: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./unittest
with:
checkout: 'false'
integration-tests:
name: Integration Tests
needs: [set-matrices]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-integration-tests'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
permissions:
contents: read
checks: write
issues: read
pull-requests: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./integrationtest
with:
checkout: 'false'
system: ${{ env.SYSTEM_NAME }}
analyze:
name: Analyze
needs: [set-matrices]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-analyze'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./analyze
with:
checkout: 'false'
build:
name: Build
needs: [set-matrices]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix-build) }}
concurrency:
group: |
${{ github.workflow }}-${{ github.event_name }}-${{ github.job }}-${{ matrix.runner }}-${{ matrix.application-name }}-${{ matrix.project-file }}-${{ matrix.docker-include-files }}-${{ matrix.registry }}
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
permissions:
contents: read
id-token: write
packages: write # Required for publishing to GitHub Container Registry
security-events: write
environment: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./build
with:
checkout: 'false'
name: ${{ matrix.application-name }}
namespace: ${{ env.SYSTEM_NAME }}
project-file: ${{ matrix.project-file }}
docker-additional-tags: 'v42,v1.2.3'
docker-include-files: ${{ matrix.docker-include-files }}
severity: 'CRITICAL'
registry: ${{ matrix.registry }}
trivy-upload-report: 'true'
trivy-post-comment: 'true'
AZURE_CLIENT_ID: ${{ vars.ACR_CLIENT_ID }}
deploy-dev:
name: Deploy Dev
needs: [set-matrices, build]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix-deploy) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.application-name }}-deploy-dev'
cancel-in-progress: false
runs-on: ${{ matrix.runner }}
permissions:
contents: read
id-token: write
environment: dev
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./deploy
with:
checkout: 'false'
name: ${{ matrix.application-name }}
namespace: ${{ env.SYSTEM_NAME }}
environment: 'dev'
helm-values-path: ${{ matrix.helm-values-path }}
slack-channel: '#team-core-alerts-muted'
AZURE_CLIENT_ID: ${{ vars.AKS_CLIENT_ID }}
deploy-dev-gke:
name: Deploy Dev GKE
needs: [set-matrices, build]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix-deploy) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.application-name }}-deploy-dev-gke'
cancel-in-progress: false
runs-on: ${{ matrix.runner }}
permissions:
contents: read
id-token: write
environment: dev
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./deploy
with:
checkout: 'false'
name: ${{ matrix.application-name }}
namespace: ${{ env.SYSTEM_NAME }}
environment: 'dev'
helm-values-path: ${{ matrix.helm-values-path }}
runtime-cloud-provider: 'GKE'
GC_SERVICE_ACCOUNT: ${{ vars.GC_SERVICE_ACCOUNT }}
GC_WORKLOAD_IDENTITY_PROVIDER: ${{ vars.GC_WORKLOAD_IDENTITY_PROVIDER }}
trivy-iac-scan:
name: Trivy IaC Scan
needs: [set-matrices]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix-trivy) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-trivy-iac-scan'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./trivy-iac-scan
with:
checkout: 'false'
terraform-format-check:
name: Terraform Format Check
needs: [set-matrices]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-terraform-format-check'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./terraform-format
with:
checkout: 'false'
slack-message-vault:
name: Slack Message using Vault
needs: [set-matrices]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-slack-message-vault'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./slack-message
with:
slack-channel: '#team-core-alerts-muted'
message: ':test_tube: Testing Slack Message using Vault in ${{ github.workflow }} for ${{ github.event_name }} event.'
environment: 'dev'
namespace: 'core'
slack-message-token:
name: Slack Message using token
needs: [set-matrices]
strategy:
matrix: ${{ fromJson(needs.set-matrices.outputs.matrix) }}
concurrency:
group: '${{ github.workflow }}-${{ github.event_name }}-${{ matrix.runner }}-slack-message-token'
cancel-in-progress: true
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: ./slack-message
with:
slack-channel: '#team-core-alerts-muted'
message: ':test_tube: Testing Slack Message using token in ${{ github.workflow }} for ${{ github.event_name }} event.'
slack-api-token: ${{ secrets.SLACK_API_TOKEN }}