name: CodeQL (daily)

on:
  schedule:
    - cron: '30 1 * * *'
  workflow_dispatch:

jobs:
  analyze:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Set up Java 17
        uses: actions/setup-java@v3
        with:
          distribution: temurin
          java-version: 17

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v2
        with:
          languages: java

      - uses: gradle/gradle-build-action@v2
        env:
          # see https://github.com/github/codeql-action/issues/972
          JAVA_TOOL_OPTIONS: "--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"
        with:
          # skipping build cache is needed so that all modules will be analyzed
          arguments: assemble --no-build-cache

      - name: Perform CodeQL analysis
        uses: github/codeql-action/analyze@v2

  open-issue-on-failure:
    # open an issue on failure because it can be easy to miss CI failure notifications
    needs: analyze
    if: failure()
    uses: ./.github/workflows/reusable-open-issue-on-failure.yml
