pr:
  - master
  - website-content

trigger:
  - master

variables:
  - group: fabric-variables

pool: 'fluentbuild'

jobs:
  - job: BuildTestLint
    workspace:
      clean: all
    steps:
      - template: azure-pipelines.tools.yml

      - script: |
          yarn
        displayName: yarn

      - template: .devops/templates/pr-target-branch.yml

      - script: |
          yarn checkchange
        displayName: check change

      ## TODO: clean up the @fluentui/docs build and @fluentui/react-northstar test WRT component-info generation
      ## the dependency order cannot be expressed with lage configuration currently
      - script: |
          yarn lage build --only --verbose --no-cache --grouped
        displayName: build
        env:
          BACKFILL_CACHE_PROVIDER: 'azure-blob'
          BACKFILL_CACHE_PROVIDER_OPTIONS: '{"connectionString":"$(BACKFILL_CONNECTION_STRING)", "container":"$(BACKFILL_CONTAINER)"}'

      - script: |
          yarn lage test lint --only --verbose --no-cache --grouped
        displayName: test, lint
        env:
          BACKFILL_CACHE_PROVIDER: 'azure-blob'
          BACKFILL_CACHE_PROVIDER_OPTIONS: '{"connectionString":"$(BACKFILL_CONNECTION_STRING)", "container":"$(BACKFILL_CONTAINER)"}'

  - job: ValidateFluent
    workspace:
      clean: all
    steps:
      - template: azure-pipelines.tools.yml

      - script: |
          yarn
        displayName: yarn

      - template: .devops/templates/pr-target-branch.yml

      - script: |
          if [ $BUILD_REASON == "PullRequest" ]; then
            yarn danger ci
          else
            echo "Skipping Danger JS because BUILD_REASON ${BUILD_REASON} != PullRequest"
          fi
        displayName: danger
        env:
          DANGER_GITHUB_API_TOKEN: $(DANGER_GITHUB_API_TOKEN)

      - script: |
          yarn lage build --scope @fluentui/e2e --no-deps --verbose --no-cache --grouped
        displayName: build
        env:
          BACKFILL_CACHE_PROVIDER: 'azure-blob'
          BACKFILL_CACHE_PROVIDER_OPTIONS: '{"connectionString":"$(BACKFILL_CONNECTION_STRING)", "container":"$(BACKFILL_CONTAINER)"}'

      - script: |
          yarn test:fluentui:e2e
        displayName: E2E Tests

      - script: |
          yarn test:fluentui:projects
        displayName: Project Tests

      - script: |
          yarn test:fluentui:circulars
        displayName: Circular Dependencies Tests

      - script: |
          yarn check-for-changed-files
        displayName: check for changed files

  - job: Deploy
    workspace:
      clean: all
    variables:
      PR_DEPLOY: 1
    steps:
      - template: azure-pipelines.tools.yml

      - script: |
          yarn
        displayName: yarn

      - script: |
          yarn lage bundle --scope @uifabric/pr-deploy-site --no-deps --verbose --no-cache --grouped
        displayName: bundle
        env:
          BACKFILL_CACHE_PROVIDER: 'azure-blob'
          BACKFILL_CACHE_PROVIDER_OPTIONS: '{"connectionString":"$(BACKFILL_CONNECTION_STRING)", "container":"$(BACKFILL_CONTAINER)"}'

      - publish: $(Build.ArtifactStagingDirectory)
        artifact: Build-PR-$(Build.BuildNumber)

      - task: AzureUpload@1
        displayName: Upload PR deploy site
        inputs:
          SourcePath: 'apps/pr-deploy-site/dist'
          azureSubscription: 'UI Fabric (bac044cf-49e1-4843-8dda-1ce9662606c8)'
          storage: fabricweb
          ContainerName: '$web'
          BlobPrefix: 'pr-deploy-site/$(Build.SourceBranch)'

  - job: ScreenerFluent
    steps:
      - template: azure-pipelines.tools.yml

      - script: |
          yarn
        displayName: yarn

      - script: |
          git config --global user.email "fabrictactical@microsoft.com"
          git config --global user.name "Fabric Tactical"
          yarn test:fluentui:visual
        displayName: run FUI VR Test
        env:
          SCREENER_API_KEY: $(screener.key)

      - task: DeleteFiles@1
        inputs:
          SourceFolder: $(Build.SourcesDirectory)
          Contents: '**/*'
        condition: always()

  - job: Screener
    workspace:
      clean: all
    steps:
      - template: azure-pipelines.tools.yml

      - script: |
          yarn
        displayName: yarn

      - template: .devops/templates/pr-target-branch.yml

      - script: |
          git config --global user.email "fabrictactical@microsoft.com"
          git config --global user.name "Fabric Tactical"
        displayName: config git user and email

      - script: |
          yarn lage screener --scope vr-tests --debug --verbose --no-deps --no-cache --grouped
        displayName: run VR Test
        env:
          SCREENER_API_KEY: $(screener.key)
          BACKFILL_CACHE_PROVIDER: 'azure-blob'
          BACKFILL_CACHE_PROVIDER_OPTIONS: '{"connectionString":"$(BACKFILL_CONNECTION_STRING)", "container":"$(BACKFILL_CONTAINER)"}'
