diff --git a/containers/agent-windows-buildkite/Dockerfile b/containers/agent-windows-buildkite/Dockerfile index ba34174..ce9ab02 100644 --- a/containers/agent-windows-buildkite/Dockerfile +++ b/containers/agent-windows-buildkite/Dockerfile @@ -114,7 +114,8 @@ RUN git config --system core.longpaths true & ` git config --global core.autocrlf false RUN choco install -y handle -COPY start_agent.ps1 C:\scripts\ +COPY start_agent.ps1 c:\scripts\ +COPY pre-checkout.ps1 c:\scripts\ COPY pre-checkout.bat c:\buildkite-agent\hooks\ COPY post-checkout.bat c:\buildkite-agent\hooks\ CMD "powershell C:\scripts\start_agent.ps1" diff --git a/containers/agent-windows-buildkite/pre-checkout.bat b/containers/agent-windows-buildkite/pre-checkout.bat index ff6f06e..fad618c 100644 --- a/containers/agent-windows-buildkite/pre-checkout.bat +++ b/containers/agent-windows-buildkite/pre-checkout.bat @@ -1,5 +1,2 @@ -echo "pre-checkout: update scripts" -cd c:\llvm-premerge-checks -git pull -git rev-parse HEAD -powershell c:\llvm-premerge-checks\scripts\windows\pre-checkout.ps1 \ No newline at end of file +REM TODO: use powershell shell for hooks directly +powershell c:\scripts\pre-checkout.ps1 \ No newline at end of file diff --git a/containers/agent-windows-buildkite/pre-checkout.ps1 b/containers/agent-windows-buildkite/pre-checkout.ps1 new file mode 100644 index 0000000..fcb4da8 --- /dev/null +++ b/containers/agent-windows-buildkite/pre-checkout.ps1 @@ -0,0 +1,28 @@ +$srcDirectory = "c:\src" +$env:BUILDKITE_BUILD_CHECKOUT_PATH=$srcDirectory + +echo "unlocking git" +taskkill /F /IM git.exe +rm -Force "$env:BUILDKITE_BUILD_CHECKOUT_PATH/.git/index.lock" +echo "BUILDKITE_BUILD_CHECKOUT_PATH: $env:BUILDKITE_BUILD_CHECKOUT_PATH" +echo "BUILDKITE_BUILD_PATH: $env:BUILDKITE_BUILD_PATH" +echo 'running processes (before)' +Get-Process | Where-Object {$_.Path -like "$env:BUILDKITE_BUILD_PATH*"} | Select-Object -ExpandProperty Path +echo "unlocking $env:BUILDKITE_BUILD_PATH" +handle -nobanner $env:BUILDKITE_BUILD_CHECKOUT_PATH +c:\llvm-premerge-checks\scripts\windows\unlock_path.ps1 $env:BUILDKITE_BUILD_CHECKOUT_PATH +echo 'running processes (after)' +Get-Process | Where-Object {$_.Path -like "$env:BUILDKITE_BUILD_PATH*"} | Select-Object -ExpandProperty Path + +echo "BUILDKITE_REPO: $env:BUILDKITE_REPO" +if (Test-Path -Path $env:BUILDKITE_BUILD_CHECKOUT_PATH) { + Set-Location -Path $env:BUILDKITE_BUILD_CHECKOUT_PATH + $remoteUrl = git remote get-url origin + echo "current remote URL: $remoteUrl" + if ($remoteUrl -ne $env:BUILDKITE_REPO) { + Write-Host "Remote URL does not match. Deleting and recreating the directory." + Set-Location -Path "C:\" + Remove-Item -Path $env:BUILDKITE_BUILD_CHECKOUT_PATH -Recurse -Force + } +} +