Skip to content

Update the config file; Update the get_modified_packs file; Convert t… #52

Update the config file; Update the get_modified_packs file; Convert t…

Update the config file; Update the get_modified_packs file; Convert t… #52

Workflow file for this run

name: XSOAR CI/CD
on:
push:
jobs:
build:
runs-on: ubuntu-latest
env:
BRANCH_NAME: ${{ github.ref_name }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
DEMISTO_README_VALIDATION: false
DEMISTO_SDK_GITHUB_TOKEN: ${{ secrets.DEMISTO_SDK_GITHUB_TOKEN }}
steps:
- name: XSOAR CI/CD master checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Content checkout
uses: actions/checkout@v2
with:
repository: demisto/content
path: content
- name: Install poetry
uses: Gr1N/setup-poetry@v8
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9.12
cache: poetry
- name: Install python dependencies
run: |
poetry install
- name: Prepare Environment
run: |
echo "PATH=/home/runner/.local/bin:$PATH" >> $GITHUB_ENV
echo "PYTHONPATH=${GITHUB_WORKSPACE}/content:${GITHUB_WORKSPACE}:${PYTHONPATH}" >> $GITHUB_ENV
echo "NEW_PACKS_FOLDER=${GITHUB_WORKSPACE}/content/new_packs_zips" >> $GITHUB_ENV
PACKS_CHANGED=$(python $GITHUB_WORKSPACE/build_related_scripts/get_modified_packs.py --repo_path $GITHUB_WORKSPACE/ --prev-ver ${DEFAULT_BRANCH})
echo "PACKS_CHANGED=${PACKS_CHANGED}" >> $GITHUB_ENV
echo "The current branch is ${BRANCH_NAME}"
echo "The default branch is ${DEFAULT_BRANCH}"
- name: Prepare Venv
run: |
cd $GITHUB_WORKSPACE/content/
# Install node packages
npm install .
git config diff.renameLimit 6000
echo "========== Build Parameters =========="
python --version
demisto-sdk --version
- name: Validate Files and Yaml
if: always()
run: |
source $GITHUB_WORKSPACE/content/.venv/bin/activate
cd $GITHUB_WORKSPACE
# Run validate on all changed files
# You can choose what validations to use in the .demisto-sdk-conf file
demisto-sdk validate --use-git --post-commit --graph --prev-ver ${DEFAULT_BRANCH}
- name: Run Unit Testing and Lint
if: always()
run: |
source $GITHUB_WORKSPACE/content/.venv/bin/activate
cd $GITHUB_WORKSPACE
# 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 --prev-ver ${DEFAULT_BRANCH}
- name: Create Packs Artifacts
run: |
if [ $PACKS_CHANGED ]; then
source $GITHUB_WORKSPACE/content/.venv/bin/activate
cd $GITHUB_WORKSPACE/
for pack in Packs/*
do
demisto-sdk prepare-content --input $pack --output $NEW_PACKS_FOLDER
done
else
echo "No packs has changed, skipping step."
fi
- name: Upload Packs to Artifacts Server
# In case 2 below (UPLOAD DIRECTLY TO YOUR XSOAR MACHINE) needed to add these variables
# For more information - https://docs-cortex.paloaltonetworks.com/r/1/Demisto-SDK-Guide/Environment-variables-setup
env:
DEMISTO_BASE_URL: ${{ secrets.DEMISTO_BASE_URL }}
DEMISTO_API_KEY: ${{ secrets.DEMISTO_API_KEY }}
# For Cortex XSOAR 8 and Cortex XSIAM add the following variable:
XSIAM_AUTH_ID: ${{ vars.XSIAM_AUTH_ID }}
run : |
if [ $PACKS_CHANGED ]; then
if [ $BRANCH_NAME == ${DEFAULT_BRANCH} ]; then
echo "Uploading artifacts ${PACKS_CHANGED}."
# 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/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) =========
cd $NEW_PACKS_FOLDER
for pack in *
do
demisto-sdk upload --input $pack
done
else
echo "The currrent branch is not the default branch, skipping upload to server."
fi
else
echo "No packs has changed, skipping step."
fi