name: Content Managament CI/CD on: push: jobs: build: runs-on: ubuntu-latest steps: - name: Content Managament 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@v5 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/content-internal-dist/build_related_scripts/get_modified_packs.py --repo_path $GITHUB_WORKSPACE/content-internal-dist/) echo "PACKS_CHANGED=${PACKS_CHANGED}" >> $GITHUB_ENV echo "DEMISTO_SDK_GITHUB_TOKEN=" >> $GITHUB_ENV # Copy Base pack from content to your repository. Needed for linting. cp -r $GITHUB_WORKSPACE/content/Packs/Base $GITHUB_WORKSPACE/repository/Packs - 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 --no-fund --no-audit . 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 demisto-sdk validate --quiet-bc-validation --no-conf-json --allow-skipped --run-old-validate --skip-new-validate - 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 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/} # TODO: 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 storge 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 else echo "No packs has changed, skipping step." fi