name: Deploy Snapshot

on:
  push:
    branches:
      - master

jobs:
  gradle:
    runs-on: ubuntu-latest
    if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
    env:
      GRADLE_OPTS: -Dorg.gradle.daemon=false
    steps:
    - name: Checkout Repo
      uses: actions/checkout@v2

    - name: Cache Gradle Folders
      uses: actions/cache@v2
      with:
        path: |
          ~/.gradle/caches/
          ~/.gradle/wrapper/
        key: cache-gradle-${{ hashFiles('detekt-bom/build.gradle.kts') }}
        restore-keys: |
          cache-gradle-

    - name: Setup Java
      uses: actions/setup-java@v1
      with:
        java-version: 8

    - name: Build detekt
      run: ./gradlew build --build-cache --parallel

    - name: Deploy Snapshot
      env:
        MAVEN_CENTRAL_USER: ${{ secrets.MAVEN_CENTRAL_USER }}
        MAVEN_CENTRAL_PW: ${{ secrets.MAVEN_CENTRAL_PW }}
      run: ./gradlew publishAllPublicationsToSonatypeSnapshotRepository -Dsnapshot=true --stacktrace
      if: ${{ github.repository == 'detekt/detekt'}}
