# The config is used to bake appveyor images, not for running CI jobs.
# The config expects the following environment variables to be set:
#  - "APPVEYOR_BAKE_IMAGE" e.g. 'electron-99.0.4767.0'. Name of the image to be baked.
#      Typically named after the Chromium version on which the image is built.
#      This can be set dynamically in the prepare-appveyor script.

version: 1.0.{build}
build_cloud: electronhq-16-core
image: base-bake-image
environment:
  GIT_CACHE_PATH: C:\Users\appveyor\libcc_cache
  ELECTRON_OUT_DIR: Default
  ELECTRON_ENABLE_STACK_DUMPING: 1
  MOCHA_REPORTER: mocha-multi-reporters
  MOCHA_MULTI_REPORTERS: mocha-appveyor-reporter, tap
  DEPOT_TOOLS_WIN_TOOLCHAIN: 0
  PYTHONIOENCODING: UTF-8

# The following lines are needed when baking from a completely new image (eg MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest via image: base-windows-server2019)
# init:
#   - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
#   - appveyor version
#   - ps: $ErrorActionPreference = 'Stop'
#   - ps: 'Write-Host "OS Build: $((Get-CimInstance Win32_OperatingSystem).BuildNumber)"'

# clone_folder: '%USERPROFILE%\image-bake-scripts'

# clone_script:  
#   - ps: Invoke-WebRequest "https://github.com/appveyor/build-images/archive/1f90d94e74c8243c909a09b994e527584dfcb838.zip" -OutFile "$env:temp\scripts.zip"
#   - ps: Expand-Archive -Path "$env:temp\scripts.zip" -DestinationPath "$env:temp\scripts" -Force
#   - ps: Copy-Item -Path "$env:temp\scripts\build-images-1f90d94e74c8243c909a09b994e527584dfcb838\scripts\Windows\*" -Destination $env:APPVEYOR_BUILD_FOLDER -Recurse  

build_script:
# The following lines are needed when baking from a completely new image (eg MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest via image: base-windows-server2019)
  # - ps: .\init_server.ps1
  # - ps: .\extend_system_volume.ps1

  # # Restart VM
  # - ps: Start-Sleep -s 5; Restart-Computer
  # - ps: Start-Sleep -s 5

  # - appveyor version
  # - ps: .\install_path_utils.ps1
  # - ps: .\install_powershell_core.ps1
  # - ps: .\install_powershell_get.ps1
  # - ps: .\install_7zip.ps1
  # - ps: .\install_chocolatey.ps1
  # - ps: .\install_webpi.ps1
  # - ps: .\install_nuget.ps1
  # - ps: .\install_pstools.ps1

  # - ps: .\install_git.ps1
  # - ps: .\install_git_lfs.ps1

  # # Restart VM
  # - ps: Start-Sleep -s 5; Restart-Computer
  # - ps: Start-Sleep -s 5
# END LINES FOR COMPLETELY NEW IMAGE

  - git config --global core.longpaths true
  - ps: >-
      if (-not (Test-Path -Path C:\projects\src)) {
        New-Item -Path C:\projects\src -ItemType Directory
      }
  - cd C:\projects\
  - git clone -q --branch=%APPVEYOR_REPO_BRANCH% https://github.com/electron/electron.git C:\projects\src\electron
  - git clone --depth=1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
  - ps: $env:PATH="$pwd\depot_tools;$env:PATH"
  - update_depot_tools.bat
  # Uncomment the following line if windows deps change
  # - src\electron\script\setup-win-for-dev.bat
  - >-
      gclient config
      --name "src\electron"
      --unmanaged
      %GCLIENT_EXTRA_ARGS%
      "https://github.com/electron/electron"
  - ps: cd src\electron
  - ps: node script\generate-deps-hash.js
  - ps: $depshash = Get-Content .\.depshash -Raw
  - ps: Copy-Item -path .\.depshash -destination ..\.depshash
  - ps: cd ..\..
  - gclient sync --with_branch_heads --with_tags --nohooks
  - ps: regsvr32 /s "C:\Program Files\Microsoft Visual Studio\2022\Community\DIA SDK\bin\amd64\msdia140.dll"
  - ps: set vs2022_install="C:\Program Files\Microsoft Visual Studio\2022\Community"

# The following lines are needed when baking from a completely new image (eg MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest via image: base-windows-server2019)
  # # Restart VM
  # - ps: Start-Sleep -s 5; Restart-Computer 
  # - ps: Start-Sleep -s 5

  # - cd %USERPROFILE%\image-bake-scripts
  # - appveyor version
  # - ps: .\optimize_dotnet_runtime.ps1
  # - ps: .\disable_windows_background_services.ps1
  # - ps: .\enforce_windows_firewall.ps1
  # - ps: .\cleanup_windows.ps1  
# END LINES FOR COMPLETELY NEW IMAGE  
on_image_bake:
  - ps: >-
      echo "Baking image: $env:APPVEYOR_BAKE_IMAGE at dir $PWD"
  - ps: Remove-Item -Recurse -Force C:\projects\depot_tools
  - ps: Remove-Item -Recurse -Force C:\projects\src\electron
# Uncomment these lines and set APPVEYOR_RDP_PASSWORD in project settings to enable RDP after bake is done
# # on_finish:
#   - ps: >-
#        $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))