diff --git a/.github/actions/runSalesforceCodeAnalyzer/action.yml b/.github/actions/runSalesforceCodeAnalyzer/action.yml new file mode 100644 index 0000000..6e9b5f4 --- /dev/null +++ b/.github/actions/runSalesforceCodeAnalyzer/action.yml @@ -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 diff --git a/.github/workflows/ciStaticCodeValidation.yml b/.github/workflows/ciStaticCodeValidation.yml index f4b502a..12d2afb 100644 --- a/.github/workflows/ciStaticCodeValidation.yml +++ b/.github/workflows/ciStaticCodeValidation.yml @@ -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