Skip to content

PR Validation ​

Reusable workflow that validates a pull request without changing the target org: it runs static code analysis and a check-only (dry-run) delta deployment including Apex tests. Call it from your own repository via uses:.

Reusable workflow - call it from your own repository with uses:. View source

Inputs ​

InputDescriptionTypeRequiredDefault
source-dirSource directory to analyze and validate.stringnoforce-app
target-org-aliasAlias used for the authenticated validation org.stringnoci
test-levelApex test level for the validation deployment. Ignored when apex-tests is set.stringnoRunLocalTests
apex-testsComma-separated or multi-line list of Apex test classes to run during the validation deployment. A selection always runs with RunSpecifiedTests. Leave empty to run the test-level.stringno-
deltaValidate only the components changed in the pull request.booleannotrue
run-code-reviewRun the code review (Salesforce Code Analyzer).booleannotrue
severity-thresholdFail if a code analyzer violation with this severity or higher is found.stringno3
environmentOptional GitHub Environment to validate in - its environment-scoped secrets select the org to validate against, e.g. one environment per target branch. Use an environment without required reviewers or branch restrictions, or every pull request waits for an approval or is rejected. Leave empty to use the repository secrets.stringno-

Secrets ​

SecretDescriptionRequired
SFDX_CONSUMER_KEYConsumer key (client ID) of the connected app used for the JWT flow.yes
SFDX_JWT_SECRET_KEYContents of the private server key (server.key) used for the JWT flow.yes
SFDX_USERNAMEUsername of the integration user to authenticate as.yes

Example usage ​

Copy this caller into your project's .github/workflows/ directory (source):

yaml
# Example: call the reusable PR validation workflow.
# Copy this file into your project's .github/workflows/ directory.

name: PR Validation

# Keep this on `pull_request`. Never switch it to `pull_request_target`: that
# event runs with the base repository's secrets, so a pull request from a fork
# could execute its own code against your Salesforce org.
on:
  pull_request:
    branches: [main]

# Least-privilege token: read the repository, plus write the code analysis
# results back as a SARIF report. A reusable workflow can never get more
# permissions than the caller grants here, so security-events: write has to be
# granted in this file as well.
permissions:
  contents: read
  security-events: write

jobs:
  validate:
    uses: svierk/salesforce-devops-starter-kit/.github/workflows/pr-validation.yml@v1.5.0
    with:
      source-dir: force-app
      test-level: RunLocalTests
      # Run only a selection of Apex test classes instead (implies RunSpecifiedTests):
      # apex-tests: AccountServiceTest,LeadServiceTest
      delta: true
      run-code-review: true
      severity-threshold: '3'
    secrets:
      SFDX_CONSUMER_KEY: ${{ secrets.SFDX_CONSUMER_KEY }}
      SFDX_JWT_SECRET_KEY: ${{ secrets.SFDX_JWT_SECRET_KEY }}
      SFDX_USERNAME: ${{ secrets.SFDX_USERNAME }}

Released under the MIT License. · llms.txt for AI agents