# Generated by `sfdt ci init --provider github --type scratch`.
# Scratch-org CI on pull 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 — 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 repository secrets (Settings > Secrets and variables > Actions):
{{authSecretsDoc}}
name: SFDT Scratch Org CI
on:
  pull_request:
    types: [opened, synchronize, reopened]
  workflow_dispatch: {}
permissions:
  contents: read
jobs:
  scratch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '{{nodeVersion}}'
      - name: Install Salesforce CLI
        run: npm install --global @salesforce/cli
      {{authSteps}}
      - name: Create scratch org
        run: sf org create scratch --definition-file {{scratchDef}} --alias sfdt-ci --duration-days 1 --set-default --wait 20
      - name: Deploy source
        run: sf project deploy start --target-org sfdt-ci --wait 30
      - name: Run Apex tests
        run: sf apex run test --target-org sfdt-ci --test-level RunLocalTests --code-coverage --result-format human --wait 30
      {{lwcTestSteps}}
      - name: Delete scratch org
        if: always()
        run: sf org delete scratch --target-org sfdt-ci --no-prompt
