Skip to content

Run static code validation #18

Run static code validation

Run static code validation #18

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
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 "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 }}