-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathconfig.yml
348 lines (321 loc) · 11.5 KB
/
config.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
348
### =============================================================
### This configuration file is used by CircleCI build server
### https://circleci.com/docs/config-sample
### =============================================================
version: 2.1
orbs:
python: circleci/python@<< pipeline.parameters.python-orb-version >>
node: circleci/node@<< pipeline.parameters.node-orb-version >>
orb-tools: circleci/[email protected]
parameters:
python-orb-version:
type: string
default: "2.0.3"
node-orb-version:
type: string
default: "5.0.1"
cache-version:
type: string
default: v3 # Change this parameter to clear cache.
global-docker-image:
type: string
default: cimg/python:3.10.2-node
references:
version_tag_regex: &version_tag_regex
/^v\d+\.\d+\.\d+$/ # version regex vx.x.x (i.e. v1.2.3)
filter_tag_only: &filter_tag_only
tags:
only: *version_tag_regex
tag_filter: &tag_filter
filters:
tags:
only: *version_tag_regex
reqs_content_checkout: &reqs_content_checkout
requires:
- checkout-content
install_node_ci: &install_node_ci
- node/install-packages:
cache-version: << pipeline.parameters.cache-version >>
install_demisto_sdk: &install_demisto_sdk
- python/install-packages:
pkg-manager: "poetry"
args: "--no-dev"
cache-version: << pipeline.parameters.cache-version >>
pre-install-steps:
- run:
name: export demisto-sdk to path
command: echo 'export PYTHONPATH="${PYTHONPATH}:${HOME}/project"' >> $BASH_ENV
- <<: *install_node_ci
install_build_dependencies: &install_build_dependencies
- python/install-packages:
pkg-manager: "poetry"
args: "--extras build"
requires_all: &requires_all
requires:
- precommit-checks
- validate-files
- create-content-artifacts
- test-lint
- run-integration-tests
- run-unit-tests
- build
jobs:
run-unit-tests:
parameters:
pythonversion:
type: string
docker:
- image: cimg/python:<< parameters.pythonversion >>-node
parallelism: 8
steps:
- checkout
- python/install-packages:
pkg-manager: "poetry"
cache-version: << pipeline.parameters.cache-version >>
- <<: *install_node_ci
- run:
name: pytest
no_output_timeout: 15m
command: |
shopt -u globstar
# The first sed expression is to remove test files from under the demisto_sdk/commands/init/templates
# directory from the globbed list of files. Need to manually remove them since the pytest 'ignore'
# argument in pytest.ini is itself ignored when explicitly passing tests to pytest. The second is to
# remove the integration tests (integration tests as opposed to unit tests) from the list because those
# tests shouldn't be parallelized.
TEST_FILES=$(circleci tests glob "**/*_test.py")
TEST_FILES=$(echo "$TEST_FILES" | sed -E 's/\S*demisto_sdk\/commands\/init\/templates\S*\.py//g')
TEST_FILES=$(echo "$TEST_FILES" | sed -E 's/\S*demisto_sdk\/tests\/integration_tests\S*\.py//g')
TEST_FILES=$(echo "$TEST_FILES" | circleci tests split --split-by=timings)
mkdir test-results
poetry run pytest -v --cov=demisto_sdk --cov-report=html --junitxml=test-results/junit.xml $TEST_FILES
- store_test_results:
path: test-results
- store_artifacts:
path: coverage_html_report
- run:
name: Coveralls upload
command: |
if [ -n "$COVERALLS_REPO_TOKEN" ]; then
pip install coveralls
coveralls
else
echo "Skipping coveralls"
fi
run-integration-tests:
parameters:
pythonversion:
type: string
docker:
- image: cimg/python:<< parameters.pythonversion >>-node
steps:
- checkout
- python/install-packages:
pkg-manager: "poetry"
cache-version: << pipeline.parameters.cache-version >>
- <<: *install_node_ci
- run:
name: pytest
no_output_timeout: 15m
command: |
shopt -u globstar
TEST_FILES=$(circleci tests glob "demisto_sdk/tests/integration_tests/**/*_test.py")
mkdir integration-test-results
poetry run pytest -v --junitxml=integration-test-results/junit.xml $TEST_FILES
- store_test_results:
path: integration-test-results
precommit-checks:
docker:
- image: << pipeline.parameters.global-docker-image >>
steps:
- checkout
- attach_workspace:
at: ~/project
- <<: *install_build_dependencies
- run:
name: create cache key for pre-commit
command: |
cp .pre-commit-config.yaml pre-commit-cache-key.txt
poetry run python --version --version >> pre-commit-cache-key.txt
cat poetry.lock >> pre-commit-cache-key.txt
- restore_cache:
keys:
- v1-pc-cache-{{ checksum "pre-commit-cache-key.txt" }}
- run:
name: Pre-commit
command: |
poetry run pre-commit --version
poetry run pre-commit run -a
- save_cache:
key: v1-pc-cache-{{ checksum "pre-commit-cache-key.txt" }}
paths:
- ~/.cache/pre-commit
checkout-content:
docker:
- image: << pipeline.parameters.global-docker-image >>
steps:
- checkout
- run:
name: Checkout the Content Repo
command: |
git clone --depth 1 https://github.com/demisto/content.git
cd content
git config diff.renameLimit 5000
git --no-pager log -1
- persist_to_workspace:
root: ~/project
paths:
- content
validate-files:
docker:
- image: << pipeline.parameters.global-docker-image >>
steps:
- checkout
- attach_workspace:
at: ~/project
- <<: *install_build_dependencies
- <<: *install_node_ci
- run:
name: Set Up & Create Id Set
when: always
environment:
CI_COMMIT_BRANCH: "master"
command: |
cd content
poetry run demisto-sdk -v
poetry run demisto-sdk create-id-set -o ./Tests/id_set.json --fail-duplicates
- run:
name: Merge Id Set
when: always
environment:
CI_COMMIT_BRANCH: "master"
command: |
cd content
poetry run demisto-sdk -v
export CIRCLE_ARTIFACTS="/home/circleci/project/artifacts"
poetry run gsutil cp gs://marketplace-dist/content/private_id_set.json $CIRCLE_ARTIFACTS/unified_id_set.json
poetry run demisto-sdk merge-id-sets -i1 ./Tests/id_set.json -i2 $CIRCLE_ARTIFACTS/unified_id_set.json -o $CIRCLE_ARTIFACTS/unified_id_set.json --fail-duplicates
- run:
name: Test validate files and yaml
when: always
environment:
CI_COMMIT_BRANCH: "master"
command: |
cd content
poetry run demisto-sdk -v
export ARTIFACTS_FOLDER="/home/circleci/project/artifacts"
poetry run ./Tests/scripts/validate.sh
test-lint:
docker:
- image: devdemisto/content-build:3.0.0.27979
steps:
- checkout
- setup_remote_docker
- attach_workspace:
at: ~/project
- run:
name: Test lint on python and ps files
when: always
command: |
pip3 uninstall virtualenv -y && pip3 install virtualenv==16.7.7
cd ~/project
export SDK_LINT_FILES_CHANGED=$(git diff master... --name-only -- demisto_sdk/commands/lint)
if [[ -z "${SDK_LINT_FILES_CHANGED}" ]]; then
echo "files under demisto_sdk/commands/lint did not change - Skipping lint runs."
exit 0
fi
cd content
echo "installing venv"
NO_HOOKS=1 SETUP_PY2=yes .hooks/bootstrap >> /tmp/lint_env_installation.log
echo "finished script installation"
source ./venv/bin/activate
pip3 install -r .circleci/build-requirements.txt >> /tmp/lint_env_installation.log
# installing local sdk inside venv
pip3 install ~/project >> /tmp/lint_env_installation.log
echo ""
echo "lint files changed running lint"
# python file (CommonServerPython lint is running over python 3 and 2)
poetry run demisto-sdk lint -i ./Packs/Base/Scripts/CommonServerPython
# ps file
poetry run demisto-sdk lint -i ./Packs/Base/Scripts/CommonServerPowerShell
- store_artifacts:
path: /tmp/lint_env_installation.log
create-content-artifacts:
docker:
- image: << pipeline.parameters.global-docker-image >>
steps:
- checkout
- attach_workspace:
at: ~/project
- <<: *install_demisto_sdk
- run:
name: Test Create Content Artifacts
when: always
command: |
cd content
poetry run demisto-sdk -v
mkdir ./tmp
poetry run demisto-sdk create-content-artifacts -a ./tmp
- store_artifacts:
path: content/tmp
build:
docker:
- image: << pipeline.parameters.global-docker-image >>
steps:
- checkout
- run:
name: Build Distrubution
command: poetry build
- persist_to_workspace:
root: ~/project
paths:
- dist
- store_artifacts:
path: dist
deploy:
docker:
- image: << pipeline.parameters.global-docker-image >>
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
name: Deploy Release to PyPi
command: poetry publish -u __token__ -p ${PYPI_TOKEN}
workflows:
version: 2.1
build_and_release:
jobs:
- checkout-content:
<<: *tag_filter
- precommit-checks:
<<: *tag_filter
- run-unit-tests:
<<: *tag_filter
matrix:
parameters:
pythonversion: [3.8.12, 3.9.10, 3.10.2]
name: run-unit-tests-<< matrix.pythonversion >>
- run-integration-tests:
<<: *tag_filter
matrix:
parameters:
pythonversion: [3.8.12, 3.9.10, 3.10.2]
name: run-integration-tests-<< matrix.pythonversion >>
- validate-files:
<<: *tag_filter
<<: *reqs_content_checkout
- test-lint:
<<: *reqs_content_checkout
- create-content-artifacts:
<<: *tag_filter
<<: *reqs_content_checkout
- build:
<<: *tag_filter
- deploy:
filters:
tags:
only: *version_tag_regex
branches:
ignore: /.*/
<<: *requires_all