# Copyright 2024-2026, Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

name: Check against DLL injection (trunk)

permissions: read-all

on:
  workflow_dispatch:
  schedule:
    # Run every day at 22:00 UTC
    - cron: '0 22 * * *'

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  check-dll-injection:
    runs-on: windows-2022
    # Disabling this workflow for non ispc/ispc repo to reduce the traffic to artifacts downloads.

    if: github.repository == 'ispc/ispc'
    steps:
    - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0

    - name: Install required packages
      run: |
        Install-ChocoPackage wget
        Install-ChocoPackage procmon
        Install-ChocoPackage 7zip
        pip install defusedxml
      shell: pwsh

    - name: Download ISPC trunk archives
      env:
        ZIP_URL: https://github.com/ispc/ispc/releases/download/trunk-artifacts/ispc-trunk-windows.zip
      run: |
        ZIP="ispc-trunk-windows.zip"
        echo "Download artifact $ZIP_URL" >> "$GITHUB_STEP_SUMMARY"
        wget --quiet -O "$ZIP" "$ZIP_URL"
        7z x "$ZIP"
        ISPC_BIN_DIR="ispc-trunk-windows/bin"
        echo "$ISPC_BIN_DIR" >> "$GITHUB_PATH"
      shell: bash

    - name: Check ISPC binary for DLL injection
      run: |
        python .github\workflows\scripts\check-dll-injection.py dbghelp.dll
      shell: cmd

    - name: Upload results
      uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
      if: always()
      with:
        name: reports
        path: |
          dll_load_filtered.xml
