name: Snapshots Publish

on:
  push:
    branches:
      - dev
      - snapshots-publishing
    paths-ignore:
      - 'docs/**'
      - '**/README*.md'

jobs:
  publish-mirai:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: git submodule update --init --recursive
      - uses: actions/setup-java@v2
        with:
          distribution: 'adopt'
          java-version: '17'

      - run: chmod -R 777 *

      - name: Init gradle project
        run: ./gradlew clean --scan

      - run: >
          ./gradlew updateSnapshotVersion --info --scan
        env:
          MIRAI_IS_SNAPSHOTS_PUBLISHING: true
          SNAPSHOTS_PUBLISHING_USER: ${{ secrets.SNAPSHOTS_PUBLISHING_USER }}
          SNAPSHOTS_PUBLISHING_KEY: ${{ secrets.SNAPSHOTS_PUBLISHING_KEY }}
          SNAPSHOTS_PUBLISHING_URL: ${{ secrets.SNAPSHOTS_PUBLISHING_URL }}
          CURRENT_BRANCH_NAME: dev

      - name: Assemble
        run: ./gradlew assemble --scan

      - name: Check
        run: >
          ./gradlew check --scan
          -Dmirai.network.show.all.components=true
          -Dkotlinx.coroutines.debug=on
          -Dmirai.network.show.packet.details=true
          -Dmirai.network.handle.selector.logging=true

      - run: >
          ./gradlew publish --info --scan
        env:
          MIRAI_IS_SNAPSHOTS_PUBLISHING: true
          SNAPSHOTS_PUBLISHING_USER: ${{ secrets.SNAPSHOTS_PUBLISHING_USER }}
          SNAPSHOTS_PUBLISHING_KEY: ${{ secrets.SNAPSHOTS_PUBLISHING_KEY }}
          SNAPSHOTS_PUBLISHING_URL: ${{ secrets.SNAPSHOTS_PUBLISHING_URL }}
          CURRENT_BRANCH_NAME: dev

      - run: >
          ./gradlew publishSnapshotPage --info
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
