# Generated by `sfdt ci init --provider azure --type scratch`.
# A standalone Azure Pipelines definition for scratch-org CI on PRs: creates a
# fresh scratch org from the Dev Hub, deploys the source, runs local Apex tests
# (plus LWC tests when detected), and always deletes the org — pass or fail.
#
# {{org}} here is the DEV HUB alias: the auth secret must belong to a Dev Hub
# user with the "Salesforce DX Scratch Org" permissions.
#
# Required pipeline variables (Pipelines > Library / pipeline variables, secret):
{{authSecretsDoc}}
trigger: none
pr:
  branches:
    include:
      - '*'
pool:
  vmImage: ubuntu-latest
steps:
  - checkout: self
  - task: NodeTool@0
    inputs:
      versionSpec: '{{nodeVersion}}'
  - script: npm install --global @salesforce/cli
    displayName: Install Salesforce CLI
  {{authSteps}}
  - script: sf org create scratch --definition-file {{scratchDef}} --alias sfdt-ci --duration-days 1 --set-default --wait 20
    displayName: Create scratch org
  - script: sf project deploy start --target-org sfdt-ci --wait 30
    displayName: Deploy source
  - script: sf apex run test --target-org sfdt-ci --test-level RunLocalTests --code-coverage --result-format human --wait 30
    displayName: Run Apex tests
  {{lwcTestSteps}}
  - script: sf org delete scratch --target-org sfdt-ci --no-prompt
    displayName: Delete scratch org
    condition: always()
