#/
# @license Apache-2.0
#
# Copyright (c) 2019 The Stdlib Authors.
#
# Licensed 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.
#/

# Define the triggers which will cause a build to run:
trigger:

  # Define branch triggers:
  branches:

    # List branches for which changes will trigger a build:
    include:
      - master
      - develop

  # Define path triggers:
  paths:

    # List paths for which changes should trigger a build:
    include:
      - bin
      - data
      - include
      - lib
      - src
      - "*.gyp"
      - "*.gypi"
      - manifest.json

    # List paths for which changes should *not* trigger a build:
    exclude:
      - benchmark
      - docs
      - etc
      - examples
      - snippets
      - package.json
      - datapackage.json
      - "*.md"


# Define pull request triggers which will cause a build to run:
pr:

  # Define branch triggers:
  branches:

    # List branches against which PRs will trigger a build to run:
    include:
      - master
      - develop


  # Define path triggers:
  paths:

    # List paths for which changes should trigger a build:
    include:
      - bin
      - data
      - etc
      - include
      - lib
      - src
      - "*.gyp"
      - "*.gypi"
      - manifest.json

    # List paths for which changes should *not* trigger a build:
    exclude:
      - benchmark
      - docs
      - examples
      - snippets
      - _tools
      - package.json
      - datapackage.json
      - "*.md"


jobs:
  - job: 'unit_tests_linux'

    # Define a display name for use in the UI:
    displayName: 'unit tests: linux'

    # Define how long a job is allowed to run before timing out:
    timeoutInMinutes: 360

    # Define how long a job is allowed to cancel:
    cancelTimeoutInMinutes: 5

    # Specify the host environment:
    pool:
      vmImage: 'ubuntu-16.04'

    # Define variable sets for parallel job execution:
    strategy:

      # Define the maximum number of parallel jobs:
      maxParallel: 10

      # Define variable sets which will be used to create separate jobs (one per variable set!):
      matrix:
        node_v16:
          NODE_VERSION: '16'
          NPM_VERSION: '>2.7.0'
        node_v14:
          NODE_VERSION: '14'
          NPM_VERSION: '>2.7.0'
        node_v12:
          NODE_VERSION: '12'
          NPM_VERSION: '>2.7.0'
        node_v10:
          NODE_VERSION: '10'
          NPM_VERSION: '>2.7.0 <7.0.0'
        node_v8:
          NODE_VERSION: '8'
          NPM_VERSION: '>2.7.0 <6.0.0'
        node_v6:
          NODE_VERSION: '6'
          NPM_VERSION: '>2.7.0 <6.0.0'
        node_v4:
          NODE_VERSION: '4'
          NPM_VERSION: '>2.7.0 <6.0.0'

    steps:
      # Configure clone settings:
      - checkout: self
        clean: false
        fetchDepth: 100 # limit clone depth to the most recent 100 commits
        lfs: false

      # Install Node.js:
      - task: NodeTool@0

        # Define a UI display name:
        displayName: 'Install Node.js'

        # Define a task-specific timeout:
        timeoutInMinutes: 5

        # Define the Node.js version to install:
        inputs:
          versionSpec: '$(NODE_VERSION)'

      # Update the npm client (older clients cannot handle scoped modules):
      - task: Npm@1

        # Define a UI display name:
        displayName: 'Update npm'

        # Define a task-specific timeout:
        timeoutInMinutes: 5

        # Update the global npm installation:
        inputs:
          command: custom
          customCommand: 'install -g npm@"$(NPM_VERSION)"'


      # Print debug information:
      - task: bash@3

        # Define a UI display name:
        displayName: 'Debug info'

        # Define a task-specific timeout:
        timeoutInMinutes: 2

        # Define the task inputs:
        inputs:
          targetType: inline
          script: |
            git --version
            node --version
            node -p 'process.platform + "@" + process.arch'
            npm --version
            npm config get registry
