buildkite / golang-example

An example on how to test a Golang program using Buildkite
https://github.com/buildkite/example-pipelines
MIT License
12 stars 15 forks source link

windows support #1

Open pquerna opened 8 years ago

pquerna commented 8 years ago

the default bootstrap.bat on windows doesn't seem to have the same level of hook support, but my script/test.ps1 i made a terrible function to munge the GOPATH and symlinks in a similar manner to this repository:

function MungeGOPATH() {
    if (!(Test-Path env:BUILDKTE_GOLANG_IMPORT_PATH)) {
        throw "env:BUILDKTE_GOLANG_IMPORT_PATH must be set"
    }

    $RepoPath = Split-Path $PSScriptRoot -Parent
    $RootPath = Split-Path $RepoPath -Parent
    $NewGoPath = Join-Path $RootPath -ChildPath "tmp"
    $NewBuildPath = Join-Path $NewGoPath -ChildPath "src/$($env:BUILDKTE_GOLANG_IMPORT_PATH)"
    $NewBuildPathParent = (Split-Path "$($NewBuildPath)" -Parent)

    $NewGoBin = Join-Path $NewGoPath -ChildPath "bin"
    $NewGoSrc = Join-Path $NewGoPath -ChildPath "src"

    echo "Creating GOPATH/bin: $($NewGoBin)"
    New-Item -force -path $NewGoBin -type directory
    echo "Creating GOPATH/src: $($NewGoSrc)"
    New-Item -force -path $NewGoSrc -type directory

    echo "Creating GOPATH/src/(build_root): $($NewBuildPathParent)"
    New-Item -force -path $NewBuildPathParent -type directory

    echo "Creating symlink $($NewBuildPath) -> $($RepoPath)"
    New-Item -force -ItemType SymbolicLink -path "$($NewBuildPath)" -value "$($RepoPath)"

    echo "New GOPATH is set to: $($NewGoPath)"
    echo "Build will now be at: $($NewBuildPath)"
    $env:GOPATH = $NewGoPath
    $env:BUILDKITE_BUILD_CHECKOUT_PATH=$NewBuildPath
    $env:Path = $env:Path + ";" + $NewGoBin
    echo "New added GOPATH/bin to PATH: $($env:Path)"

    Set-Location -Path "$($env:BUILDKITE_BUILD_CHECKOUT_PATH)"
}

MungeGOPATH

Note this requires PowerShell 5.0 (for New-Item with a SymbolicLink), and must be run under an Administrator account or a system where symlinks are allowed for other users.

keithpitt commented 8 years ago

@pquerna sorry about the Windows problems, and thanks for sharing that snippet! I'll try and find some time in the next few weeks getting this example working with Windows out of the box.

jmccarthy commented 6 years ago

Here's an example workaround for insufficient GOPATH symlink following on Windows:

REM ==== Create temp GOPATH based on project contents
mkdir tmp\go\bin
mkdir tmp\go\src\github.com\xxx\yyy
robocopy . tmp\go\src\github.com\xxx\yyy *.go /s /njh /njs /ndl /nc /ns /np /xd tmp
robocopy . tmp\go\src\github.com\xxx\yyy *.s /s /njh /njs /ndl /nc /ns /np /xd tmp
set GOPATH=%cd%\tmp\go
ghost commented 5 years ago

You should see how its done here ! https://github.com/elastic/beats

Mage is used for cross platform scripting throughout. https://github.com/elastic/beats/blob/master/magefile.go

TO kick it off from windows a generic kicker is used: https://github.com/elastic/beats/blob/master/make.bat

TO kick it off for Linux 7 Darwin its just Makefile: https://github.com/elastic/beats/blob/master/Makefile

Mage is really awesome for Cross device CI things..