Skip to content

Fjernet newLines som var overflødige #54

Fjernet newLines som var overflødige

Fjernet newLines som var overflødige #54

name: "Run static code validation"
on:
push:
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"
default: ${{ github.ref }}
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: Static code validation
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
shell: "bash"
steps:
- name: "Set common defaults"
run: |
echo "GIT_REF=${{ github.event.inputs.gitRef || github.ref }}" >> $GITHUB_ENV
echo "VALIDATE_ENTIRE_REPO=${{ github.event.inputs.validateEntireRepo }}" >> $GITHUB_ENV
if [ "${{ github.event_name }}" == "push" ]; then
echo "VALIDATE_ENTIRE_REPO=false" >> $GITHUB_ENV
fi
- name: "Install SF CLI"
uses: navikt/sf-platform/.github/actions/installSfCli@main
with:
version: ${{ vars.SF_CLI_VERSION }}
- name: "Install Salesforce Code Analyzer"
run: |
echo "::group::Install Salesforce Code Analyzer Plugin"
sf plugins install code-analyzer@${{ vars.SF_SCANNER_VERSION }}
sf plugins --core
echo "::endgroup::"
- 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: |
prettierPathsToValidate='**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}'
eslintPathsToValidate='**/{aura,lwc}/**/*.js'
sfCodeAnalyzerPathToValidate='src'
if [ ! ${{ inputs.validateEntireRepo }} ]; then
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
if: ${{ !cancelled() && steps.paths.outcome == 'success' }}
uses: navikt/sf-platform/.github/actions/prettierCheck@main
with:
pathToValidate: ${{ steps.paths.outputs.prettierPathsToValidate }}
- name: Eslint check
if: ${{ !cancelled() && steps.paths.outcome == 'success' }}
uses: navikt/sf-platform/.github/actions/eslintCheck@main
with:
pathToValidate: ${{ steps.paths.outputs.eslintPathsToValidate }}
- name: Run Salesforce Code Analyzer
id: run-code-analyzer
if: ${{ !cancelled() && steps.paths.outcome == 'success' }}
uses: forcedotcom/run-code-analyzer@v1
with:
run-command: run
run-arguments: --normalize-severity --outfile results.html --target ${{ steps.paths.outputs.sfCodeAnalyzerPathToValidate }}
results-artifact-name: salesforce-code-analyzer-results
- name: Check the Salesforce Code Analyzer outputs to determine whether to fail
if: ${{ !cancelled() && steps.paths.outcome == 'success' && ( 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 ) }}
shell: bash
run: exit 1