Skip to content

Commit

Permalink
Kjøre code analyzer igjennom action
Browse files Browse the repository at this point in the history
  • Loading branch information
torhakon committed Aug 29, 2024
1 parent 5ef0ec1 commit 9d89b8b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 23 deletions.
60 changes: 60 additions & 0 deletions .github/actions/runSalesforceCodeAnalyzer/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "Run Salesforce Code Scanner"
description: "Run Prettier on the code"
inputs:
pathToValidate:
description: "The path to the files we want to validate"
required: true
runs:
using: "composite"
steps:
- name: Print inputs
shell: bash
run: |
echo "Path to validate: ${{ inputs.pathToValidate }}"
- name: Check if sf cli and code analyzer is installed
id: checkInstallationStatus
shell: bash
run: |
needToInstallSfCli=false
needToInstallSfCodeAnalyzer=false
package='@salesforce/cli'
plugin='@salesforce/sfdx-scanner'
if [ `npm list -g | grep -c $package` -eq 0 ]; then
echo $package is not installed
needToInstallSfCli=true
elif [ `sf plugins | grep -c $plugin` -eq 0 ]; then
echo $package is installed, need to install $plugin.
needToInstallSfCodeAnalyzer=true
else
echo $package and $plugin is installed.
fi
echo "needToInstallSfCli=$needToInstallSfCli" >> $GITHUB_OUTPUT
echo "needToInstallSfCodeAnalyzer=$needToInstallSfCodeAnalyzer" >> $GITHUB_OUTPUT
- id: installSfCli
if: ${{ steps.checkInstallationStatus.outputs.needToInstallSfCli }}
uses: navikt/crm-workflows-base/.github/actions/installSF@master

- id: installSfCodeAnalyzer
if: ${{ steps.checkInstallationStatus.outputs.needToInstallSfCodeAnalyzer }}
shell: bash
run: |
sf plugins install @salesforce/sfdx-scanner
- name: Run Salesforce Code Analyzer
id: run-code-analyzer
uses: forcedotcom/run-code-analyzer@v1
with:
run-command: run
run-arguments: --normalize-severity --outfile results.html --target ${{ inputs.pathToValidate }}
results-artifact-name: salesforce-code-analyzer-results

- name: Check the Salesforce Code Analyzer outputs to determine whether to fail
shell: bash
if: |
steps.run-code-analyzer.outputs.exit-code > 0 ||
steps.run-code-analyzer.outputs.num-sev1-violations > 0 ||
steps.run-code-analyzer.outputs.num-violations > 10
run: exit 1
51 changes: 28 additions & 23 deletions .github/workflows/ciStaticCodeValidation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,34 @@ jobs:
with:
pathToValidate: ${{ steps.paths.outputs.eslintPathsToValidate }}

# Install SF CLI
- uses: navikt/crm-workflows-base/.github/actions/installSF@master
- name: Salesforce Code Analyzer
uses: navikt/sf-platform/.github/actions/runSalesforceCodeAnalyzer@main
with:
pathToValidate: ${{ steps.paths.outputs.sfCodeAnalyzerPathToValidate }}

- name: "Get diff sf file names"
id: getDiff
if: ${{ inputs.validateEntireRepo }} == false
run: |
mapfile -t diffedSfFiles < <(git diff --name-only --diff-filter=d HEAD~ -- src\**\*.{cls,cmp,component,css,html,js,json,page,trigger,xml})
json=$(jq -c -n '$ARGS.positional' --args "${diffedSfFiles[@]}")
echo "diffedSfFiles=$json" >> $GITHUB_OUTPUT
# # Install SF CLI
# - uses: navikt/crm-workflows-base/.github/actions/installSF@master

- name: Run Salesforce Code Analyzer
id: run-code-analyzer
uses: forcedotcom/run-code-analyzer@v1
if: steps.getDiff.outputs.diffedSfFiles != '[]' || inputs.validateEntireRepo
with:
run-command: run
run-arguments: --normalize-severity --outfile results.html --target ${{ inputs.validateEntireRepo == true && 'src' || fromJson( steps.getDiff.outputs.diffedSfFiles) }}
results-artifact-name: salesforce-code-analyzer-results
# - name: "Get diff sf file names"
# id: getDiff
# if: ${{ inputs.validateEntireRepo }} == false
# run: |
# mapfile -t diffedSfFiles < <(git diff --name-only --diff-filter=d HEAD~ -- src\**\*.{cls,cmp,component,css,html,js,json,page,trigger,xml})
# json=$(jq -c -n '$ARGS.positional' --args "${diffedSfFiles[@]}")
# echo "diffedSfFiles=$json" >> $GITHUB_OUTPUT

# - name: Run Salesforce Code Analyzer
# id: run-code-analyzer
# uses: forcedotcom/run-code-analyzer@v1
# if: steps.getDiff.outputs.diffedSfFiles != '[]' || inputs.validateEntireRepo
# with:
# run-command: run
# run-arguments: --normalize-severity --outfile results.html --target ${{ inputs.validateEntireRepo == true && 'src' || fromJson( steps.getDiff.outputs.diffedSfFiles) }}
# results-artifact-name: salesforce-code-analyzer-results

- name: Check the Salesforce Code Analyzer outputs to determine whether to fail
if: |
steps.run-code-analyzer.outputs.exit-code > 0 ||
steps.run-code-analyzer.outputs.num-sev1-violations > 0 ||
steps.run-code-analyzer.outputs.num-violations > 10
run: exit 1
# - name: Check the Salesforce Code Analyzer outputs to determine whether to fail
# if: |
# steps.run-code-analyzer.outputs.exit-code > 0 ||
# steps.run-code-analyzer.outputs.num-sev1-violations > 0 ||
# steps.run-code-analyzer.outputs.num-violations > 10
# run: exit 1

0 comments on commit 9d89b8b

Please sign in to comment.