name: CodeQL Analysis

on:
  workflow_call:
  schedule:
    - cron: '42 23 * * 5'

env:
  NODE_OPTIONS: --max_old_space_size=6144

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest
    permissions:
      actions: read
      contents: read
      security-events: write
    strategy:
      fail-fast: true
      matrix:
        language:
          - javascript
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Prepare
        uses: ./.github/actions/prepare
        with:
          build: false

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v2
        with:
          config-file: ./.github/codeql/codeql-config.yml

      - name: Perform CodeQL analysis
        uses: github/codeql-action/analyze@v2
        with:
          upload: false
          output: sarif-results

      - name: Upload Artifact
        uses: actions/upload-artifact@v3
        with:
          name: sarif-results
          path: sarif-results
          retention-days: 1

      - name: Upload SARIF
        uses: github/codeql-action/upload-sarif@v2
        with:
          sarif_file: sarif-results/javascript.sarif
