name: Windup-dependent projects' PR builder for JDK11

on:
  pull_request:
    branches:
      - master
      - 'releases/**'

jobs:
  windup-build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.3.4
      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: 'temurin'
          java-package: jdk
      - name: Cache local Maven repository
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-windup-build-${{ github.sha }}
          restore-keys:
            ${{ runner.os }}-maven-windup-build
      - name: Build on JDK 11
        run: mvn -B clean install -DskipTests

  windup-rulesets-build:
    runs-on: ubuntu-latest
    needs: [windup-build]
    strategy:
      fail-fast: false
      matrix:
        jdk-distribution: [ temurin ]
        ruleset-test: [ WindupRulesTest,  WindupRulesLinksTest]
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2.3.4
        with:
          repository: windup/windup-rulesets
          ref: ${{ github.base_ref }}
      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: ${{ matrix.jdk-distribution }}
          java-package: jdk
      - name: Cache local Maven repository
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-windup-rulesets-build-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-maven-windup-build-${{ github.sha }}
      - name: Test
        run: mvn clean test -nsu -f rules -Dtest=${{ matrix.ruleset-test }}
      - name: Build for the windup-maven-plugin-build
        run: mvn clean install -nsu -DskipTests

  windup-maven-plugin-build:
    runs-on: ubuntu-latest
    needs: [windup-rulesets-build]
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2.3.4
        with:
          repository: windup/windup-maven-plugin
          ref: ${{ github.base_ref }}
      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: 'adopt'
          java-package: jdk
      - name: Cache local Maven repository
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-windup-rulesets-build-${{ github.sha }}
      - name: Build
        run: mvn clean install -nsu

  windup-quickstarts-build:
    runs-on: ubuntu-latest
    needs: [windup-build]
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2.3.4
        with:
          repository: windup/windup-quickstarts
          ref: ${{ github.base_ref }}
      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: 'adopt'
          java-package: jdk
      - name: Cache local Maven repository
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-windup-build-${{ github.sha }}
      - name: Build
        run: mvn clean install -s settings.xml -nsu