<commit_before>parameters:
  - name: VSCODE_QUALITY
    type: string

steps:
  - task: NodeTool@0
    inputs:
      versionSpec: "16.x"

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - task: AzureKeyVault@1
      displayName: "Azure Key Vault: Get Secrets"
      inputs:
        azureSubscription: "vscode-builds-subscription"
        KeyVaultName: vscode
        SecretsFilter: "<PASSWORD>-mixin-password"

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        cat << EOF > ~/.netrc
        machine github.com
        login vscode
        password $(github-<PASSWORD>-mixin-password)
        EOF

        git config user.email "<EMAIL>"
        git config user.name "VSCode"
      displayName: Prepare tooling

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        git fetch https://github.com/$(VSCODE_MIXIN_REPO).git $VSCODE_DISTRO_REF
        echo "##vso[task.setvariable variable=VSCODE_DISTRO_COMMIT;]$(git rev-parse FETCH_HEAD)"
        git checkout FETCH_HEAD
      condition: and(succeeded(), ne(variables.VSCODE_DISTRO_REF, ' '))
      displayName: Checkout override commit

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        git pull --no-rebase https://github.com/$(VSCODE_MIXIN_REPO).git $(node -p "require('./package.json').distro")
      displayName: Merge distro

  - script: |
      mkdir -p .build
      node build/azure-pipelines/common/computeNodeModulesCacheKey.js $VSCODE_ARCH $ENABLE_TERRAPIN > .build/yarnlockhash
      node build/azure-pipelines/common/computeBuiltInDepsCacheKey.js > .build/builtindepshash
    displayName: Prepare yarn cache flags

  # using `genericNodeModules` instead of `nodeModules` here to avoid sharing the cache with builds running inside containers
  - task: Cache@2
    inputs:
      key: "genericNodeModules | $(Agent.OS) | .build/yarnlockhash"
      path: .build/node_modules_cache
      cacheHitVar: NODE_MODULES_RESTORED
    displayName: Restore node_modules cache

  # Cache built-in extensions to avoid GH rate limits.
  - task: Cache@2
    inputs:
      key: '"builtInDeps" | .build/builtindepshash'
      path: .build/builtInExtensions
    displayName: Restore built-in extensions

  - script: |
      set -e
      tar -xzf .build/node_modules_cache/cache.tgz
    condition: and(succeeded(), eq(variables.NODE_MODULES_RESTORED, 'true'))
    displayName: Extract node_modules cache

  - script: |
      set -e
      npx https://aka.ms/enablesecurefeed standAlone
    timeoutInMinutes: 5
    retryCountOnTaskFailure: 3
    condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'), eq(variables['ENABLE_TERRAPIN'], 'true'))
    displayName: Switch to Terrapin packages

  - script: |
      set -e
      sudo apt update -y
      sudo apt install -y build-essential pkg-config libx11-dev libx11-xcb-dev libxkbfile-dev libsecret-1-dev libnotify-bin
    displayName: Install build tools
    condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))

  - script: |
      set -e
      for i in {1..3}; do # try 3 times, for Terrapin
        yarn --frozen-lockfile --check-files && break
        if [ $i -eq 3 ]; then
          echo "Yarn failed too many times" >&2
          exit 1
        fi
        echo "Yarn failed $i, trying again..."
      done
    env:
      ELECTRON_SKIP_BINARY_DOWNLOAD: 1
      PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
      GITHUB_TOKEN: "$(github-<PASSWORD>)"
    displayName: Install dependencies
    condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))

  - script: |
      set -e
      node build/lib/builtInExtensions.js
    env:
      GITHUB_TOKEN: "$(github-distro-mixin-password)"
    displayName: Download missing built-in extensions

  - script: |
      set -e
      node build/azure-pipelines/common/listNodeModules.js .build/node_modules_list.txt
      mkdir -p .build/node_modules_cache
      tar -czf .build/node_modules_cache/cache.tgz --files-from .build/node_modules_list.txt
    condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))
    displayName: Create node_modules archive

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    # Mixin must run before optimize, because the CSS loader will inline small SVGs
    - script: |
        set -e
        node build/azure-pipelines/mixin
      displayName: Mix in quality

  - script: |
      set -e
      yarn npm-run-all -lp core-ci extensions-ci hygiene eslint valid-layers-check vscode-dts-compile-check tsec-compile-check
    env:
      GITHUB_TOKEN: "$(github-distro-mixin-password)"
    displayName: Compile & Hygiene

  - script: |
      set -e
      yarn --cwd build compile
      ./.github/workflows/check-clean-git-state.sh
    displayName: Check /build/ folder

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        yarn --cwd test/smoke compile
        yarn --cwd test/integration/browser compile
      displayName: Compile test suites
      condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - task: AzureCLI@2
      inputs:
        azureSubscription: "vscode-builds-subscription"
        scriptType: pscore
        scriptLocation: inlineScript
        addSpnToEnvironment: true
        inlineScript: |
          Write-Host "##vso[task.setvariable variable=AZURE_TENANT_ID]$env:tenantId"
          Write-Host "##vso[task.setvariable variable=AZURE_CLIENT_ID]$env:servicePrincipalId"
          Write-Host "##vso[task.setvariable variable=AZURE_CLIENT_SECRET;issecret=true]$env:servicePrincipalKey"<commit_msg>Only do the `/build/` folder check on OSS, where we don't mixin (#161381)<commit_after>parameters:
  - name: VSCODE_QUALITY
    type: string

steps:
  - task: NodeTool@0
    inputs:
      versionSpec: "16.x"

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - task: AzureKeyVault@1
      displayName: "Azure Key Vault: Get Secrets"
      inputs:
        azureSubscription: "vscode-builds-subscription"
        KeyVaultName: vscode
        SecretsFilter: "github-distro-mixin-password"

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        cat << EOF > ~/.netrc
        machine github.com
        login vscode
        password $(github-distro-mixin-password)
        EOF

        git config user.email "<EMAIL>"
        git config user.name "VSCode"
      displayName: Prepare tooling

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        git fetch https://github.com/$(VSCODE_MIXIN_REPO).git $VSCODE_DISTRO_REF
        echo "##vso[task.setvariable variable=VSCODE_DISTRO_COMMIT;]$(git rev-parse FETCH_HEAD)"
        git checkout FETCH_HEAD
      condition: and(succeeded(), ne(variables.VSCODE_DISTRO_REF, ' '))
      displayName: Checkout override commit

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        git pull --no-rebase https://github.com/$(VSCODE_MIXIN_REPO).git $(node -p "require('./package.json').distro")
      displayName: Merge distro

  - script: |
      mkdir -p .build
      node build/azure-pipelines/common/computeNodeModulesCacheKey.js $VSCODE_ARCH $ENABLE_TERRAPIN > .build/yarnlockhash
      node build/azure-pipelines/common/computeBuiltInDepsCacheKey.js > .build/builtindepshash
    displayName: Prepare yarn cache flags

  # using `genericNodeModules` instead of `nodeModules` here to avoid sharing the cache with builds running inside containers
  - task: Cache@2
    inputs:
      key: "genericNodeModules | $(Agent.OS) | .build/yarnlockhash"
      path: .build/node_modules_cache
      cacheHitVar: NODE_MODULES_RESTORED
    displayName: Restore node_modules cache

  # Cache built-in extensions to avoid GH rate limits.
  - task: Cache@2
    inputs:
      key: '"builtInDeps" | .build/builtindepshash'
      path: .build/builtInExtensions
    displayName: Restore built-in extensions

  - script: |
      set -e
      tar -xzf .build/node_modules_cache/cache.tgz
    condition: and(succeeded(), eq(variables.NODE_MODULES_RESTORED, 'true'))
    displayName: Extract node_modules cache

  - script: |
      set -e
      npx https://aka.ms/enablesecurefeed standAlone
    timeoutInMinutes: 5
    retryCountOnTaskFailure: 3
    condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'), eq(variables['ENABLE_TERRAPIN'], 'true'))
    displayName: Switch to Terrapin packages

  - script: |
      set -e
      sudo apt update -y
      sudo apt install -y build-essential pkg-config libx11-dev libx11-xcb-dev libxkbfile-dev libsecret-1-dev libnotify-bin
    displayName: Install build tools
    condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))

  - script: |
      set -e
      for i in {1..3}; do # try 3 times, for Terrapin
        yarn --frozen-lockfile --check-files && break
        if [ $i -eq 3 ]; then
          echo "Yarn failed too many times" >&2
          exit 1
        fi
        echo "Yarn failed $i, trying again..."
      done
    env:
      ELECTRON_SKIP_BINARY_DOWNLOAD: 1
      PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
      GITHUB_TOKEN: "$(github-distro-mixin-password)"
    displayName: Install dependencies
    condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))

  - script: |
      set -e
      node build/lib/builtInExtensions.js
    env:
      GITHUB_TOKEN: "$(github-<PASSWORD>ro-mixin-password)"
    displayName: Download missing built-in extensions

  - script: |
      set -e
      node build/azure-pipelines/common/listNodeModules.js .build/node_modules_list.txt
      mkdir -p .build/node_modules_cache
      tar -czf .build/node_modules_cache/cache.tgz --files-from .build/node_modules_list.txt
    condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'))
    displayName: Create node_modules archive

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    # Mixin must run before optimize, because the CSS loader will inline small SVGs
    - script: |
        set -e
        node build/azure-pipelines/mixin
      displayName: Mix in quality

  - script: |
      set -e
      yarn npm-run-all -lp core-ci extensions-ci hygiene eslint valid-layers-check vscode-dts-compile-check tsec-compile-check
    env:
      GITHUB_TOKEN: "$(github-<PASSWORD>)"
    displayName: Compile & Hygiene

  - ${{ if eq(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        yarn --cwd build compile
        ./.github/workflows/check-clean-git-state.sh
      displayName: Check /build/ folder

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - script: |
        set -e
        yarn --cwd test/smoke compile
        yarn --cwd test/integration/browser compile
      displayName: Compile test suites
      condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
    - task: AzureCLI@2
      inputs:
        azureSubscription: "vscode-builds-subscription"
        scriptType: pscore
        scriptLocation: inlineScript
        addSpnToEnvironment: true
        inlineScript: |
          Write-Host "##vso[task.setvariable variable=AZURE_TENANT_ID]$env:tenantId"
          Write-Host "##vso[task.setvariable variable=AZURE_CLIENT_ID]$env:servicePrincipalId"
          Write-Host "##vso[task.setvariable variable=AZURE_CLIENT_SECRET;issecret=true]$env:servicePrincipalKey"
{'fraction_non_alphanumeric': 0.11163398692810457, 'fraction_numerical': 0.004357298474945534, 'mean_word_length': 2.8458445040214477, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 18, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4926660', 'n_tokens_mistral': 3856, 'n_tokens_neox': 3747, 'n_words': 846}