language: php
php: 5.6
branches:
  except:
    - master
    - /^feature\//
notifications:
  email:
    on_success: never
    on_failure: always
  slack:
      secure: cHbnVNoDkoOMPCs1lzD4u3NA0ALfQMtXQdkntADSCqgleHHuRS1SmSGU2o7lj1HkOLGNDEyIHmpeQMaZBvvVG1iq3qVHWROnIx9lV2uuXPRDB7xlFSZ71pxr2GRG2fzO5DVIye+sMsyie2A5RCQ6NHaCzO6B3Q0pss0pza3TZ8sYXbezkGoEI4NLXPKCZaQboZAA8uPsiAPg1G4KGazDYkXQ2jg5lk9Uokf51OehzbkpAYfn2f8A+ZxJ8T48LrFC8sLxl+cDWRRdRneX32WCzksoSlOhsbRsLkf8IZVWxLlX9QC1QMg8JIe6/tU98fPMZBF3ZWuSNuLVOHpMAr+/fXxqwBW7bss+vYR/bW5L7oRSyJx5tMAwR5BOcSvIUCXOs4Tq00JMELbn7oL/cesie6L3SJcuxtXPggOdRrhMfX5ehRvFETp+mAbIDtr19+JRhTkjLpMIXx7y2IrJijtCxqAavhJ2iMGzpDp343tRCTNYml/yOB23VnyWSI/43Y87pqIa93GfddbcTidSbnTO6bdiSoIRumiFYdmpX/plmH/jdOxjBeDo6uKc2+KoJgdgr7HIGdOQRdQdqoOMF8H+ZxiUmCs3000pzEsb0ugV7yNubRBboVSEKnegeDWpj04V6iQCAWZx6PHkJWRb9a7XnGyPS3f0YReh5blL9NpZYno=
env:
  global:
    # GH_TOKEN
    - secure: "GIFHCpRBw07hm/RwDUbeh1EZS3nUCRFnsAhyeBm02a5dKbCCIrAUoI5HVjTPyFiG/UKaRo3u/7byA3ROmXgVE48Hg5n4E3+ga8zOwdRdXql7V6pwu4bII4Kr+4qFgIDkn8ca1Ut1bxKQZI/NP/FR73pZ/pst/rtw27M4Au/PZSHAtAkMF1KSqcRSfvggAtqnhh3xFTFx13XvakX7zpP1AyD1Yft4dHhhZN+BHTxQgRrl+fJLky1MAwIwOl1xOF1VH+RQDdh3yXLHMfbznTjdeE9vJCiEjnZPUgZ+aXusLj1bJoNgrRNVCCikrOMLFK854YxxzGuzRtN/6xhcB/8LeFypw8jhHNnswJ5TX8heB7i4Jbu/7OTCk5/Ew0uG6kveTtvWsAOmVZZAqSl4Z/hZowCAavXy2X1DmZpsjQ0ljxZC271a5UQpI5HF7EKVoFhzvxyxZrxlUYSSDFTOoNGauKvsZbtgz6A0eAQOpjtuWXRTYnbxsOEZFuZCuOwUU6EdDtSA0RIpxnUI3qwn26+GzGTaaxjwTQ+ZtytmHaddC3jgKZ9EfZB6yOUeXXdnI+h0coSR8lp4yjOU/ZWnA9n96+fMqwnR5zCbxJeErhI8RJFWJL1/so1k0wq3t4OixVjDGY1rJkkugD8AnIUEPgB/gfGtF5t6J4WGrpFhWzej9/c="
before_install:
  - composer self-update
  - if [ ! -z "$TRAVIS_TAG" ]; then
      gem install sass;
      npm install -g gulp &>/dev/null;
    fi
install:
  - if [ ! -z "$TRAVIS_TAG" ]; then
      npm install &>/dev/null;
      gulp -up &>/dev/null;
    fi
  - cd $TRAVIS_BUILD_DIR/src && composer install --no-dev;
  - cd $TRAVIS_BUILD_DIR/bin/build && composer install --no-dev
script:
  - export SHORT_COMMIT=$(echo $TRAVIS_COMMIT | cut -c1-9)
  - echo "Branch ($TRAVIS_BRANCH)"
  - cd $TRAVIS_BUILD_DIR/bin/build
  - if [ "$TRAVIS_BRANCH" == "develop" ]; then
      php build.php dev -Dpackage_dir=$TRAVIS_BUILD_DIR/../repo_pkgs -Dxml.version=dev-$SHORT_COMMIT -Dstr.fileversion=_develop;
    elif [ ! -z "$TRAVIS_TAG" ]; then
      php build.php prod -Dpackage_dir=$TRAVIS_BUILD_DIR/../repo_pkgs -Dxml.version=$TRAVIS_TAG;
    else
      echo "($TRAVIS_BRANCH) is not a supported branch for builds";
    fi
before_deploy:
  - export PROJ_PKGS_PATH=$TRAVIS_BUILD_DIR/../repo_pkgs
  - export PROJ_PKGS=$HOME/build/$TRAVIS_REPO_SLUG/../repo_pkgs/*.zip
  - if [ "$TRAVIS_BRANCH" == 'develop' ]; then
        FILES_PATH=$PROJ_PKGS_PATH;
        JSON="{";
        FILES=$FILES_PATH/*.zip;
        COUNT=`ls $FILES 2>/dev/null | wc -l | awk '{print $1}'`;
        COMMIT=$TRAVIS_COMMIT;
        SHORT_COMMIT=$(echo $COMMIT | cut -c1-9)
        CURRENT_DATE=`date +%s`

        JSON+="\"count\":$COUNT,";
        JSON+="\"commit\":\"$COMMIT\",";
        JSON+="\"commit_short\":\"$SHORT_COMMIT\",";
        JSON+="\"date\":\"$CURRENT_DATE\",";
        JSON+="\"files\":[";

        i=0;
        for file in ${FILES[@]}; do
            i=$(($i + 1));
            SIZE=`wc -c < $file | awk '{print $1}'`;
            DATE=`stat --format=\"%m\" $file`;
            JSON+="{";
            JSON+="\"file\":\"${file##*/}\",";
            JSON+="\"size\":$SIZE,";
            JSON+="\"date\":$DATE";
            JSON+="}";

            if [ $i != $COUNT ]; then
                JSON+=",";
            fi
        done;
        JSON+="]}";

        echo $JSON > "$FILES_PATH/map.json";
      fi
deploy:
  - provider: releases
    api_key:
      secure: "KgEZx0dHoPLOYj9T087flZKgaf4ggasJcd/DOjHjsXKhjyLYuWZNLOdJaT0MQ+UJ2RwzW+7ESR1lquwEqUN8uPFaA05SZwrCyJU1pOgTYqunM+Sz+lRWANMjgwtGNAQvPfTTAoaKZxrOVSMxv0U2OBAHE2lEsDvz7kwCuHbsoU3/xY144ecUG2lWItHjxQr2X7GmApBgCZ63OPaHK/NP1a8xtkQT+kTfKRHIZwPCyRplSRhqaa8ftQoi5SynaHtECi9/RYCRp3wgclbCPHRH3Eez4li+AdE8Q/X+LK/jmIYqOUWvq8IpS0ePg67fuE4cBNLYBrbPWgSPfUka3/61KyGRTw+2ofdf9eMOtJQa7JZUSWWUEeeyeBFIomNvY40nWSmC+T/l5EixIwBFF7CzVatnDPCz3w4gPYxAVwQjTtKqqFu6ZfeQNp0asj9OqukF3nJbN42iuIh6vxHxIQ6U3WMo+0t507i0rYf3Esl3YGlMVUuN7mNlWNv5eKrfD2CLHeBiDvo6SRCdYpgLu6FMBnwM2Fadlm51nAN/tpSxXEA1gUoVT3rJ8e6vnFcdy1ZHq1DPMtiZ8oMLBtdq8lcDs8DzKqCwImfmsDtM7M040JG/MuB5kVUXLcA5ycRCh1piDUAqITmvPucYHO8hT63cMZHwcxlqw1Ta3ckB4Ng3Eqg="
    skip_cleanup: true
    file_glob: true
    file: "${PROJ_PKGS}"
    on:
      repo: gantry/gantry5
      tags: true
  - provider: s3
    access_key_id: AKIAIGEIWVFNBMVSH2UA
    secret_access_key:
      secure: "DP32BDS3fk7/tLsZxj5CjiAT5GLHQFNOFte9Rds7eird+xqOSqUXHVplkOSVPKCt6V3CIO3wtxe97T4cuxtoobwVlwF8WRmrS4x98u2sLIS9lSZZzDg/W8tkLjOmW9QOKFtBEykj1z1i9nYDlhKFDtGNIkN7juZUz5UZ2S3Unwsm94vcm8ATghXGclwfib329I+7GVIA24PMUv2ETl0PGs+s+D1KmhXeU5UwharxnM+X4kyIsCBPrxXX+2QfAiSrjqKwHfzGQjRJIAQ6m4UdzuZWbxSAiJ4TrWrwRYDCKn8Va72g9UcUdiOyLd6Eg54iSCKdbQ+zELYjhcuwO7g4kpc6V/wgcHYVG4stPyuiXc2G+ZAGXDtW0H7QobeXEUTAsad2AshmCA+lFCmecywBdpsDSYp9ZBY0Qfevncmx0CIWlaPPVjUQ3FMn+oniamJlmbwpmHLiZuCyDE9sSxeQrPSI/7N+zSD03EM6AxIBswaF6XzIhcP3aPz9BzJ2v/YHpPzxtqLaLhEswxWkghmRYASaJn6Ut9xwuWkfhO2UIzkBW6RA3HV6CjZ5opQBe4IyxiVsB2qPzQfxGXz4pN2BoTbuLyf4jS0CA1h6g/7vpCz6VnOuTzBg/c7nQjk8Y69hUYHL91lSlZ/a7tNHe3z9DtaxVg24MG56e+mevYpUgLk="
    bucket: gantry5
    local-dir: "$PROJ_PKGS_PATH"
    upload-dir: nightly
    skip_cleanup: true
    acl: public_read
    on:
      repo: gantry/gantry5
      branch: develop
after_deploy:
  - echo "Branch ($TRAVIS_BRANCH) - Tag ($TRAVIS_TAG)"
  - if [ ! -z "$TRAVIS_TAG" ]; then
      git config user.email "bot@travis-ci.org";
      git config user.name "Travis CI";
      git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*";
      git fetch --quiet;
      git checkout develop;
      git reset --hard HEAD;
      cd $TRAVIS_BUILD_DIR/bin/build;
      php build.php prod-versions -Dupdate_versions=true -Dxml.version=$TRAVIS_TAG;
      cd $TRAVIS_BUILD_DIR;
      git commit -am "Release [$TRAVIS_TAG] - Automatic Version Number Updates";
      git push --force --quiet --set-upstream https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git develop:master &>/dev/null;
    fi
  - if [ "$TRAVIS_BRANCH" == 'develop' ]; then
      curl -L http://gantry.org/cibuilds >/dev/null 2>&1;
    fi
