# CodeQL build configuration for nvme-cli
# Mostly based on auto-configuration with additions and tweaks for:
# * meson install
# * language detection
name: "CodeQL"

on:
  push:
    branches: [ "master" ]
  pull_request:
    # The branches below must be a subset of the branches above
    branches: [ "master" ]
  schedule:
    - cron: '24 2 * * 5'

jobs:
  analyze:
    name: Analyze
    # Runner size impacts CodeQL analysis time. To learn more, please see:
    #   - https://gh.io/recommended-hardware-resources-for-running-codeql
    #   - https://gh.io/supported-runners-and-hardware-resources
    #   - https://gh.io/using-larger-runners
    # Consider using larger runners for possible analysis time improvements.
    runs-on: 'ubuntu-latest'
    timeout-minutes: 360
    permissions:
      actions: read
      contents: read
      security-events: write

    strategy:
      fail-fast: false
      matrix:
        language: [ 'c-cpp', 'python' ]
        # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
        # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
        # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
        # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

    steps:
    - name: Checkout repository
      uses: actions/checkout@v5

    - name: Install build tools
      run: |
          sudo apt-get update
          sudo apt-get install meson

    # Initializes the CodeQL tools for scanning.
    - if: matrix.language == 'c-cpp'
      name: Initialize CodeQL C
      uses: github/codeql-action/init@v4
      with:
        languages: 'c-cpp'

    - if: matrix.language == 'python'
      name: Initialize CodeQL Python
      uses: github/codeql-action/init@v4
      with:
        languages: 'python'
        config-file: ./.github/codeql/codeql-config.yml
  
    - name: meson build
      run: |
         meson setup --force-fallback-for=libnvme,json-c .build
         ninja -C .build

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