name: Gradle publish

on:
  workflow_dispatch:
  release:
    types: [ created ]

jobs:
  publish:
    environment:
      name: publish
    strategy:
      matrix:
        os: [ macOS-latest, windows-latest ]
    runs-on: ${{matrix.os}}
    steps:
      - uses: actions/checkout@v3.0.0
      - uses: actions/setup-java@v3.10.0
        with:
          java-version: 11
          distribution: liberica
      - name: Cache konan
        uses: actions/cache@v3.0.1
        with:
          path: ~/.konan
          key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
          restore-keys: |
            ${{ runner.os }}-gradle-
      - name: Publish Windows Artifacts
        if: matrix.os == 'windows-latest'
        uses: gradle/gradle-build-action@v2.4.2
        with:
          arguments: |
            publishAllPublicationsToSpaceRepository
            -Ppublishing.targets=all
            -Ppublishing.space.user=${{ secrets.SPACE_APP_ID }}
            -Ppublishing.space.token=${{ secrets.SPACE_APP_SECRET }}
      - name: Publish Mac Artifacts
        if: matrix.os == 'macOS-latest'
        uses: gradle/gradle-build-action@v2.4.2
        with:
          arguments: |
            publishMacosX64PublicationToSpaceRepository
            publishMacosArm64PublicationToSpaceRepository
            publishIosX64PublicationToSpaceRepository
            publishIosArm64PublicationToSpaceRepository
            publishIosSimulatorArm64PublicationToSpaceRepository
            -Ppublishing.targets=all
            -Ppublishing.space.user=${{ secrets.SPACE_APP_ID }}
            -Ppublishing.space.token=${{ secrets.SPACE_APP_SECRET }}