# Aim to have fast builds
# TODO: Maybe don't build the files into seperate folders and copy them after that anyway.

language: php

php:
  - 7.0

git:
  depth: 1
  submodules: false

if: branch IS master
if: tag IS blank

branches:
  only:
    master

# Simultaneous builds for common and uncommon resolutions
env:
  matrix:
    - buildType=Common
    - buildType=Uncommon
  global:
    - secure: "X0PrKXLjW6r8e0zT7+SshhP7uaW/5EW2BJPCc/oRIWX6eC4QLXv0lQBstIZ6vChAvgYv2K1CcBlWHrQarTlHqmkYnfHAfOFK//qURFUfuyTkKcKU/aCYvm4op0jPGw8+wbOkxwfnbvOaa0E7oBv4GCXVPYCU3nm7E1H2XHgcfJukaEhpvFfHaNohoh1ygVt65G1WIoYwUIFh/0XXgP6RVBDCAU+QYaNopK5co2O40vhjtg2f0la4zMsunMEY5oXNMaM/oRAvGBaXJ3KUTgSb0+uRlEM/XxOYRyfmG6fjVXYbwL6j+kNCLsZklCfN98AAvbysCebQWhI46vJcPa/Ji/ImMeAns17fBlHMn+PI0MIBbPkMztEkenXW3Yv1BquBHElhB758Fd1Zt9KdA5H5JC6WfuRBd+QBwlzOBxOrVfmaI3uOmy3cEvQZgckPGN+7SdSDyrw/+ukM+Ks775qaZ/bw3eQyMx6DpfATa6pVzK0AWj4Xlm4IufaOFI/hy2gH60hV+3KuYXeSJOq4gXYbtJcruAbHK5YOeEmAEsVCpz+RKSuAWWvcPktoyLTOjbGTM89Yf3jFgZOFi4HNCt7K67/bDnflsHj04X/pDm3gQ0XhxQx1Sj1j0IG1XLh+k37uL2FZusBbd+8kI1SkMED5aVWTp1WmbJN+dJXZMWJxJPc=" # GITHUB_TOKEN

matrix:
  fast_finish: true

# === Build steps ===

# No dependencies
install: npm install -g github-release-cli@0.4.1

# No need to debug the PHP code. Keeping this enabled slows down execution.
before_script:
  - phpenv config-rm xdebug.ini

script: ./build.sh

after_success:
  # Create zip file
  - mkdir build
  - mv $TRAVIS_BUILD_DIR/Enhancement/* build
  - mv $TRAVIS_BUILD_DIR/Enthusiast/* build
  - mv $TRAVIS_BUILD_DIR/Modifications/* build
  - mv $TRAVIS_BUILD_DIR/Performance/* build
  - mv $TRAVIS_BUILD_DIR/Quality/* build
  - mv $TRAVIS_BUILD_DIR/Workaround/* build
  - cd build
  - $([ "$buildType" = "Common" ] && echo zip -o -9 -r -q "../graphicPacksCommon_$TRAVIS_BUILD_NUMBER"".zip" ./*  || echo zip -o -9 -r -q "../graphicPacks$TRAVIS_BUILD_NUMBER""_Uncommon.zip" ./*)
  - cd ..
  # Create github release
  # The odd naming of the releases will create a more compatible order. It's intended.
  - |
    github-release upload \
      --owner=slashiee \
      --repo=cemu_graphic_packs \
      --tag="Travis$TRAVIS_BUILD_NUMBER" \
      --name="Graphic Packs: version $TRAVIS_BUILD_NUMBER" \
      --body="$(git log -1 --format='Commited at %ci by **%cn** in commit %h%n### %s%n```%n%b%n```%n') $(if [ '$buildType' = 'Common' ]; then echo 'This is a prerelease with only the common resolutions.'; fi)" \
      $([ "$buildType" = "Common" ] && echo "--prerelease=true" || echo "--prerelease=false") \
      $([ "$buildType" = "Common" ] && echo "graphicPacksCommon_$TRAVIS_BUILD_NUMBER"".zip" || echo "graphicPacks$TRAVIS_BUILD_NUMBER""_Uncommon.zip")
  # Request a new Github Pages build when all the releases are present so that the links will be updated. Need to use a seperate file due to weird yaml parsing.
  - sh requestGithubPages.sh