<commit_before># Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

name: $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

trigger: none # disable triggers based on commits.
pr: none # disable triggers based on pull requests.

resources:
  repositories:
  - repository: msgraph-sdk-java # The name used to reference this repository in the checkout step
    type: github
    endpoint: microsoftgraph
    name: microsoftgraph/msgraph-sdk-java
    ref: dev # checkout the dev branch
  - repository: msgraph-metadata
    type: github
    endpoint: microsoftgraph
    name: microsoftgraph/msgraph-metadata
    ref: master # 
  pipelines:
  - pipeline: publishMetadata # This pipeline validates and produces an metadata artifact that we use for generation.
    source: (v1.0 - 3) msgraph-publish-cleanmetadata
    trigger:
      branches:
      - master

pool:
  vmImage: windows-latest # Info about this image: [0][1]

variables:
  - group: MicrosoftGraph # Variable group, where variables not set here come from. Set in Azure DevOps

steps:
- checkout: msgraph-sdk-java
  clean: true
  fetchDepth: 1
  persistCredentials: true
- checkout: msgraph-metadata
  clean: true
  fetchDepth: 1

- task: PowerShell@2 # Setup environment variables and make them available to all tasks. See [1] for more info.
  displayName: 'Calculate and set pipeline variables for this job'
  inputs:
    targetType: inline
    script: |
      $repoDir = "$env:Build_SourcesDirectory\msgraph-sdk-java\"
      Write-Host "Path to java repository: $repoDir"
      Write-Host "##vso[task.setvariable variable=repoDir]$repoDir"

      $outputPath = Join-Path $env:Build_SourcesDirectory "output"
      Write-Host "Path to typewriter.exe output $outputPath"
      Write-Host "##vso[task.setvariable variable=outputPath]$outputPath"

      $cleanMetadata = "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/clean_v10_metadata/cleanMetadataWithDescriptionsv1.0.xml"
      Write-Host "Path to clean metadata $cleanMetadata"
      Write-Host "##vso[task.setvariable variable=cleanMetadata]$cleanMetadata"

      $branchName = "v1.0/pipelinebuild/$env:Build_BuildId" # Match the spec in the GH Action
      Write-Host "Branch path spec for the pull request will be $branchName"
      Write-Host "##vso[task.setvariable variable=branchName]$branchName"

- task: PowerShell@2
  displayName: 'Git: branch from dev named with the build id: $(Build.BuildId)'
  inputs:
    targetType: inline
    workingDirectory: '$(Build.SourcesDirectory)/msgraph-sdk-java'
    script: |
      Write-Host "The new branch name will be: $env:branchName"
      git checkout -B $env:branchName | Write-Host

- task: PowerShell@2
  displayName: 'Git: set user config'
  inputs:
    targetType: inline
    workingDirectory: '$(Build.SourcesDirectory)/msgraph-sdk-java'
    script: |
      git config user.email "<EMAIL>"
      git config user.name "Microsoft Graph DevX Tooling"

- task: PowerShell@2
  displayName: 'Remove generated models and requests from the repo'
  inputs:
    targetType: inline
    script: |
      $mainDir = Join-Path $env:repoDir "\src\main\"
      $extensionsAndGeneratedDirectories = Get-ChildItem $mainDir -Include extensions,generated -Recurse -Directory

      # this list should be updated if a new hand-crafted extension is added to one of the extensions/ directories
      $filesThatShouldNotBeDeleted = "UploadSession.java","DateOnly.java","TimeOfDay.java","Multipart.java","ChunkedUploadRequest.java","ChunkedUploadResult.java","CustomRequestBuilder.java"
      foreach ($directory in $extensionsAndGeneratedDirectories)
      {
          Remove-Item $directory.FullName -Recurse -Force -Exclude $filesThatShouldNotBeDeleted
      }
      Write-Host "Removed the existing generated files in the repo's main directory: $mainDir" -ForegroundColor Green
  enabled: true # The old GUI pipeline wasn't doing this. I recall that there was a reason
  # for this but I can't recall the reason but I think it was related to reducing number of
  # generated files.

- task: PowerShell@2
  displayName: 'Typewriter: generate v1.0 Java files'
  inputs:
    targetType: filePath
    filePath: '$(Build.SourcesDirectory)/msgraph-metadata/scripts/runTypewriter.ps1'
    arguments: '-verbosity Info -language Java -metadata $(cleanMetadata) -output $(outputPath) -generationMode Files'
    workingDirectory: '$(Build.SourcesDirectory)' # Set the root for a multi-repo pipeline. /s
  enabled: true

- task: PowerShell@2
  displayName: 'Copy generated requests and models into the repo'
  inputs:
    targetType: inline<commit_msg>- adds step to automatically increment version number with code gen PRs<commit_after># Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

name: $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

trigger: none # disable triggers based on commits.
pr: none # disable triggers based on pull requests.

resources:
  repositories:
  - repository: msgraph-sdk-java # The name used to reference this repository in the checkout step
    type: github
    endpoint: microsoftgraph
    name: microsoftgraph/msgraph-sdk-java
    ref: dev # checkout the dev branch
  - repository: msgraph-metadata
    type: github
    endpoint: microsoftgraph
    name: microsoftgraph/msgraph-metadata
    ref: master # 
  pipelines:
  - pipeline: publishMetadata # This pipeline validates and produces an metadata artifact that we use for generation.
    source: (v1.0 - 3) msgraph-publish-cleanmetadata
    trigger:
      branches:
      - master

pool:
  vmImage: windows-latest # Info about this image: [0][1]

variables:
  - group: MicrosoftGraph # Variable group, where variables not set here come from. Set in Azure DevOps

steps:
- checkout: msgraph-sdk-java
  clean: true
  fetchDepth: 1
  persistCredentials: true
- checkout: msgraph-metadata
  clean: true
  fetchDepth: 1

- task: PowerShell@2 # Setup environment variables and make them available to all tasks. See [1] for more info.
  displayName: 'Calculate and set pipeline variables for this job'
  inputs:
    targetType: inline
    script: |
      $repoDir = "$env:Build_SourcesDirectory\msgraph-sdk-java\"
      Write-Host "Path to java repository: $repoDir"
      Write-Host "##vso[task.setvariable variable=repoDir]$repoDir"

      $outputPath = Join-Path $env:Build_SourcesDirectory "output"
      Write-Host "Path to typewriter.exe output $outputPath"
      Write-Host "##vso[task.setvariable variable=outputPath]$outputPath"

      $cleanMetadata = "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/clean_v10_metadata/cleanMetadataWithDescriptionsv1.0.xml"
      Write-Host "Path to clean metadata $cleanMetadata"
      Write-Host "##vso[task.setvariable variable=cleanMetadata]$cleanMetadata"

      $branchName = "v1.0/pipelinebuild/$env:Build_BuildId" # Match the spec in the GH Action
      Write-Host "Branch path spec for the pull request will be $branchName"
      Write-Host "##vso[task.setvariable variable=branchName]$branchName"

- task: PowerShell@2
  displayName: 'Git: branch from dev named with the build id: $(Build.BuildId)'
  inputs:
    targetType: inline
    workingDirectory: '$(Build.SourcesDirectory)/msgraph-sdk-java'
    script: |
      Write-Host "The new branch name will be: $env:branchName"
      git checkout -B $env:branchName | Write-Host

- task: PowerShell@2
  displayName: 'Git: set user config'
  inputs:
    targetType: inline
    workingDirectory: '$(Build.SourcesDirectory)/msgraph-sdk-java'
    script: |
      git config user.email "<EMAIL>"
      git config user.name "Microsoft Graph DevX Tooling"

- task: PowerShell@2
  displayName: 'Remove generated models and requests from the repo'
  inputs:
    targetType: inline
    script: |
      $mainDir = Join-Path $env:repoDir "\src\main\"
      $extensionsAndGeneratedDirectories = Get-ChildItem $mainDir -Include extensions,generated -Recurse -Directory

      # this list should be updated if a new hand-crafted extension is added to one of the extensions/ directories
      $filesThatShouldNotBeDeleted = "UploadSession.java","DateOnly.java","TimeOfDay.java","Multipart.java","ChunkedUploadRequest.java","ChunkedUploadResult.java","CustomRequestBuilder.java"
      foreach ($directory in $extensionsAndGeneratedDirectories)
      {
          Remove-Item $directory.FullName -Recurse -Force -Exclude $filesThatShouldNotBeDeleted
      }
      Write-Host "Removed the existing generated files in the repo's main directory: $mainDir" -ForegroundColor Green
  enabled: true # The old GUI pipeline wasn't doing this. I recall that there was a reason
  # for this but I can't recall the reason but I think it was related to reducing number of
  # generated files.

- task: PowerShell@2
  displayName: 'Typewriter: generate v1.0 Java files'
  inputs:
    targetType: filePath
    filePath: '$(Build.SourcesDirectory)/msgraph-metadata/scripts/runTypewriter.ps1'
    arguments: '-verbosity Info -language Java -metadata $(cleanMetadata) -output $(outputPath) -generationMode Files'
    workingDirectory: '$(Build.SourcesDirectory)' # Set the root for a multi-repo pipeline. /s
  enabled: true

- task: PowerShell@2
  displayName: 'Increment minor version number'
  inputs:
    targetType: filePath
    filePath: '$(Build.SourcesDirectory)/msgraph-sdk-java/Scripts/incrementMinorVersion.ps1'
    workingDirectory: '$(Build.SourcesDirectory)/msgraph-sdk-java/Scripts'
  enabled: true

- task: PowerShell@2
  displayName: 'Copy generated requests and models into the repo'
  inputs:
    targetType: inline
{'fraction_non_alphanumeric': 0.09165032511095056, 'fraction_numerical': 0.004954071627618949, 'mean_word_length': 3.9948453608247423, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1446226', 'n_tokens_mistral': 2765, 'n_tokens_neox': 2701, 'n_words': 884}