name: Samples

on:
  push:
    paths:
      - 'samples/**'
  pull_request:
    paths:
      - 'samples/**'

jobs:
  build:
    runs-on: windows-latest
    strategy:
      fail-fast: true
      matrix:
        java_version: [ 11, 14 ]

    steps:
      - uses: actions/checkout@v2
      - name: "Set up JDK ${{ matrix.java_version }}"
        uses: actions/setup-java@v1
        with:
          java-version: ${{ matrix.java_version }}

      - name: Cache maven dependencies
        uses: actions/cache@v1
        with:
          path: ~/.m2/repository
          key: samples-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            samples-${{ runner.os }}-maven-

      - name: build js sample
        run: ./gradlew build
        working-directory: samples\js

      - name: build Spek sample
        run: ./gradlew build
        working-directory: samples\jvm\spek

      - name: build Junit5 sample
        run: ./gradlew build
        working-directory: samples\jvm\junit5

      - name: build MPP sample
        run: ./gradlew build
        working-directory: samples\multiplatform

      # Kotlin does not yet support to generate jdk 14 byte code
      - name: determine kotlin compile target
        run: |
          export KOTLIN_TARGET=$(if [ "${{ matrix.java_version }}" -eq "14" ]; then echo "13"; else echo "${{ matrix.java_version }}"; fi)
          echo "KOTLIN_TARGET=$KOTLIN_TARGET" >> $GITHUB_ENV
        shell: bash

      - name: build maven sample
        run: ./mvnw -B clean verify "-Djava.version=${{ env.KOTLIN_TARGET }}"
        working-directory: samples/maven
