-
Notifications
You must be signed in to change notification settings - Fork 27
158 lines (138 loc) · 6.43 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
name: XSOAR CI/CD
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: XSOAR CI/CD master checkout
uses: actions/checkout@v2
with:
repository: your/repository
path: repository
fetch-depth: 0
- name: Content checkout
uses: actions/checkout@v2
with:
repository: demisto/content
path: content
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8.5
- name: Install pip and requirements
run: |
pip install --upgrade pip
pip install -r ${GITHUB_WORKSPACE}/repository/requirements.txt
- name: Prepare Environment
env:
REF: ${{ github.ref }}
run: |
echo "PATH=/home/runner/.local/bin:$PATH" >> $GITHUB_ENV
echo "PYTHONPATH=${GITHUB_WORKSPACE}/content:${GITHUB_WORKSPACE}:${PYTHONPATH}" >> $GITHUB_ENV
echo "ARTIFACTS_FOLDER=/home/runner/work/repository/repository/content/artifacts" >> $GITHUB_ENV
echo "NEW_PACKS_FOLDER=/home/runner/work/repository/repository/content/new_packs_zips" >> $GITHUB_ENV
echo "DEMISTO_README_VALIDATION=false" >> $GITHUB_ENV
BRANCH_NAME=${REF#refs/heads/}
PACKS_CHANGED=$(python $GITHUB_WORKSPACE/repository/build_related_scripts/get_modified_packs.py --repo_path $GITHUB_WORKSPACE/repository/)
echo "PACKS_CHANGED=${PACKS_CHANGED}" >> $GITHUB_ENV
echo "DEMISTO_SDK_GITHUB_TOKEN=<your-github-token>" >> $GITHUB_ENV
- name: Prepare Venv
run: |
cd $GITHUB_WORKSPACE/content/
if [ ! -e "venv" ]; then
echo "installing venv"
NO_HOOKS=1 SETUP_PY2=no .hooks/bootstrap
source ./venv/bin/activate
pip3 install -r ${GITHUB_WORKSPACE}/repository/requirements.txt
demisto-sdk --version
else
echo "venv exists (from cache). activating"
source ./venv/bin/activate
fi
# Install node packages
npm install .
git config diff.renameLimit 6000
echo "========== Build Parameters =========="
python3 --version
demisto-sdk --version
- name: Create ID Set
run: |
if [ $PACKS_CHANGED ]; then
cd $GITHUB_WORKSPACE/repository/
source $GITHUB_WORKSPACE/content/venv/bin/activate
# Download content's
gsutil cp gs://marketplace-dist/content/id_set.json ./Tests/content-id_set.json
# Create repository id-set
demisto-sdk create-id-set
# Merge id-sets and copy to artifacts folder
demisto-sdk merge-id-sets -i1 ./Tests/id_set.json -i2 ./Tests/content-id_set.json -o ./Tests/id_set.json
cp "./Tests/id_set.json" "$ARTIFACTS_FOLDER/id_set.json"
else
echo "No packs has changed, skipping step."
fi
- name: Validate Files and Yaml
if: always()
run: |
source $GITHUB_WORKSPACE/content/venv/bin/activate
cd $GITHUB_WORKSPACE/repository
# Run validate on all changed files
# You can choose what validations to use in the .demisto-sdk-conf file
demisto-sdk validate --quite-bc-validation --no-conf-json --allow-skipped
- name: Run Unit Testing and Lint
if: always()
run: |
source $GITHUB_WORKSPACE/content/venv/bin/activate
cd $GITHUB_WORKSPACE/repository
# Copy necessary files
cp $GITHUB_WORKSPACE/content/Tests/demistomock/demistomock.py ./
cp $GITHUB_WORKSPACE/content/Tests/demistomock/demistomock.ps1 ./
cp $GITHUB_WORKSPACE/content/Packs/Base/Scripts/CommonServerPython/CommonServerPython.py ./
cp $GITHUB_WORKSPACE/content/Packs/Base/Scripts/CommonServerPowerShell/CommonServerPowerShell.ps1 ./
mkdir -p ./dev_envs/pytest/
cp $GITHUB_WORKSPACE/content/Tests/scripts/dev_envs/pytest/conftest.py ./dev_envs/pytest/
# Run lint on all changed files
# You can choose what lint checks to use in the .demisto-sdk-conf file
demisto-sdk lint -g
- name: Create Packs Artifacts
run: |
if [ $PACKS_CHANGED ]; then
source $GITHUB_WORKSPACE/content/venv/bin/activate
cd $GITHUB_WORKSPACE/repository/
for pack in Packs/*
do
demisto-sdk zip-packs --input $pack --output $ARTIFACTS_FOLDER
done
else
echo "No packs has changed, skipping step."
fi
- name: Upload Packs to Artifacts Server
env:
REF: ${{ github.ref }}
run : |
if [ $PACKS_CHANGED ]; then
BRANCH_NAME=${REF#refs/heads/}
# Select the way you want to install the packs on the machine, and remove the second part
# For example: Choose the option 1 - UPLOAD TO ARTIFACTS SERVER OPTION, and remove the option 2 - UPLOAD DIRECTLY TO YOUR XSOAR MACHINE.
# For more information - https://xsoar.pan.dev/docs/reference/articles/xsoar-ci-cd#to-deploy-content
# 1. ========= UPLOAD TO ARTIFACTS SERVER OPTION =========
# Upload to the artifacts server of your choice.
# Create a file with the service account data
# use the bucket_upload script to upload your packs to google cloud storage
python $GITHUB_WORKSPACE/repository/build_related_scripts/bucket_upload.py --service_account $GITHUB_WORKSPACE/service_account.json --packs_directory $NEW_PACKS_FOLDER --branch_name $BRANCH_NAME
# Delete the service account file
rm $GITHUB_WORKSPACE/service_account.json
# 2. ========= UPLOAD DIRECTLY TO YOUR XSOAR MACHINE (WHEN MERGING TO MAIN REPO) =========
if [ $BRANCH_NAME != master ]; then
# Get the config_file
CONFIG_FILE=$(cat xsoar_config.json)
# Extract the Marketplace Packs section from the config_file
MARKETPLACE_PACKS_LIST=$(cat $CONFIG_FILE | jq -r '.marketplace_packs')
# Upload Custom Packs
demisto-sdk upload --input-config-file /xsoar_config.json
# Upload MarketPlace Packs
python3 build_related_scripts/MarketPlaceInstallerFromCICD.py --marketplace-packs-list $MARKETPLACE_PACKS_LIST
fi
else
echo "No packs has changed, skipping step."
fi