. ./exiter.ps1
. C:\var\vcap\packages\golang-1.27-windows\bosh\compile.ps1
$env:CGO_ENABLED="0"

$ErrorActionPreference = "Stop";
trap { $host.SetShouldExit(1) }

$BOSH_INSTALL_TARGET = Resolve-Path "${env:BOSH_INSTALL_TARGET}"
if ((Get-Item $BOSH_INSTALL_TARGET).LinkType -ne "") {
  $BOSH_INSTALL_TARGET = (Get-Item $BOSH_INSTALL_TARGET).Target
}

Push-Location otel-collector-builder\
  go.exe run go.opentelemetry.io\collector\cmd\builder --config=config.yaml --skip-generate --skip-get-modules
  if ($LASTEXITCODE -ne 0) {
    Write-Error "Error building otel-collector"
  }
Pop-Location

Copy-Item "otel-collector\otelcol-cf" -Destination "${env:BOSH_INSTALL_TARGET}\otel-collector.exe"

Exit 0
