$ErrorActionPreference = "Stop"

$projectDir = if ($env:CI_PROJECT_DIR) { $env:CI_PROJECT_DIR } else { (Get-Location).Path }
$platformVer = $env:PLATFORM_VER

if (-not $platformVer) {
  throw "PLATFORM_VER must be set"
}

$artifactDir = Join-Path $projectDir "data/windows/$platformVer"
New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null

$artifacts = Get-ChildItem -Path (Join-Path $projectDir "data") -Filter "cinc-workstation*" -ErrorAction SilentlyContinue
if ($artifacts) {
  foreach ($artifact in $artifacts) {
    Move-Item -Force -Path $artifact.FullName -Destination $artifactDir
  }
} else {
  Write-Host "No Windows artifacts found to move"
}

rm.exe -rf C:\cinc-project\cinc-workstation C:\omnibus-ruby\src C:\omnibus-ruby\pkg
rm.exe -rf C:\omnibus-ruby\build C:\omnibus-ruby\cache
