branches:
  only:
    - master
environment:
  source: '%TEMP%/source'
  files: '%TEMP%/files'
  tool: '%TEMP%/tool'
  github_access_token:
    secure: JSOJKfdgXW09TdfN75l84f7+22GElWNgPo1Vab449RFYe8+BEbO/btueR3g0qldG
before_build:
  - git clone -q --branch=master https://github.com/Visual-Studio-China/azure-xplat-cli-preprocessor %TEMP%/preprocessor
  - ps: |
      $solution = (ls -r $env:TEMP/preprocessor *.sln | select -first 1).FullName
      nuget restore $solution
      msbuild $solution /p:configuration=release /p:outputpath=$env:tool
  - git clone -q --branch=master https://github.com/Visual-Studio-China/ci-scripts %TEMP%/ci-scripts
build_script:
  - ps: |
      npm install -g azure-cli --silent
      mkdir $env:source
      mkdir $env:files
      azure config mode arm
      azure help --json > $env:source/azure.arm.json
      azure config mode asm
      azure help --json > $env:source/azure.asm.json
      copy $env:APPVEYOR_BUILD_FOLDER/lib/plugins.arm.json $env:source
      copy $env:APPVEYOR_BUILD_FOLDER/lib/plugins.asm.json $env:source
      $files_generator = (ls $env:tool *.exe).FullName
      & $files_generator arm $env:source/azure.arm.json $env:source/plugins.arm.json $env:files
      & $files_generator asm $env:source/azure.asm.json $env:source/plugins.asm.json $env:files
test: off
on_success:
  - git clone -q --branch=master %content_repo% %TEMP%\Azure
  - ps: |
      $root_folder = (ls $env:TEMP\Azure -dir | select -first 1).FullName
      ls $root_folder -dir | ? { $_.BaseName -ne 'specs' } | % { rm -r $_.FullName }
      ls $env:files -dir | % { copy $_.FullName $root_folder -recurse -force }
      ls $env:files *.yml | % { copy $_.FullName $root_folder -force }
      copy -path $env:APPVEYOR_BUILD_FOLDER\Documentation -filter *.md -destination $root_folder\Conceptual -recurse -force
      cd $env:TEMP/ci-scripts
      ./process_xplat_cli_content.ps1 $root_folder
  - cd %TEMP%\Azure
  - git config --global credential.helper store
  - git config core.safecrlf false
  - ps: ac "$env:USERPROFILE\.git-credentials" "https://$($env:github_access_token):x-oauth-basic@github.com`n"
  - git add -A
  - git diff --quiet --exit-code --cached || git commit --author="VSC CI Service <vscavu@microsoft.com>" -m "Update azure xplat cli docs." && git push origin master
