Fix NoSuchPathError in get_modified_packs #46
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |