name: Microsoft C++ Code Analysis

on:
  schedule:
    - cron: '0 0 * * 0'
  workflow_dispatch:

env:
  # Path to the CMake build directory.
  build: '${{ github.workspace }}/build'

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

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

      - name: Setup
        run: |
          $Url = "https://archives.boost.io/release/1.90.0/source/boost_1_90_0.zip"
          (New-Object System.Net.WebClient).DownloadFile($Url, "$RUNNER_TEMP\boost.zip")
          Expand-Archive -Path "$RUNNER_TEMP\boost.zip" -DestinationPath C:\local
          Rename-Item -Path "C:\local\boost_1_90_0" -NewName "boost"

      - name: Configure CMake
        env:
          BOOST_ROOT: C:\local\boost
        run: cmake -B ${{ env.build }} -DQL_USE_STD_CLASSES=ON

      - name: Run MSVC Code Analysis
        uses: microsoft/msvc-code-analysis-action@v0.1.1
        # Provide a unique ID to access the sarif output path
        id: run-analysis
        env:
          CAExcludePath: C:\local\boost
        with:
          cmakeBuildDirectory: ${{ env.build }}
          buildConfiguration: Release
          ruleset: '${{ github.workspace }}/.msvc-analysis.ruleset'

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

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

