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.stringnoRunLocalTests
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

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.0.0
    with:
      source-dir: force-app
      test-level: RunLocalTests
      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.