# Scan the C/C++ and Python code for vulnerabilities using CodeQL.
name: CodeQL

on:
  workflow_call:

jobs:
  codeql:
    name: CodeQL
    runs-on: ubuntu-latest
    permissions:
      actions: read
      contents: read
      security-events: write

    steps:
    - name: Clone the git repo
      uses: actions/checkout@v4

    - name: Install pmem/valgrind (including dependencies)
      run: |
        export VALGRIND_DEPS="autoconf \
          automake"

        export BASE_DEPS="build-essential \
          git \
          libdaxctl-dev \
          libndctl-dev \
          pandoc \
          pkg-config"

        sudo apt-get update \
        && sudo apt-get install -y --no-install-recommends \
          ${VALGRIND_DEPS} \
          ${BASE_DEPS} \
        && sudo ./utils/docker/images/install-valgrind.sh

    - name: Initialize CodeQL
      uses: github/codeql-action/init@v2
      with:
        languages: cpp, python

    - name: Build PMDK
      run: make test -j$(nproc)

    - name: CodeQL scan
      uses: github/codeql-action/analyze@v2
