language: node_js
node_js:
  - "lts/*"

jobs:
  include:
    - stage: Test
      if: tag IS blank 
      before_install:
        - sudo apt-get install libsecret-1-dev
        - sudo apt-get install fakeroot
      script:
        - npm run lint
        - npm test
        - npm run coverage
        - npm run make
    # Define the release stage that runs semantic-release
    - stage: Create Release
      if: (NOT type IN (pull_request)) AND (branch = master)
      script: skip
      before_install:
        - sudo apt-get install libsecret-1-dev
        - sudo apt-get install fakeroot
      deploy:
        provider: script
        skip_cleanup: true
        script: npx semantic-release
    # Define the stages that build the binaries and attach them to the release/tag.
    - stage: Build and Deploy
      if: (NOT type IN (pull_request)) AND tag IS present
      os: linux
      before_install:
        - sudo apt-get install libsecret-1-dev
        - sudo apt-get install fakeroot
      before_script: echo "{\"apiKey\":\"$BUNGIE_API_KEY\",\"clientId\":\"$BUNGIE_CLIENT_ID\",\"clientSecret\":\"$BUNGIE_CLIENT_SECRET\"}" > config/bungieApp.json
      script: npm run make
      before_deploy: zip -r "$TRAVIS_OS_NAME.zip" ./out/make/*
      deploy:
        provider: releases
        api_key: "$GITHUB_TOKEN"
        skip_cleanup: true
        file: "$TRAVIS_OS_NAME.zip"
        on:
          all_branches: true # We rely on the stage condition.
    - stage: Build and Deploy
      if: tag IS present
      os: osx
      before_script: echo "{\"apiKey\":\"$BUNGIE_API_KEY\",\"clientId\":\"$BUNGIE_CLIENT_ID\",\"clientSecret\":\"$BUNGIE_CLIENT_SECRET\"}" > config/bungieApp.json
      script: npm run make
      before_deploy: zip -r "$TRAVIS_OS_NAME.zip" ./out/make/*
      deploy:
        provider: releases
        api_key: "$GITHUB_TOKEN"
        skip_cleanup: true
        file: "$TRAVIS_OS_NAME.zip"
        on:
          all_branches: true # We rely on the stage condition.
    - stage: Build and Deploy
      if: (NOT type IN (pull_request)) AND tag IS present
      os: windows
      before_install:
        - yarn config delete proxy
        - npm config rm proxy
        - npm config rm https-proxy
      before_script: echo "{\"apiKey\":\"$BUNGIE_API_KEY\",\"clientId\":\"$BUNGIE_CLIENT_ID\",\"clientSecret\":\"$BUNGIE_CLIENT_SECRET\"}" > config/bungieApp.json
      script: npm run make
      before_deploy: 
        - choco install zip
        - zip -r "$TRAVIS_OS_NAME.zip" ./out/make/*
      deploy:
        provider: script
        skip_cleanup: true
        script: node tools/releaseWindows.js "$GITHUB_TOKEN"
        on:
          all_branches: true # We rely on the stage condition.