-
Notifications
You must be signed in to change notification settings - Fork 363
347 lines (294 loc) · 14.9 KB
/
detection-testing.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
337
338
339
340
341
342
343
344
345
346
347
# name: detection-testing
# on:
# push:
# pull_request:
# types: [opened, reopened]
# schedule:
# - cron: "44 4 * * *"
# jobs:
# validate-tag-if-present:
# runs-on: ubuntu-latest
# steps:
# - name: TAGGED, Validate that the tag is in the correct format
# run: |
# echo "The GITHUB_REF: $GITHUB_REF"
# #First check to see if the release is a tag
# if [[ $GITHUB_REF =~ refs/tags/* ]]; then
# #Yes, this is a tag, so we need to test to make sure that the tag
# #is in the correct format (like v1.10.20)
# if [[ $GITHUB_REF =~ refs/tags/v[0-9]+.[0-9]+.[0-9]+ ]]; then
# echo "PASS: Tagged release with good format"
# exit 0
# else
# echo "FAIL: Tagged release with bad format"
# exit 1
# fi
# else
# echo "PASS: Not a tagged release"
# exit 0
# fi
# quit-for-dependabot:
# runs-on: ubuntu-latest
# if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]'
# steps:
# - name: "Placeholder"
# run: |
# echo "yes it ran"
# docker-detection-testing-setup:
# runs-on: ubuntu-latest
# if: "!contains(github.ref, 'refs/tags/')" #don't run on tags - future steps won't run either since they depend on this job
# needs: [validate-tag-if-present, quit-for-dependabot]
# steps:
# - name: Get branch and PR required for detection testing main.py
# id: vars
# run: |
# echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
# - name: Checkout Repo
# uses: actions/checkout@v2
# #with:
# # ref: develop
# - uses: actions/setup-python@v2
# with:
# python-version: '3.9' #Available versions here - https://github.com/actions/python-versions/releases easy to change/make a matrix/use pypy
# architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
# cache: 'pip'
# - name: Install Python Dependencies
# run: |
# python -m venv .venv
# source .venv/bin/activate
# python -m pip install wheel
# python -m pip install -r requirements.txt
# - name: Run the CI
# run: |
# source .venv/bin/activate
# cd bin/docker_detection_tester
# echo "github.event.issue.pull_request : [${{ github.event.issue.pull_request }}]"
# echo "github.event.pull_request.number : [${{ github.event.pull_request.number }}]"
# echo "steps.vars.outputs.branch : [${{ steps.vars.outputs.branch }}]"
# echo "github.event.pull_request.head.ref : [${{ github.event.pull_request.head.ref }}]"
# echo "github.event_name : [${{ github.event_name }}]"
# if [[ ${{ github.event_name }} == schedule ]]; then
# # Note that scheduled actions ONLY run on the default branch, so it won't run on all other branches!
# echo "Running a nightly test on all detections OR a commit was made directly to develop"
# python detection_testing_execution.py run --branch develop --mode all --mock --config_file test_config_github_actions.json
# elif [[ ! -z "${{ github.event.pull_request.head.ref }}" && ! -z "${{ github.event.pull_request.number }}" ]]; then
# echo "Pull request from source branch [${{ github.event.pull_request.head.ref }}] for PR number [${{ github.event.issue.number }}]"
# python detection_testing_execution.py run --branch ${{ github.event.pull_request.head.ref }} --pr_number ${{ github.event.pull_request.number }} --mode changes --mock --config_file test_config_github_actions.json
# else
# echo "Push from branch [${{ steps.vars.outputs.branch }}]"
# python detection_testing_execution.py run --branch ${{ steps.vars.outputs.branch }} --mode changes --mock --config_file test_config_github_actions.json
# fi
# mv *-test-run.json replicate_test.json
# - name: Upload Test Results Files
# uses: actions/upload-artifact@v2
# with:
# name: testing-results-config
# path: |
# bin/docker_detection_tester/prior_config/apps/DA-ESS-ContentUpdate-latest.tar.gz
# bin/docker_detection_tester/prior_config/config_tests_0.json
# bin/docker_detection_tester/prior_config/config_tests_1.json
# bin/docker_detection_tester/prior_config/config_tests_2.json
# bin/docker_detection_tester/prior_config/config_tests_3.json
# bin/docker_detection_tester/prior_config/config_tests_4.json
# bin/docker_detection_tester/prior_config/config_tests_5.json
# bin/docker_detection_tester/prior_config/config_tests_6.json
# bin/docker_detection_tester/prior_config/config_tests_7.json
# bin/docker_detection_tester/prior_config/config_tests_8.json
# bin/docker_detection_tester/prior_config/config_tests_9.json
# - name: Upload File to Enable Replication of the Test at a Different Time or Place
# uses: actions/upload-artifact@v2
# with:
# name: replicate_test
# path: |
# bin/docker_detection_tester/replicate_test.json
# docker-detection-testing-execution:
# runs-on: ubuntu-latest
# if: "!contains(github.ref, 'refs/tags/')" #don't run on tags - future steps won't run either since they depend on this job
# needs: [docker-detection-testing-setup]
# strategy:
# matrix:
# manifest_filename: ["config_tests_0.json",
# "config_tests_1.json",
# "config_tests_2.json",
# "config_tests_3.json",
# "config_tests_4.json",
# "config_tests_5.json",
# "config_tests_6.json",
# "config_tests_7.json",
# "config_tests_8.json",
# "config_tests_9.json"]
# steps:
# - name: Get branch and PR required for detection testing main.py
# id: vars
# run: |
# echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
# - name: Checkout Repo
# uses: actions/checkout@v2
# #with:
# # ref: develop
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: testing-results-config
# path: bin/docker_detection_tester/prior_config
# - uses: actions/setup-python@v2
# with:
# python-version: '3.9' #Available versions here - https://github.com/actions/python-versions/releases easy to change/make a matrix/use pypy
# architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
# cache: 'pip'
# - name: Install Python Dependencies
# run: |
# python -m venv .venv
# source .venv/bin/activate
# python -m pip install wheel
# python -m pip install -r requirements.txt
# - name: Run the CI
# run: |
# source .venv/bin/activate
# cd bin/docker_detection_tester
# python detection_testing_execution.py run -c prior_config/${{ matrix.manifest_filename}}
# - name: Upload Test Results Files
# uses: actions/upload-artifact@v2
# with:
# name: ${{ matrix.manifest_filename}}.results
# path: |
# bin/docker_detection_tester/test_results/success.csv
# bin/docker_detection_tester/test_results/error.csv
# bin/docker_detection_tester/test_results/failure.csv
# bin/docker_detection_tester/test_results/combined.csv
# bin/docker_detection_tester/test_results/success.json
# bin/docker_detection_tester/test_results/error.json
# bin/docker_detection_tester/test_results/failure.json
# bin/docker_detection_tester/test_results/combined.json
# bin/docker_detection_tester/test_results/summary.json
# docker-detection-testing-execution-merge-results:
# runs-on: ubuntu-latest
# if: "!contains(github.ref, 'refs/tags/')" #don't run on tags - future steps won't run either since they depend on this job
# needs: [docker-detection-testing-setup, docker-detection-testing-execution]
# steps:
# - name: Get branch and PR required for detection testing main.py
# id: vars
# run: |
# echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
# - name: Checkout Repo
# uses: actions/checkout@v2
# #with:
# # ref: develop
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_0.json.results
# path: bin/docker_detection_tester/results_0
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_1.json.results
# path: bin/docker_detection_tester/results_1
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_2.json.results
# path: bin/docker_detection_tester/results_2
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_3.json.results
# path: bin/docker_detection_tester/results_3
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_4.json.results
# path: bin/docker_detection_tester/results_4
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_5.json.results
# path: bin/docker_detection_tester/results_5
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_6.json.results
# path: bin/docker_detection_tester/results_6
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_7.json.results
# path: bin/docker_detection_tester/results_7
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_8.json.results
# path: bin/docker_detection_tester/results_8
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: config_tests_9.json.results
# path: bin/docker_detection_tester/results_9
# - uses: actions/setup-python@v2
# with:
# python-version: '3.9' #Available versions here - https://github.com/actions/python-versions/releases easy to change/make a matrix/use pypy
# architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
# cache: 'pip'
# - name: Install Python Dependencies
# run: |
# python -m venv .venv
# source .venv/bin/activate
# python -m pip install wheel
# python -m pip install -r requirements.txt
# - name: Merge Detections into single File
# run: |
# source .venv/bin/activate
# cd bin/docker_detection_tester
# python summarize_json.py --files results_*/summary.json --output_filename summary_test_results.json
# - name: Upload Summary Test Results JSON
# uses: actions/upload-artifact@v2
# if: always()
# with:
# name: SummaryTestResults
# path: |
# bin/docker_detection_tester/summary_test_results.json
# - name: Upload Failures Manifest on Failure
# uses: actions/upload-artifact@v2
# if: failure()
# with:
# name: DetectionFailureManifest
# path: |
# bin/docker_detection_tester/detection_failure_manifest.json
# #Always clean these up, they make the output messy
# - name: Clean up intermediate Files
# uses: geekyeggo/delete-artifact@v1
# if: always()
# with:
# name: |
# config_tests_0.json.results
# config_tests_1.json.results
# config_tests_2.json.results
# config_tests_3.json.results
# config_tests_4.json.results
# config_tests_5.json.results
# config_tests_6.json.results
# config_tests_7.json.results
# config_tests_8.json.results
# config_tests_9.json.results
# - name: Log in to S3 for Artifact Uploads
# if: ${{ github.event_name == 'schedule' }}
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: us-west-2
# - name: Upload S3 Badge and Summary Artifacts for Nightly Scheduled Run
# if: ${{ github.event_name == 'schedule' }}
# run: |
# cd bin/docker_detection_tester
# python generate_detection_coverage_badge.py --input_summary_file summary_test_results.json --output_badge_file detection_coverage.svg --badge_string "Pass Rate"
# #Upload artifact (summary test results)
# aws s3 cp summary_test_results.json s3://security-content/reporting/summary_test_results.json
# #Since these reside in a public bucket, no need to explicitly mark as public
# # make the file public since it is not by default
# #aws s3api put-object-acl --bucket security-content --key reporting/summary_test_results.json --acl public-read
# #Upload artifact (test results coverage badge)
# aws s3 cp detection_coverage.svg s3://security-content/reporting/detection_coverage.svg
# #Since these reside in a public bucket, no need to explicitly mark as public
# # make the file public since it is not by default
# #aws s3api put-object-acl --bucket security-content --key reporting/detection_coverage.svg --acl public-read