name: Query filters tests

on:
  push:
    branches:
    - main
    - releases/v*
  pull_request:
    types:
    - opened
    - synchronize
    - reopened
    - ready_for_review
  schedule:
    - cron: '0 5 * * *'
  workflow_dispatch: {}

defaults:
  run:
    shell: bash

jobs:
  query-filters:
    name: Query Filters Tests
    if: github.triggering_actor != 'dependabot[bot]'
    timeout-minutes: 45
    runs-on: ubuntu-latest
    permissions:
      contents: read # This permission is needed to allow the GitHub Actions workflow to read the contents of the repository.
    steps:
    - name: Check out repository
      uses: actions/checkout@v6

    - name: Install Node.js
      uses: actions/setup-node@v6
      with:
        node-version: 24
        cache: npm

    - name: Install dependencies
      run: npm ci

    - name: Prepare test
      id: prepare-test
      uses: ./.github/actions/prepare-test
      with:
        version: linked

    - name: Check SARIF for default queries with Single include, Single exclude
      uses: ./../action/.github/actions/query-filter-test
      with:
        sarif-file:  ${{ runner.temp }}/results/javascript.sarif
        queries-run: js/zipslip
        queries-not-run: js/path-injection
        config-file: ./.github/codeql/codeql-config-query-filters1.yml
        tools: ${{ steps.prepare-test.outputs.tools-url }}

    - name: Check SARIF for query packs with Single include, Single exclude
      uses: ./../action/.github/actions/query-filter-test
      with:
        sarif-file:  ${{ runner.temp }}/results/javascript.sarif
        queries-run: js/zipslip,javascript/example/empty-or-one-block
        queries-not-run: js/path-injection
        config-file: ./.github/codeql/codeql-config-query-filters2.yml
        tools: ${{ steps.prepare-test.outputs.tools-url }}

    - name: Check SARIF for query packs and local queries with Single include, Single exclude
      uses: ./../action/.github/actions/query-filter-test
      with:
        sarif-file:  ${{ runner.temp }}/results/javascript.sarif
        queries-run: js/zipslip,javascript/example/empty-or-one-block,inrepo-javascript-querypack/show-ifs
        queries-not-run: js/path-injection,complex-python-querypack/show-ifs,complex-python-querypack/foo/bar/show-ifs
        config-file: ./.github/codeql/codeql-config-query-filters3.yml
        tools: ${{ steps.prepare-test.outputs.tools-url }}
