name: "CodeQL Code Scanning"

on:
  push:
    branches:
      - "develop"
      - "release-*"
    paths:
      # File types
      - "**.cpp"
      - "**.h"
      - "**.java"
      - "**.ui"

      # Directories
      - "buildconfig/**"
      - "cmake/**"
      - "launcher/**"
      - "libraries/**"
      - "program_info/**"
      - "tests/**"

      # Files
      - "CMakeLists.txt"
      - "COPYING.md"

      # Workflows
      - ".github/codeql/**"
      - ".github/workflows/codeql.yml"
      - ".github/actions/setup-dependencies/**"
  pull_request:
    paths:
      # File types
      - "**.cpp"
      - "**.h"
      - "**.java"
      - "**.ui"

      # Directories
      - "buildconfig/**"
      - "cmake/**"
      - "launcher/**"
      - "libraries/**"
      - "program_info/**"
      - "tests/**"

      # Files
      - "CMakeLists.txt"
      - "COPYING.md"

      # Workflows
      - ".github/codeql/**"
      - ".github/workflows/codeql.yml"
      - ".github/actions/setup-dependencies/**"
  workflow_dispatch:

jobs:
  CodeQL:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          submodules: "true"

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          config-file: ./.github/codeql/codeql-config.yml
          queries: security-and-quality
          languages: cpp, java

      - name: Setup dependencies
        uses: ./.github/actions/setup-dependencies
        with:
          build-type: Debug

      - name: Configure and Build
        run: |
          cmake --preset linux_debug
          cmake --build --preset linux_debug

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@v3
