name: "CodeQL"

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]
  schedule:
    - cron: '24 7 * * 4'

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest
    timeout-minutes: 360
    permissions:
      actions: read
      contents: read
      security-events: write

    strategy:
      fail-fast: false
      matrix:
        language: [ 'cpp', 'java' ]

    steps:
    - name: Checkout repository
      uses: actions/checkout@v3.6.0

    - name: Initialize CodeQL
      uses: github/codeql-action/init@v2
      with:
        languages: ${{ matrix.language }}

    - name: Setup JDK 17
      uses: actions/setup-java@v3.12.0
      with:
        distribution: "temurin"
        java-version: 17
          
    - name: Setup Gradle
      uses: gradle/gradle-build-action@v2.8.0

    - name: Setup cmake
      run: |
        echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "cmake;3.22.1" --sdk_root=${ANDROID_SDK_ROOT} &> /dev/null
        echo "sdk.dir=${ANDROID_HOME}" > local.properties
    
    - name: Build
      run: |
        chmod +x ./gradlew
        ./gradlew :app:assembleAppRelease

    - name: Perform CodeQL Analysis
      uses: github/codeql-action/analyze@v2
      with:
        category: "/language:${{matrix.language}}"
