Skip to content

Run static code validation #14

Run static code validation

Run static code validation #14

name: "Run static code validation"
on:
workflow_call:
inputs:
validateEntireRepo:
description: "Validate entire repo (setting to false will only validate the diff against main)"
default: true
required: false
type: boolean
gitRef:
description: "Which git ref to use"
required: false
type: string
secrets:
SF_DEVHUB_URL:
required: true
workflow_dispatch:
inputs:
validateEntireRepo:
description: "Validate entire repo (unchecking will only validate the diff against main)"
default: true
required: false
type: boolean
jobs:
validate:
name: Validate Build
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
shell: "bash"
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
ref: ${{ inputs.gitRef }}
fetch-depth: "0"
- name: "Install dev dependencies"
run: |
npm ci
- name: "Set variables"
id: paths
run: |
if [ ${{ inputs.validateEntireRepo }} ]; then
prettierPathsToValidate='.'
eslintPathsToValidate='.'
sfCodeAnalyzerPathToValidate='src'
else
mapfile -t prettier_diffed_files_to_lint < <(git diff --name-only --diff-filter=d HEAD~ -- \*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml})
mapfile -t eslint_diffed_files_to_lint < <(git diff --name-only --diff-filter=d HEAD~ -- \*.js})
mapfile -t codeAnalyzer_diffed_sf_files < <(git diff --name-only --diff-filter=d HEAD~ -- src\**\*.{cls,cmp,component,css,html,js,json,page,trigger,xml})
codeAnalyzer_json=$(jq -c -n '$ARGS.positional' --args "${codeAnalyzer_diffed_sf_files[@]}")
prettierPathsToValidate ="${prettier_diffed_files_to_lint[@]}"
eslintPathsToValidate="${eslint_diffed_files_to_lint[@]}"
sfCodeAnalyzerPathToValidate=$codeAnalyzer_json
fi
echo "prettierPathsToValidate=$prettierPathsToValidate" >> $GITHUB_OUTPUT
echo "eslintPathsToValidate=$eslintPathsToValidate" >> $GITHUB_OUTPUT
echo "codeAnalyzer_json=$codeAnalyzer_json" >> $GITHUB_OUTPUT
echo "sfCodeAnalyzerPathToValidate=sfCodeAnalyzerPathToValidate" >> $GITHUB_OUTPUT
- name: Prettier Check
uses: navikt/sf-platform/.github/actions/prettierCheck@main
with:
pathToValidate: ${{ steps.paths.outputs.prettierPathsToValidate }}
- name: Eslint check
uses: navikt/sf-platform/.github/actions/eslintCheck@main
with:
pathToValidate: ${{ steps.paths.outputs.eslintPathsToValidate }}
- name: Salesforce Code Analyzer
uses: navikt/sf-platform/.github/actions/runSalesforceCodeAnalyzer@main
with:
pathToValidate: ${{ steps.paths.outputs.sfCodeAnalyzerPathToValidate }}
# # Install SF CLI
# - uses: navikt/crm-workflows-base/.github/actions/installSF@master
# - 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