# Generated by `sfdt ci init --provider gitlab --type scratch`.
# Merge this job into your .gitlab-ci.yml. Scratch-org CI on merge requests:
# 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 via
# after_script — 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 CI/CD variables (Settings > CI/CD > Variables, masked):
{{authSecretsDoc}}
sfdt-scratch:
  image: {{image}}
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
  script:
    {{cliSetup}}
    {{authSteps}}
    - sf org create scratch --definition-file {{scratchDef}} --alias sfdt-ci --duration-days 1 --set-default --wait 20
    - sf project deploy start --target-org sfdt-ci --wait 30
    - sf apex run test --target-org sfdt-ci --test-level RunLocalTests --code-coverage --result-format human --wait 30
    {{lwcTestSteps}}
  after_script:
    - sf org delete scratch --target-org sfdt-ci --no-prompt || true
