name: CodeQL

on:
  push:
    branches:
      - master
    paths-ignore:
      - '**/*.md'
      - '**/doc/*'
  pull_request:
    branches:
      - master
    paths-ignore:
      - '**/*.md'
      - '**/doc/*'
  schedule:
    - cron: "24 18 * * 3"

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

    strategy:
      fail-fast: true
      matrix:
        language:
          - cpp

    steps:
      - name: Checkout ProFTPD
        uses: actions/checkout@v3
        with:
          repository: proftpd/proftpd

      - name: Checkout mod_vroot
        uses: actions/checkout@v3
        with:
          path: contrib/mod_vroot

      - name: Install Packages
        run: |
          sudo apt-get update
          sudo apt-get install --yes libssl-dev zlib1g-dev

      - name: Configure
        run: |
          ./configure --with-modules=mod_sftp:mod_vroot

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v2
        with:
          languages: ${{ matrix.language }}
          config-file: contrib/mod_vroot/.codeql.yml
          queries: +security-and-quality
          source-root: contrib/mod_vroot

      - name: Build
        run: |
          make

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@v2
        with:
          category: "/language:${{ matrix.language }}"
          checkout_path: contrib/mod_vroot
          output: sarif-results
          upload: true
