name: BuildKiteWindowsGPUBootstrap
description: Set up worker image for windows-gpu pipeline
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: SetupStep
        action: ExecutePowerShell
        inputs:
          commands:
            - |
              $ErrorActionPreference = "Stop"

              choco --version
              choco feature enable -n=allowGlobalConfirmation

              # CMake 3.29.2
              Write-Host '>>> Installing CMake 3.29.2...'
              choco install cmake --version 3.29.2 --installargs "ADD_CMAKE_TO_PATH=System"
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }

              # Notepad++
              Write-Host '>>> Installing Notepad++...'
              choco install notepadplusplus
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }

              # Mambaforge
              Write-Host '>>> Installing Mambaforge...'
              choco install mambaforge /RegisterPython:1 /D:C:\tools\mambaforge
              C:\tools\mambaforge\Scripts\conda.exe init --user --system
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }
              . "C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1"
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }
              conda config --set auto_activate_base false

              # Install Java 11
              Write-Host '>>> Installing Java 11...'
              choco install openjdk11
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }

              # Install Maven
              Write-Host '>>> Installing Maven...'
              choco install maven
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }

              # Install GraphViz
              Write-Host '>>> Installing GraphViz...'
              choco install graphviz
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }

              # Install Visual Studio 2022 Community
              Write-Host '>>> Installing Visual Studio 2022 Community...'
              choco install visualstudio2022community `
                  --params "--wait --passive --norestart"
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }
              choco install visualstudio2022-workload-nativedesktop --params `
                  "--wait --passive --norestart --includeOptional"
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }

              # Install CUDA 12.4
              Write-Host '>>> Installing CUDA 12.4...'
              choco install cuda --version=12.4.1.551
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }

              # Install R
              Write-Host '>>> Installing R...'
              choco install r.project --version=4.3.2
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }
              choco install rtools --version=4.3.5550
              if ($LASTEXITCODE -ne 0) { throw "Last command failed" }
