name: "Quarkus Cron Native image"
on:
  schedule:
    - cron: '0 2 * * *'
  repository_dispatch:


jobs:
  build:
    runs-on: ubuntu-18.04
    strategy:
      matrix:
        java: [ 11 ]
    name: build-and-testing
    steps:

      - name: Stop MySQL
        run: sudo systemctl stop mysql

      - name: Pull docker image
        run: docker pull quay.io/quarkus/ubi-quarkus-native-image:19.3.1-java${{ matrix.java }}

      - name: Set up Java
        uses: actions/setup-java@v1
        with:
          java-version: ${{ matrix.java }}

      - name: Checkout Quarkus
        uses: actions/checkout@v2
        with:
          repository: quarkusio/quarkus
          ref: master

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

      - name: Build Quarkus
        run: mvn -B install -DskipTests -DskipITs -Dno-format

      - name: Run integration tests in native
        run: mvn -B  --settings azure-mvn-settings.xml verify -f integration-tests/pom.xml -Dno-format -Ddocker -Dnative -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-native-image:19.3.1-java${{ matrix.java }} -Dtest-postgresql -Dtest-elasticsearch -Dtest-mysql -Dtest-dynamodb -Dtest-vault -Dtest-neo4j

      - name: Report
        if: always()
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_API_TOKEN }}
          STATUS: ${{ job.status }}
          JAVA_VERSION: ${{ matrix.java }}
        run: |
          echo "The report step got status: ${STATUS}"
          sudo apt-get update -o Dir::Etc::sourcelist="sources.list" \
            -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
          sudo apt-get install -y gnupg2 gnupg-agent
          echo Installing SDKMAN
          curl -s "https://get.sdkman.io" | bash
          source ~/.sdkman/bin/sdkman-init.sh && \
          sdk install kotlin 1.3.61 && \

          # we need to install Java 8 because kscript doesn't yet work with Java 11: https://github.com/holgerbrandl/kscript/issues/239
          if [[ ${JAVA_VERSION} = 11 ]]; then
            echo "y" | sdk install java $(sdk list java | grep open.*\s*8.0.* | awk '{print $8}')
            export JAVA_HOME="$HOME/.sdkman/candidates/java/current"
          fi

          sdk install kscript 2.9.0
          [[ ${JAVA_VERSION} = 8 ]] && ISSUE_NUMBER="6717" || ISSUE_NUMBER="6723"
          kscript .github/NativeBuildReport.kts ${GITHUB_TOKEN} ${STATUS} ${ISSUE_NUMBER}
