name: Gradle CI

on:
  push:
    branches: [ master ]
    paths-ignore: [ "**.md", "schemas/**", ".editorconfig", ".gitignore", ".gitattributes" ]
  pull_request:
    branches: [ master ]
    paths-ignore: [ "**.md", "schemas/**", ".editorconfig", ".gitignore", ".gitattributes" ]

jobs:
  gradle:
    strategy:
      fail-fast: false
      matrix:
        os: [ "ubuntu-latest", "windows-latest", "macos-latest" ]
    runs-on: ${{ matrix.os }}
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-java@v3
        with:
          distribution: zulu
          java-version: 11

      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2

      - name: Setup Gradle Dependencies Cache
        uses: actions/cache@v3
        with:
          path: ~/.gradle/caches
          key: ${{ matrix.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }}


      - name: Setup Gradle Wrapper Cache
        uses: actions/cache@v3
        with:
          path: ~/.gradle/wrapper
          key: ${{ matrix.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}

      - name: Build
        uses: gradle/gradle-build-action@v2
        with:
          arguments: assemble
      - name: Test
        uses: gradle/gradle-build-action@v2
        with:
          arguments: check
      - name: Package
        uses: gradle/gradle-build-action@v2
        with:
          arguments: fatJar
      - name: Upload build
        uses: actions/upload-artifact@v3
        with:
          name: 'minosoft-${{ matrix.os }}'
          path: build/libs/minosoft-fat-*.jar
