# azure-pipelines.yml

trigger:
  - main

stages:
  - stage: build
    displayName: "Deploy to chromatic"
    jobs:
      - job: Chromatic_Deploy
        displayName: Install packages and publishes to Chromatic
        variables:
          npm_config_cache: $(Pipeline.Workspace)/.npm
        steps:
          # Install node and install/cache modules
          - task: NodeTool@0
            inputs:
              versionSpec: "12.x"
            displayName: "Install Node.js"
          - task: Cache@2
            displayName: Install and cache packages
            inputs:
              key: 'npm | "$(Agent.OS)" | package-lock.json'
              restoreKeys: |
                npm | "$(Agent.OS)"
              path: $(npm_config_cache)
          - script: npm ci
            condition: ne(variables.CACHE_RESTORED, 'true')

            # Publish to chromatic
          - task: CmdLine@2
            displayName: Publish to Chromatic
            inputs:
              # Disable --auto-accept-changes to fail each build that has changes (and check them in Chromatic's App)
              script: npx chromatic --project-token=${CHROMATIC_PROJECT_TOKEN} --auto-accept-changes
