# You might add new branch names in pipeline "branches"
image: node:20
definitions:
  services:
    docker:
      memory: 3072

pipelines:
  # Check jobs on pull requests
  pull-requests:
    "**":
      - parallel:
          # Run MegaLinter
          - step:
              name: Run MegaLinter
              image: oxsecurity/megalinter-salesforce:latest
              script:
                - export DEFAULT_WORKSPACE=$BITBUCKET_CLONE_DIR && bash /entrypoint.sh
              artifacts:
                - megalinter-reports/**
          # Simulate deployment
          - step:
              name: Simulate SFDX deployment
              clone:
                depth: full
              script:
                - npm install --no-cache @salesforce/cli --global
                - sf plugins install @salesforce/plugin-packaging
                - echo 'y' | sf plugins install sfdx-hardis
                - echo 'y' | sf plugins install sfdx-git-delta
                - sf version --verbose --json
                - export BRANCH_NAME=$(echo "$BITBUCKET_PR_DESTINATION_BRANCH" | sed 's/refs\/heads\///')
                - export CI_COMMIT_REF_NAME=$BRANCH_NAME
                - export ORG_ALIAS=$BRANCH_NAME
                - export CONFIG_BRANCH=$BRANCH_NAME
                - export FORCE_COLOR=1
                - export SFDX_DISABLE_FLOW_DIFF=false # Set to true to disable Flow doc during CI/CD setup
                - sf hardis:auth:login
                - sf hardis:project:deploy:smart --check

  branches:
    # Add all your major branches here
    "{integration,uat,preprod,production,main}":
      - step:
          name: Deploy to major org
          clone:
            depth: full
          script:
            - npm install --no-cache @salesforce/cli --global
            - sf plugins install @salesforce/plugin-packaging
            - echo 'y' | sf plugins install sfdx-hardis
            - echo 'y' | sf plugins install sfdx-git-delta
            - sf version --verbose --json
            - export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | sed 's/refs\/heads\///')
            - export CI_COMMIT_REF_NAME=$BRANCH_NAME
            - export CONFIG_BRANCH=$BRANCH_NAME
            - export ORG_ALIAS=$BRANCH_NAME
            - export FORCE_COLOR=1
            - sf hardis:auth:login
            - sf hardis:project:deploy:smart
