trigger:
  - master
  - next

jobs:
  - job: Lint
    pool:
      vmImage: ubuntu-16.04
    steps:
      - task: NodeTool@0
        inputs:
          versionSpec: ^10.13.0
        displayName: 'Install Node.js'
      - task: Npm@1
        inputs:
          command: custom
          customCommand: i -g npm@latest
        displayName: 'Install latest NPM'
      - script: |
          node -v
          npm -v
        displayName: 'Print versions'
      - task: Npm@1
        inputs:
          command: custom
          customCommand: ci
        displayName: 'Install dependencies'
      - script: npm run lint
        displayName: 'Run lint'
      - script: npm run security
        displayName: 'Run NPM audit'
      - script: ./node_modules/.bin/commitlint-azure-pipelines
        displayName: 'Run lint commit message'

  - job: Linux
    pool:
      vmImage: ubuntu-16.04
    strategy:
      maxParallel: 5
      matrix:
        node-12:
          node_version: ^12.0.0
          webpack_version: latest
        node-10:
          node_version: ^10.13.0
          webpack_version: latest
        node-8:
          node_version: ^8.9.0
          webpack_version: latest
        node-6:
          node_version: ^6.9.0
          webpack_version: latest
        node-8-canary:
          node_version: ^8.9.0
          webpack_version: next
          continue_on_error: true
    steps:
      - task: NodeTool@0
        inputs:
          versionSpec: $(node_version)
        displayName: 'Install Node.js $(node_version)'
      - task: Npm@1
        inputs:
          command: custom
          customCommand: i -g npm@latest
        displayName: 'Install latest NPM'
      - script: |
          node -v
          npm -v
        displayName: 'Print versions'
      - task: Npm@1
        inputs:
          command: custom
          customCommand: ci
        displayName: 'Install dependencies'
      - script: npm i webpack@$(webpack_version)
        displayName: 'Install "webpack@$(webpack_version)"'
      - script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
        displayName: 'Run tests with coverage'
      - task: PublishTestResults@2
        inputs:
          testRunTitle: 'Linux with Node.js $(node_version)'
          testResultsFiles: '**/junit.xml'
        condition: succeededOrFailed()
        displayName: 'Publish test results'
      - script: curl -s https://codecov.io/bash | bash -s -- -t $(CODECOV_TOKEN)
        condition: succeededOrFailed()
        displayName: 'Submit coverage data to codecov'

  - job: macOS
    pool:
      vmImage: macOS-10.14
    strategy:
      maxParallel: 5
      matrix:
        node-12:
          node_version: ^12.0.0
          webpack_version: latest
        node-10:
          node_version: ^10.13.0
          webpack_version: latest
        node-8:
          node_version: ^8.9.0
          webpack_version: latest
        node-6:
          node_version: ^6.9.0
          webpack_version: latest
        node-8-canary:
          node_version: ^8.9.0
          webpack_version: next
          continue_on_error: true
    steps:
      - task: NodeTool@0
        inputs:
          versionSpec: $(node_version)
        displayName: 'Install Node.js $(node_version)'
      - task: Npm@1
        inputs:
          command: custom
          customCommand: i -g npm@latest
        displayName: 'Install latest NPM'
      - script: |
          node -v
          npm -v
        displayName: 'Print versions'
      - task: Npm@1
        inputs:
          command: custom
          customCommand: ci
        displayName: 'Install dependencies'
      - script: npm i webpack@$(webpack_version)
        displayName: 'Install "webpack@$(webpack_version)"'
      - script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
        displayName: 'Run tests with coverage'
      - task: PublishTestResults@2
        inputs:
          testRunTitle: 'Linux with Node.js $(node_version)'
          testResultsFiles: '**/junit.xml'
        condition: succeededOrFailed()
        displayName: 'Publish test results'
      - script: curl -s https://codecov.io/bash | bash -s -- -t $(CODECOV_TOKEN)
        condition: succeededOrFailed()
        displayName: 'Submit coverage data to codecov'

  - job: Windows
    pool:
      vmImage: windows-2019
    strategy:
      maxParallel: 5
      matrix:
        node-12:
          node_version: ^12.0.0
          webpack_version: latest
        node-10:
          node_version: ^10.13.0
          webpack_version: latest
        node-8:
          node_version: ^8.9.0
          webpack_version: latest
        node-6:
          node_version: ^6.9.0
          webpack_version: latest
        node-8-canary:
          node_version: ^8.9.0
          webpack_version: next
          continue_on_error: true
    steps:
      - script: 'git config --global core.autocrlf input'
        displayName: 'Config git core.autocrlf'
      - checkout: self
      - task: NodeTool@0
        inputs:
          versionSpec: $(node_version)
        displayName: 'Install Node.js $(node_version)'
      - task: Npm@1
        inputs:
          command: custom
          customCommand: i -g npm@latest
        displayName: 'Install latest NPM'
      - script: |
          node -v
          npm -v
        displayName: 'Print versions'
      - task: Npm@1
        inputs:
          command: custom
          customCommand: ci
        displayName: 'Install dependencies'
      - script: npm i webpack@$(webpack_version)
        displayName: 'Install "webpack@$(webpack_version)"'
      - script: npm run test:coverage -- --ci --reporters="default" --reporters="jest-junit" || $(continue_on_error)
        displayName: 'Run tests with coverage'
      - task: PublishTestResults@2
        inputs:
          testRunTitle: 'Linux with Node.js $(node_version)'
          testResultsFiles: '**/junit.xml'
        condition: succeededOrFailed()
        displayName: 'Publish test results'
      - script: curl -s https://codecov.io/bash | bash -s -- -t $(CODECOV_TOKEN)
        condition: succeededOrFailed()
        displayName: 'Submit coverage data to codecov'
