#
# 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.
#

dist: trusty 

language: java cpp 

compiler: gcc

jdk:
  - oraclejdk8

sudo: required

services:
  - docker

cache:
  directories:
  - $HOME/.m2
  - $HOME/pulsar-dep
  - "$HOME/apache-maven-3.5.0"

# Reconstruct the gpg keys to sign the artifacts
before_deploy:
  - echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import --batch || true
  - echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust --batch || true

# Upgrade to maven 3.5.0
before_install:
  - export M2_HOME=$HOME/apache-maven-3.5.0
  - if [ ! -d $M2_HOME/bin ]; then curl https://archive.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz | tar zxf - -C $HOME; fi
  - export PATH=$M2_HOME/bin:$PATH

install:
  - (sudo bash -x $TRAVIS_BUILD_DIR/pulsar-client-cpp/travis-build.sh $HOME/pulsar-dep $TRAVIS_BUILD_DIR dep) || exit -1
  - (cd site && make travis_setup)

script:
    # Build Java and C++
    - (mvn -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn license:check test package && sudo bash -x $TRAVIS_BUILD_DIR/pulsar-client-cpp/travis-build.sh $HOME/pulsar-dep $TRAVIS_BUILD_DIR compile) || exit -1
    # Build docker images
    - docker/build.sh || exit -1
    # Generate website
    - (cd site && make travis_build) || exit -1

deploy:
  -
     provider: script
     skip_cleanup: true
     script: mvn deploy -DskipTests --settings .travis/settings.xml
     on:
       tags: false
  -
    provider: script
    skip_cleanup: true
    script: mvn install deploy -Papache-release -DskipTests --settings .travis/settings.xml
    on:
      repo: apache/pulsar
      tags: true
  -
    provider: releases
    skip_cleanup: true
    api_key:
      secure: cmjsJ43FwlwWUVh+4TJ/V+yKu/bd78ov0Olm0BFao0tco5ZYNfbRB5jxWD9X4AxpRN4Rfn+u/17oRavUSfv1M/CKMj6mTzXl8gQ6gieIWrgGYfdZrpBxEY0mccaEbaXSGNEWFj/e8oJixdeBeFCp3AkUSTO9DS5f+yoKeF1XibeJIhDLY0xWgeLMkUimzizsiplQBhrPmHExM8DRwSEojs4np56QgcJHdpU9snxkKzjCW5kKcQ6vPXzWpRLBRxLNU0MzYf6HRSqsGE5M3oG8PXNi+WuMS+4pKfxhcw7vS7642/8dWV28Flvet9E+rXutaM7I+jd5ZQG+/jTo2IOTUJ164ZaxYl6rjsf94d8u51AxDPLer+/C19DfrjiYGOLX8Cad+dLWT+otVISie76oNTeThqyG/5W+PpX9cTP/yBeZs5j/mgYJI4mVU4z0fACgyh+Gc3SyBwPvc3eePsFoVS4CvksgoMJJzgtN6to5hh8Pl4dM3FtpWnhjS3Zm2ieu8CUiC3HKCB1DzeNXXRkgcL+D8CXrxcfeOtBs34MEwua7C3fmSagyt1e1/PeYPE4F9Oi6Tiu59jGA5mnx27TDiPCEsf0a5UBHIY95ducB/BBKsXrACmnzAgPSP321fDNKBWMveTw3h2dKLC6PIf78LJ3Rln/i4okCQ8PkgEOz1A0=
    file_glob: true
    file: "distribution/server/target/pulsar-*.tar.gz"
    on:
      repo: apache/pulsar
      tags: true
  -
    provider: script
    skip_cleanup: true
    script: (cd site && make travis_publish)
    on:
        repo: apache/pulsar
        branch: master
  -
    provider: script
    skip_cleanup: true
    script: docker/publish.sh
    on:
       tags: true
