# Build and publish a node.js-based library from a github repository. Only
# publish anything to npm if the tests succeeded (so the build was ok)
# and the build is spawned from a new release in github.

pool:
  vmImage: 'Ubuntu 16.04'

steps:
  - task: NodeTool@0
    inputs:
      versionSpec: '8.x'
    displayName: 'Install Node.js'

  - script: |
      npm install
      npm run test
    displayName: 'Npm install and test'

  - task: Npm@1
    # only execute this task when the sourceBranch is a new release
    condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
    inputs:
      command: publish
      publishEndpoint: npmjs.com
    displayName: 'Publish to npmjs.com'
