name: CI

on: [push, pull_request]

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ ubuntu-18.04, windows-2019 ]
        jdk: [ 8, 11 ]
    steps:
      - uses: actions/checkout@v2
        with:
          path: dubbo-spi-extensions
      - uses: actions/checkout@v2
        with:
          repository: 'apache/dubbo'
          ref: '3.0'
          path: dubbo
      - name: "Set up JDK ${{ matrix.jdk }}"
        uses: actions/setup-java@v1
        with:
          java-version: ${{ matrix.jdk }}
      - uses: actions/cache@v2
        name: "Cache local Maven repository"
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
      - name: "Build tools"
        run: |
          cd ./dubbo
          ./mvnw --batch-mode -U -e --no-transfer-progress install -pl dubbo-build-tools -am -DskipTests=true
      - name: "Test with Maven"
        timeout-minutes: 40
        if: ${{ startsWith( matrix.os, 'ubuntu') }}
        run: |
          cd ./dubbo-spi-extensions
          ./mvnw --batch-mode -U -e --no-transfer-progress clean test verify -Pjacoco -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -DskipTests=false -DskipIntegrationTests=false -Dcheckstyle.skip=false -Dcheckstyle_unix.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true
      - name: "Test with Maven"
        timeout-minutes: 50
        if: ${{ startsWith( matrix.os, 'windows') }}
        run: |
          cd ./dubbo-spi-extensions
          ./mvnw --batch-mode -U -e --no-transfer-progress clean test verify -Pjacoco -D"http.keepAlive=false" -D"maven.wagon.http.pool=false" -D"maven.wagon.httpconnectionManager.ttlSeconds=120" -D"maven.wagon.http.retryHandler.count=5" -DskipTests=false -DskipIntegrationTests=true -D"checkstyle.skip=false" -D"checkstyle_unix.skip=true" -D"rat.skip=false" -D"maven.javadoc.skip=true"
      - name: "Pack rat file if failure"
        if: failure()
        run: 7z a ${{ github.workspace }}/rat.zip *rat.txt -r
      - name: "Upload rat file if failure"
        if: failure()
        uses: actions/upload-artifact@v2
        with:
          name: "rat-file"
          path: ${{ github.workspace }}/rat.zip
      - name: "Pack checkstyle file if failure"
        if: failure()
        run: 7z a ${{ github.workspace }}/checkstyle.zip *checkstyle* -r
      - name: "Upload checkstyle file if failure"
        if: failure()
        uses: actions/upload-artifact@v2
        with:
          name: "checkstyle-file"
          path: ${{ github.workspace }}/checkstyle.zip
      - name: "Upload coverage to Codecov"
        uses: codecov/codecov-action@v1
