name: Deploy Snapshot

on:
  push:
    branches:
      - main

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

permissions:
  contents: read

jobs:
  gradle:
    runs-on: ubuntu-latest
    if: github.repository == 'detekt/detekt' && !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: Build detekt
      uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 # tag=v2
      with:
        arguments: build

    - name: Deploy Snapshot
      uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 # tag=v2
      env:
        ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_KEY }}
        ORG_GRADLE_PROJECT_SIGNING_PWD: ${{ secrets.ORG_GRADLE_PROJECT_SIGNING_PWD }}
        ORG_GRADLE_PROJECT_SONATYPE_USERNAME: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_USERNAME }}
        ORG_GRADLE_PROJECT_SONATYPE_PASSWORD: ${{ secrets.ORG_GRADLE_PROJECT_SONATYPE_PASSWORD }}
      with:
        arguments: publishAllToSonatypeSnapshot -Dsnapshot=true --stacktrace
