name: Samples

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

jobs:
    build:
        runs-on: windows-latest
        strategy:
            fail-fast: true
            matrix:
                java_version: [9, 10, 11, 12, 13, 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 jasmine sample
                run: ./gradlew build
                working-directory: samples\js\jasmine

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

            -   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 "::set-env name=KOTLIN_TARGET::$KOTLIN_TARGET"
                shell: bash

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