name: "MSVC-CodeAnalysis"

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  build: ${{ github.workspace }}/build
  config: Debug

jobs:
  analyze:
    name: Analyze
    runs-on: windows-latest

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

      - name: Install Qt
        uses: jurplel/install-qt-action@v4
        with:
          version: '6.7.2'
          host: 'windows'
          target: 'desktop'

      - name: Set up MSVC
        uses: ilammy/msvc-dev-cmd@v1

      - name: Configure CMake
        run: cmake -B "${{ env.build }}" -DCMAKE_BUILD_TYPE=${{ env.config }} -DJKQtPlotter_BUILD_EXAMPLES=OFF -DJKQtPlotter_BUILD_TOOLS=OFF -DJKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS=OFF

      - name: Build CMake
        run: cmake --build "${{ env.build }}" --config "${{ env.config }}"

      - name: Run MSVC Code Analysis
        uses: microsoft/msvc-code-analysis-action@v0.1.1
        id: run-analysis
        with:
          cmakeBuildDirectory: ${{ env.build }}
          buildConfiguration: ${{ env.config }}
          ruleset: NativeRecommendedRules.ruleset

      - name: Upload SARIF to GitHub
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: ${{ steps.run-analysis.outputs.sarif }}

      - name: Upload SARIF as an Artifact
        uses: actions/upload-artifact@v4
        with:
          name: sarif-file
          path: ${{ steps.run-analysis.outputs.sarif }}
