Skip to content

Commit 6a95b0e

Browse files
NEW @W-18394864@ Improved usability of violations (#77)
* @W-18394864@ Summarizer can create two tables now * @W-18394864@ Dependencies can identify changed files * @W-18394864@ Achieved compatibility with latest main * @W-18394864@ Refactored for more sensible code placement * @W-18394864@ Creating review with link to summary * @W-18394864@ Fixing typo * @W-18394864@ Table size limit now shared between tables * @W-18394864@ Adding E2E test * @W-18394864@ Fixing typo in CI job * @W-18394864@ Fixing another typo in CI job * @W-18394864@ Debugged issues with URL * @W-18394864@ Summary message sorts violations * @W-18394864@ Polishing code * @W-18394864@ Adjusted truncation message * @W-18394864@ Implemented feedback from code review * @W-18394864@ Addressed feedback * @W-18394864@ Updated README and adjusted permission checks. * @W-18394864@ Feedback from code review * @W-18394864@ Fixed linting issue * @W-18394864@ feedback from code review * @W-18394864@ removing wrongly added file * @W-18394864@ Final feedback from code review * @W-18394864@ Final-final feedback * @W-18394864@ Final-final-final review * @W-18394864@ Oversight * fix: edit readme and errors (#79) * @W-18394864@ Bundling changes * @W-18394864@ Fixing linting problem --------- Co-authored-by: Juliet Shackell <63259011+jshackell-sfdc@users.noreply.github.com>
1 parent 51fa863 commit 6a95b0e

23 files changed

Lines changed: 17177 additions & 195 deletions

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
test-action:
4646
name: GitHub Actions Test
4747
runs-on: ubuntu-latest
48+
permissions:
49+
pull-requests: write
4850

4951
steps:
5052
- name: Checkout
@@ -76,7 +78,10 @@ jobs:
7678
uses: ./
7779
with:
7880
run-arguments: --view detail --workspace "./src,./__tests__" --output-file results.json
81+
github-token: ${{github.token}}
7982

8083
- name: Print Output
8184
id: output
82-
run: echo "${{ steps.test-action.outputs.exit-code }}"
85+
run: |
86+
echo "${{ steps.test-action.outputs.exit-code }}"
87+
echo "${{ steps.test-action.outputs.review-id }}"

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ The `forcedotcom/run-code-analyzer@v2` GitHub Action is based on [Salesforce Cod
1515

1616
## v2 Inputs
1717
* <b>`run-arguments`</b> *(Default: `--view detail --output-file sfca_results.json`)*
18-
* Specifies the arguments passed to the `run` command.
19-
* For a full list of acceptable arguments for the `run` command, see the [code-analyzer Command Reference](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_code-analyzer_commands_unified.htm).
20-
* The stdout text from the `run` command is written to the [GitHub workflow run logs](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/monitoring-workflows/using-workflow-run-logs).
18+
* Specifies the flags passed to the `code-analyzer run` command.
19+
* For a full list of valid flags for the `code-analyzer run` command, see the [code-analyzer Command Reference](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_code-analyzer_commands_unified.htm).
20+
* The stdout text from the `code-analyzer run` command is written to the [GitHub workflow run logs](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/monitoring-workflows/using-workflow-run-logs).
2121
* Each output file specified by a `--output-file` (or `-f`) flag is included in the ZIP archive [GitHub workflow run artifact](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/downloading-workflow-artifacts) for you to download.
2222
* <b>`results-artifact-name`</b> *(Default: `salesforce-code-analyzer-results`)*
2323
* Specifies the name of the ZIP archive [GitHub workflow run artifact](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/downloading-workflow-artifacts) where the results output files are uploaded.
24+
* <b>`github-token`</b>
25+
* When this action is run against a pull request, you can provide a GitHub token, which is used to create a review of the pull request. The review specifies how many violations were found (both in the project as a whole and in changed files) and links to the action summary page.
26+
* This token must have write permissions for pull requests.
27+
* You can use the default GitHub token stored as the `GITHUB_TOKEN` secret, as long as you also use the job-level `permissions` property to give that token write access for pull requests.
2428

2529
## v2 Outputs
2630
* `exit-code`
@@ -37,11 +41,13 @@ The `forcedotcom/run-code-analyzer@v2` GitHub Action is based on [Salesforce Cod
3741
* The number of Low (4) severity violations found.
3842
* `num-sev5-violations`
3943
* The number of Info (5) severity violations found.
44+
* `review-id`
45+
* If the action created a pull request review, this is its ID.
4046

41-
This `run-code-analyzer@v2` action won't exit your GitHub workflow when it finds violations. We recommend that you add a subsequent step to your workflow that uses the available outputs to determine how your workflow should proceed.
47+
This `run-code-analyzer@v2` action doesn't exit your GitHub workflow when it finds violations. We recommend that you add a subsequent step to your workflow that uses the available outputs to determine how your workflow should proceed.
4248

4349
## Environment Prerequisites
44-
The [Salesforce Code Analyzer v5.x](https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/code-analyzer.html) and its bundled engines can each have their own set of requirements in order to run successfully. So we recommend that you set up your GitHub runner(s) with this software:
50+
The [Salesforce Code Analyzer v5.x](https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/code-analyzer.html) and its bundled engines can each have their own set of requirements in order to run successfully. We recommend that you set up your GitHub runner(s) with this software:
4551
* `node` version 20.9.0 or greater
4652
* Required by all engines.
4753
* `java` version 11 or greater
@@ -52,15 +58,20 @@ The [Salesforce Code Analyzer v5.x](https://developer.salesforce.com/docs/platfo
5258
## Example v2 Usage
5359

5460
name: Salesforce Code Analyzer Workflow
55-
on: push
61+
on:
62+
pull_request:
5663
jobs:
5764
salesforce-code-analyzer-workflow:
65+
permissions:
66+
pull-requests: write # Grants permission to create a pull request review. Only necessary if running against pull requests.
67+
contents: read # Grants permission to check out the repository. Only necessary for private repos.
68+
actions: read # Grants permission to read the in-progress actions. Only necessary for private repos.
5869
runs-on: ubuntu-latest
5970
steps:
6071
- name: Check out files
6172
uses: actions/checkout@v4
6273

63-
# PREREQUISITES - Only needed if runner doesn't already satisfy these requirements
74+
# PREREQUISITES - Only needed if the runner doesn't already satisfy these requirements.
6475
- name: Ensure node v20.9.0 or greater
6576
uses: actions/setup-node@v4
6677
with:
@@ -87,8 +98,9 @@ The [Salesforce Code Analyzer v5.x](https://developer.salesforce.com/docs/platfo
8798
with:
8899
run-arguments: --workspace . --view detail --output-file sfca_results.html --output-file sfca_results.json
89100
results-artifact-name: salesforce-code-analyzer-results
101+
github-token: ${{ github.token }}
90102

91-
- name: Check the outputs to determine whether to fail
103+
- name: Check the Outputs to Determine Whether to Fail
92104
if: |
93105
steps.run-code-analyzer.outputs.exit-code > 0 ||
94106
steps.run-code-analyzer.outputs.num-sev1-violations > 0 ||

__tests__/data/sampleRunResults.json

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"runDir": "/Users/runner/work/sample-sf-project/sample-sf-project/",
33
"violationCounts": {
4-
"total": 202,
4+
"total": 203,
55
"sev1": 0,
66
"sev2": 88,
77
"sev3": 49,
88
"sev4": 44,
9-
"sev5": 21
9+
"sev5": 22
1010
},
1111
"versions": {
1212
"code-analyzer": "0.20.2",
@@ -3680,6 +3680,31 @@
36803680
],
36813681
"message": "Avoid unescaped user controlled content in EL",
36823682
"resources": ["https://docs.pmd-code.org/pmd-doc-7.8.0/pmd_rules_visualforce_security.html#vfunescapeel"]
3683+
},
3684+
{
3685+
"rule": "DetectCopyPasteForApex",
3686+
"engine": "cpd",
3687+
"severity": 5,
3688+
"tags": ["Recommended", "Design", "Apex"],
3689+
"primaryLocationIndex": 0,
3690+
"locations": [
3691+
{
3692+
"file": "force-app/main/default/classes/NameController.cls",
3693+
"startLine": 1,
3694+
"startColumn": 1,
3695+
"endLine": 10,
3696+
"endColumn": 50
3697+
},
3698+
{
3699+
"file": "force-app/main/default/classes/SharingInnerClass.cls",
3700+
"startLine": 15,
3701+
"startColumn": 1,
3702+
"endLine": 25,
3703+
"endColumn": 50
3704+
}
3705+
],
3706+
"message": "Duplicate code detected for language 'apex'. Found 2 code locations containing the same block of code consisting of 123 tokens across 10 lines.",
3707+
"resources": ["https://docs.pmd-code.org/latest/pmd_userdocs_cpd.html#refactoring-duplicates"]
36833708
}
36843709
]
36853710
}

__tests__/data/sampleRunResults_expectedSummary.md renamed to __tests__/data/sampleRunResults_oneTableSummary.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
## Salesforce Code Analyzer Results
2-
### :warning: 202 Violation(s) Found
2+
### :warning: 203 Violation(s) Found
33
<blockquote>
44
:black_circle: 0 Critical severity violation(s)<br/>
55
:red_circle: 88 High severity violation(s)<br/>
66
:orange_circle: 49 Medium severity violation(s)<br/>
77
:yellow_circle: 44 Low severity violation(s)<br/>
8-
:white_circle: 21 Info severity violation(s)
8+
:white_circle: 22 Info severity violation(s)
99
</blockquote>
1010
<table><tr><th> </th><th>Location</th><th>Rule</th><th>Message</th></tr>
1111
<tr><td>:red_circle:</td><td><sup>force-app/main/default/aura/AccountRepeat/AccountRepeat.cmp-meta.xml:3:17</sup></td><td><sup>regex:AvoidOldSalesforceApiVersions</sup></td><td><sup>Found the use of a Salesforce API version that is 3 or more years old. Avoid using an API version that is &lt;= 56.0.</sup></td></tr>
@@ -189,6 +189,7 @@
189189
<tr><td>:yellow_circle:</td><td><sup>force-app/main/default/classes/testSELECT2.cls:2:12</sup></td><td><sup>pmd:<a href="https://docs.pmd-code.org/pmd-doc-7.8.0/pmd_rules_apex_documentation.html#apexdoc">ApexDoc</a></sup></td><td><sup>Missing ApexDoc comment</sup></td></tr>
190190
<tr><td>:yellow_circle:</td><td><sup>force-app/main/default/classes/testSELECT2.cls:4:12</sup></td><td><sup>pmd:<a href="https://docs.pmd-code.org/pmd-doc-7.8.0/pmd_rules_apex_documentation.html#apexdoc">ApexDoc</a></sup></td><td><sup>Missing ApexDoc comment</sup></td></tr>
191191
<tr><td>:yellow_circle:</td><td><sup>force-app/main/default/classes/testSELECT2.cls:11:12</sup></td><td><sup>pmd:<a href="https://docs.pmd-code.org/pmd-doc-7.8.0/pmd_rules_apex_documentation.html#apexdoc">ApexDoc</a></sup></td><td><sup>Missing ApexDoc comment</sup></td></tr>
192+
<tr><td>:white_circle:</td><td><sup>(main) force-app/main/default/classes/NameController.cls:1:1<br/>force-app/main/default/classes/SharingInnerClass.cls:15:1</sup></td><td><sup>cpd:<a href="https://docs.pmd-code.org/latest/pmd_userdocs_cpd.html#refactoring-duplicates">DetectCopyPasteForApex</a></sup></td><td><sup>Duplicate code detected for language 'apex'. Found 2 code locations containing the same block of code consisting of 123 tokens across 10 lines.</sup></td></tr>
192193
<tr><td>:white_circle:</td><td><sup>force-app/main/default/classes/NameController.cls:2:1</sup></td><td><sup>regex:NoTrailingWhitespace</sup></td><td><sup>Found trailing whitespace at the end of a line of code.</sup></td></tr>
193194
<tr><td>:white_circle:</td><td><sup>force-app/main/default/classes/NameController.cls:8:1</sup></td><td><sup>regex:NoTrailingWhitespace</sup></td><td><sup>Found trailing whitespace at the end of a line of code.</sup></td></tr>
194195
<tr><td>:white_circle:</td><td><sup>force-app/main/default/classes/SafeNoSharing.cls:11:1</sup></td><td><sup>regex:NoTrailingWhitespace</sup></td><td><sup>Found trailing whitespace at the end of a line of code.</sup></td></tr>

0 commit comments

Comments
 (0)