# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: PluginsTest

on:
  pull_request:
    paths:
      - '.github/workflows/plugins-*.yaml'
      - 'apm-application-toolkit/**'
      - 'apm-commons/**'
      - 'apm-protocol/**'
      - 'apm-sniffer/**'
      - 'test/plugin/**'
      - '**/pom.xml'
      - '!test/e2e/**'
      - '!apm-webapp/**'
      - '!apm-dist/**'
      - '!apm-dist-es7/**'
      - '!apm-docker/**'
      - '!oap-server/**'
      - '!**.md'

jobs:
  PluginsTest:
    name: Plugin
    runs-on: ubuntu-18.04
    timeout-minutes: 90
    strategy:
      matrix:
        case:
          - mysql-scenario
          - undertow-scenario
          - webflux-scenario
          - zookeeper-scenario
          - spring-3.1.x-scenario
          - spring-4.1.x-scenario
          - spring-4.3.x-scenario
          - spring-async-scenario
          - vertx-eventbus-3.x-scenario
          - vertx-web-3.54minus-scenario
          - vertx-web-3.6plus-scenario
          - mariadb-scenario
          - quasar-scenario
          - baidu-brpc-scenario
          - retransform-class-scenario
          - retransform-class-tomcat-scenario
          - graphql-8.x-scenario
          - graphql-9.x-scenario
          - graphql-12.x-scenario
          - hbase-scenario
          - spring-kafka-1.3.x-scenario
          - spring-kafka-2.2.x-scenario
          - spring-kafka-2.3.x-scenario
          - spring-scheduled-scenario
          - elasticjob-2.x-scenario
          - quartz-scheduler-2.x-scenario
          - xxl-job-2.x-scenario
          - thrift-scenario
          - dbcp-2.x-scenario
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Cache local Maven repository
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
      - uses: actions/setup-java@v1
        with:
          java-version: 8
      - name: Run Plugin Test
        uses: ./.github/actions/plugins-test
        with:
          test_case: ${{ matrix.case }}

  Oracle:
    name: Oracle
    runs-on: ubuntu-18.04
    timeout-minutes: 90
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - uses: actions/setup-java@v1
        with:
          java-version: 8
      - name: Add checkstyle-plugin
        run: sed -i '/<\/sourceDirectories>/i <sourceDirectory>scenarios\/oracle-scenario<\/sourceDirectory>' test/plugin/pom.xml
      - name: Build SkyWalking Agent
        run: ./mvnw --batch-mode clean package -DskipTests -Pagent
      - name: Build Docker image
        run: ./mvnw --batch-mode -f test/plugin/pom.xml clean package -DskipTests
      - name: Oracle 10.2.0.4.0 (1)
        run: |
          curl -O https://skyapm.github.io/ci-assist/jars/ojdbc14-10.2.0.4.0.jar
          curl -L -o ./skywalking-agent/plugins/apm-oracle-10.x-plugin-2.0.0.jar https://github.com/SkyAPM/java-plugin-extensions/releases/download/2.0.0/apm-oracle-10.x-plugin-2.0.0.jar
          ./mvnw --batch-mode install:install-file -Dfile=ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar
          bash test/plugin/run.sh oracle-scenario
      - name: Report Coverage
        run: bash -x tools/coverage/report.sh
