name: detekt with type resolution

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - '**'

env:
  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
  GRADLE_CACHE_USERNAME: ${{ secrets.GRADLE_CACHE_USERNAME }}
  GRADLE_CACHE_PASSWORD: ${{ secrets.GRADLE_CACHE_PASSWORD }}

permissions:
  contents: read

jobs:
  plain:
    permissions:
      contents: read  # for actions/checkout to fetch code
      security-events: write  # for github/codeql-action/upload-sarif to upload SARIF results
    runs-on: ubuntu-latest
    if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
    steps:
      - name: Checkout Repo
        uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3

      - name: Setup Java
        uses: actions/setup-java@16cca5479d7c6b6843f6a6515640ba33c6501543 # tag=v3
        with:
          java-version: 17
          distribution: 'temurin'

      - name: Run detekt-cli with argsfile
        uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 # tag=v2
        with:
          arguments: :detekt-cli:runWithArgsFile

      - name: Upload SARIF to Github using the upload-sarif action
        uses: github/codeql-action/upload-sarif@3f62b754e23e0dd60f91b744033e1dc1654c0ec6 # tag=v2
        if: ${{ always() }}
        with:
          sarif_file: build/detekt-report.sarif


  gradle:
    runs-on: ubuntu-latest
    if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
    steps:
    - name: Checkout Repo
      uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3

    - name: Setup Java
      uses: actions/setup-java@16cca5479d7c6b6843f6a6515640ba33c6501543 # tag=v3
      with:
        java-version: 17
        distribution: 'temurin'
    - name: Run analysis
      uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 # tag=v2
      with:
        arguments: detektMain detektTest
