name: $(BuildID)

pool:
  vmImage: 'ubuntu-16.04'

variables:
- group: 'env-variables'

strategy:
  maxParallel: 3
  matrix:
    Node 6:
      node_version: 6.x
    Node 8:
      node_version: 8.x
    Node 10:
      node_version: 10.x

steps:
- task: NodeTool@0
  inputs:
    versionSpec: $(node_version)
  displayName: 'Install Node.js'

- script: |
    yarn install --ignore-engines
    echo 'Downloading Code Climate Test Reporter...'
    curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
    chmod +x ./cc-test-reporter
    echo 'Done downloading Code Climate Test Reporter.'
  displayName: 'Install dependencies'

- script: |
    ./cc-test-reporter before-build
    yarn ci 2> /dev/null 
    if [ $? -eq 0 ]
      then
        echo '"yarn ci" passed, publishing to code climate.'
        ./cc-test-reporter after-build --exit-code 0
        echo 'Publishing code coverage results to coveralls.io'
        yarn coverage
        exit 0
      else
        echo '"yarn ci" failed, publishing to code climate.'
        ./cc-test-reporter after-build --exit-code 1
        exit 1
    fi
  displayName: 'eslint > mocha > codeclimate & coveralls'
  env:
    CC_TEST_REPORTER_ID: $(CC_TEST_REPORTER_ID)
    COVERALLS_SERVICE_NAME: $(COVERALLS_SERVICE_NAME)
    COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN)
    GIT_BRANCH: $(Build.SourceBranch)
    GIT_COMMIT_SHA: $(Build.SourceVersion)

- task: PublishTestResults@2
  displayName: 'Publish test results (Azure Pipelines)'
  condition: succeededOrFailed()
  inputs:
    testRunner: JUnit
    testResultsFiles: 'test/junit-results.xml'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage results (Azure Pipelines)'
  inputs: 
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'
    reportDirectory: '$(System.DefaultWorkingDirectory)/coverage/lcov-report'

name: $(BuildID)

resources:
  repositories:
    - repository: apt
      type: github
      name: futagoza/apt

variables:
- group: 'env-variables'

jobs:

- template: eslint.yml@apt

- template: node-test.yml@apt
  parameters:
    node_version: 6.x
    after:
    - script: yarn coverage
      env:
        COVERALLS_SERVICE_NAME: $(COVERALLS_SERVICE_NAME)
        COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN)
        GIT_BRANCH: $(Build.SourceBranch)
        GIT_COMMIT_SHA: $(Build.SourceVersion)
    azure_coverage: True

Use Pipeline templates from futagoza/apt
Use Pipeline templates from futagoza/apt
