# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
#
# SPDX-License-Identifier: AGPL-3.0-only

name: Static Analysis

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]
  schedule:
    - cron: '0 7 * * 6'

permissions:
  actions: read
  contents: read
  security-events: write

jobs:
  njsscan:
    runs-on: ubuntu-latest
    name: Njsscan code scanning
    steps:
      - name: Checkout the code
        uses: actions/checkout@v6.0.2
      - name: Scan with njsscan
        id: njsscan
        uses: ajinabraham/njsscan-action@c7b65a3590ade829628b2b3c87b34ac0ce666a79 # master
        with:
          args: '--sarif --output results.sarif src || true'
      - name: Upload njsscan report
        uses: github/codeql-action/upload-sarif@ae9ef3a1d2e3413523c3741725c30064970cc0d4 # v3.32.5
        with:
          sarif_file: results.sarif

  codeql:
    name: CodeQL analysis
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        language: [ 'javascript' ]
        # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6.0.2

      - name: Initialize CodeQL
        uses: github/codeql-action/init@ae9ef3a1d2e3413523c3741725c30064970cc0d4 # v3.32.5
        with:
          languages: ${{ matrix.language }}
          queries: +security-and-quality

      - name: Autobuild
        uses: github/codeql-action/autobuild@ae9ef3a1d2e3413523c3741725c30064970cc0d4 # v3.32.5

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@ae9ef3a1d2e3413523c3741725c30064970cc0d4 # v3.32.5
        with:
          category: "/language:${{ matrix.language }}"
