Skip to content

Commit a6c41ec

Browse files
committed
Reusable Workflow
1 parent 707fb2a commit a6c41ec

File tree

2 files changed

+97
-69
lines changed

2 files changed

+97
-69
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: 'PR Validation - Auto Triggered'
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, labeled]
6+
branches:
7+
- main
8+
- release/**
9+
10+
workflow_dispatch:
11+
12+
jobs:
13+
validate-selfhosted:
14+
if: ${{ contains(github.event.pull_request.labels.*.name, 'long-run') }}
15+
uses: ./.github/workflows/validate.yaml
16+
with:
17+
runner-type: 'github-hosted'
18+
timeout: 640
19+
20+
validate-githubhosted:
21+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'long-run') }}
22+
uses: ./.github/workflows/validate.yaml
23+
with:
24+
runner-type: 'github-hosted'
25+
timeout: 480
26+
27+
static-check:
28+
name: 'See if Static Analysis should run'
29+
runs-on: ubuntu-latest
30+
31+
outputs:
32+
all-changed-files: ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0
38+
39+
- name: Get all changed files for this PR
40+
id: changed-files
41+
uses: tj-actions/changed-files@v42
42+
with:
43+
files_ignore_from_source_file: changed-files-ignore-list.txt
44+
separator: ","
45+
46+
- name: List changed files, skipping this job if there are no files to analyze
47+
run: |
48+
if [ "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" == "" ]; then
49+
echo 'No files eligible for scanning were changed. Skipping Static Analysis.'
50+
exit 0
51+
else
52+
echo ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
53+
fi
54+
55+
static:
56+
name: 'Run Static Analysis'
57+
runs-on: ubuntu-latest
58+
needs: static-check
59+
if: needs.static-check.outputs.all-changed-files != ''
60+
61+
steps:
62+
- uses: actions/checkout@v4
63+
with:
64+
fetch-depth: 0
65+
66+
- name: Install Salesforce CLI & Salesforce Code Analyzer
67+
run: |
68+
echo "Installing Salesforce CLI & Salesforce Code Analyzer"
69+
70+
- name: Run Salesforce Code Analyzer
71+
id: run-code-analyzer
72+
# uses: forcedotcom/run-code-analyzer@v1
73+
run: |
74+
echo "Running Salesforce Code Analyzer"
75+
76+
- name: Check the outputs to determine whether to fail
77+
if: |
78+
steps.run-code-analyzer.outputs.exit-code > 0 ||
79+
steps.run-code-analyzer.outputs.num-sev1-violations > 0
80+
run: exit 1

.github/workflows/validate.yaml

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
name: 'PR Validation - Auto Triggered'
99

1010
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
11+
workflow_call:
12+
inputs:
13+
runner-type:
14+
description: 'Runner type (self-hosted or GitHub-hosted)'
15+
required: true
16+
type: string
17+
timeout:
18+
description: 'Job timeout in minutes'
19+
required: false
20+
default: 480
21+
type: number
22+
23+
# permissions:
24+
# contents: read # Allows the workflow to read repository contents, required for checkout and other read operations
25+
# pull-requests: write # This is required to delete a label from the PR
2226

2327

2428
# Ensures that multiple validation job runs do not execute concurrently on the same PR.
@@ -31,8 +35,8 @@ jobs:
3135
validate:
3236
name: 'Validate Changed Packages'
3337
if: ${{ ! contains(github.event.pull_request.labels.*.name, 'long-run') }}
34-
timeout-minutes: 640
35-
runs-on: ubuntu-latest
38+
timeout-minutes: ${{ inputs.timeout }}
39+
runs-on: ${{ inputs.runner-type == 'github-hosted' && 'ubuntu-latest' || fromJSON('["group=${{ vars.RUNNER_GROUP_LATEST }}", "labels=self-hosted"]') }}
3640
# container:
3741
# image: ${{ vars.SFP_IMAGE }}
3842
# credentials:
@@ -85,62 +89,6 @@ jobs:
8589
echo "Deleting stale CI org"
8690
8791

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-
14492
# validate-package-coverage:
14593
# name: 'Validate Package Metadata Coverage'
14694
# runs-on: ubuntu-latest

0 commit comments

Comments
 (0)