1+ # Based on Flxbl (formerly DX@Scale) CI/CD Template for GitHub
2+ #
3+ # To know more about flxbl, visit https://docs.flxbl.io
4+ # To know more on sfpowerscripts, visit- https://docs.flxbl.io/sfp
5+
6+ # This pipeline is used to validate an incoming change using a scratch org fetched from the CI pool
7+
8+ name : ' PR Validation - Auto Triggered'
9+
10+ on :
11+ pull_request :
12+ types : [opened, synchronize, reopened]
13+ branches :
14+ - main
15+ - release/**
16+
17+ workflow_dispatch :
18+
19+ permissions :
20+ contents : read # Allows the workflow to read repository contents, required for checkout and other read operations
21+ pull-requests : write # This is required to delete a label from the PR
22+
23+
24+ # Ensures that multiple validation job runs do not execute concurrently on the same PR.
25+ # If a new run is triggered, any in-progress run for the same group is canceled.
26+ concurrency :
27+ group : ${{ github.workflow }}-${{ github.ref }}
28+ cancel-in-progress : true
29+
30+ jobs :
31+ validate-githubhosted :
32+ name : ' Validate Changed Packages'
33+ if : ${{ ! contains(github.event.pull_request.labels.*.name, 'long-run') }}
34+ timeout-minutes : 640
35+ runs-on : ubuntu-latest
36+ # container:
37+ # image: ${{ vars.SFP_IMAGE }}
38+ # credentials:
39+ # username: ${{ github.repository_owner }}
40+ # password: ${{ secrets.ACCESS_TOKEN }}
41+
42+ steps :
43+ - uses : actions/checkout@v4
44+ with :
45+ fetch-depth : 0
46+
47+ # New step: Scan sfdx-project.json for "replaceWithFile" entries and check if files exist
48+ - name : ' Check replaceWithFile existence in sfdx-project.json'
49+ id : check-replaceWithFile
50+ run : |
51+ # Extract "replaceWithFile" values from sfdx-project.json and check if the files exist
52+ shell : bash
53+
54+ - name : ' Get all changed files for this PR'
55+ id : changed-deployable-files
56+ uses : tj-actions/changed-files@v42
57+ with :
58+ files_ignore_from_source_file : validation-ignore-list.txt
59+ separator : " ,"
60+
61+ - name : ' Authenticate Dev Hub'
62+ run : |
63+ echo "Authenticating with Dev Hub"
64+
65+ # Validate source and trigger test, skipping if there are no deployable changes
66+ - name : ' If deployable changes were made, push source to a scratch org'
67+ run : |
68+ if [ "${{ steps.changed-deployable-files.outputs.all_changed_and_modified_files }}" == "" ]; then
69+ echo 'No deployable changes were made. Skipping Scratch Org Validation.'
70+ exit 0
71+ fi
72+ echo "Deploying source to a scratch org"
73+
74+ # Upload test results to the GitHub workspace
75+ - name : ' Upload test results'
76+ # uses: actions/upload-artifact@v4
77+ if : ${{ !cancelled() }}
78+ run : |
79+ echo "Dummy Uploading test results"
80+
81+ # If the job is cancelled, release the CI org
82+ - name : ' Delete stale CI org'
83+ if : ${{ cancelled() }}
84+ run : |
85+ echo "Deleting stale CI org"
86+
87+
88+
89+ static-check :
90+ name : ' See if Static Analysis should run'
91+ runs-on : ubuntu-latest
92+
93+ outputs :
94+ all-changed-files : ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
95+
96+ steps :
97+ - uses : actions/checkout@v4
98+ with :
99+ fetch-depth : 0
100+
101+ - name : Get all changed files for this PR
102+ id : changed-files
103+ uses : tj-actions/changed-files@v42
104+ with :
105+ files_ignore_from_source_file : changed-files-ignore-list.txt
106+ separator : " ,"
107+
108+ - name : List changed files, skipping this job if there are no files to analyze
109+ run : |
110+ if [ "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" == "" ]; then
111+ echo 'No files eligible for scanning were changed. Skipping Static Analysis.'
112+ exit 0
113+ else
114+ echo ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
115+ fi
116+
117+ static :
118+ name : ' Run Static Analysis'
119+ runs-on : ubuntu-latest
120+ needs : static-check
121+ if : needs.static-check.outputs.all-changed-files != ''
122+
123+ steps :
124+ - uses : actions/checkout@v4
125+ with :
126+ fetch-depth : 0
127+
128+ - name : Install Salesforce CLI & Salesforce Code Analyzer
129+ run : |
130+ echo "Installing Salesforce CLI & Salesforce Code Analyzer"
131+
132+ - name : Run Salesforce Code Analyzer
133+ id : run-code-analyzer
134+ # uses: forcedotcom/run-code-analyzer@v1
135+ run : |
136+ echo "Running Salesforce Code Analyzer"
137+
138+ - name : Check the outputs to determine whether to fail
139+ if : |
140+ steps.run-code-analyzer.outputs.exit-code > 0 ||
141+ steps.run-code-analyzer.outputs.num-sev1-violations > 0
142+ run : exit 1
143+
144+ # validate-package-coverage:
145+ # name: 'Validate Package Metadata Coverage'
146+ # runs-on: ubuntu-latest
147+ # container:
148+ # image: ${{ vars.SFP_IMAGE }}
149+ # credentials:
150+ # username: ${{ github.repository_owner }}
151+ # password: ${{ secrets.ACCESS_TOKEN }}
152+ # steps:
153+ # - uses: actions/checkout@v4
154+ # with:
155+ # fetch-depth: 0
156+
157+ # - name: 'Validate metadata coverage'
158+ # shell: bash
159+ # run: |
160+ # sfdx sfpowerkit:package:valid -n redhatcrm-core -b StandardValueSet
161+
0 commit comments