Skip to content

Commit

Permalink
Support Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v committed Dec 15, 2020
1 parent 32cad98 commit 30a5e54
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
36 changes: 34 additions & 2 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pipeline {
}
axis {
name 'PLATFORM'
values 'ubuntu-18 && immutable' // TODO: support windows, 'windows-2019 && immutable'
values 'ubuntu-18 && immutable', 'windows-2019 && immutable'
}
}
stages {
Expand All @@ -55,7 +55,15 @@ pipeline {
deleteDir()
unstash 'source'
dir("${BASE_DIR}"){
sh(label: "test for ${GO_VERSION} in ${PLATFORM}", script: '.ci/scripts/test.sh')
whenTrue(isUnix()) {
sh(label: "go test for ${GO_VERSION} in ${PLATFORM}", script: '.ci/scripts/test.sh')
}
whenFalse(isUnix()) {
retryWithSleep(retries: 2, seconds: 5, backoff: true){
bat(label: "Install Go/Mage ${GO_VERSION}", script: ".ci/scripts/install-tools.bat")
}
bat(label: "go test for ${GO_VERSION} in ${PLATFORM}", script: '.ci/scripts/test.bat')
}
}
}
}
Expand All @@ -76,3 +84,27 @@ pipeline {
}
}
}

def withGoEnvMultiplatform(Map args = [:], Closure body) {
if(isUnix()) {
withGoEnv(version: "${args.version}"){
body()
}
} else {
def mingwArch = is32() ? '32' : '64'
def goArch = is32() ? '386' : 'amd64'
def chocoPath = 'C:\\ProgramData\\chocolatey\\bin'
def userProfile="${env.WORKSPACE}"
def goRoot = "${userProfile}\\.gvm\\versions\\go${args.version}.windows.${goArch}"
def path = "${env.WORKSPACE}\\bin;${goRoot}\\bin;${chocoPath};C:\\tools\\mingw${mingwArch}\\bin;${env.PATH}"
withEnv([
"GOPATH=${env.WORKSPACE}",
"GOROOT=${goRoot}",
"HOME=${env.WORKSPACE}",
"PATH=${path}",
"USERPROFILE=${userProfile}"
]) {
body()
}
}
}
53 changes: 53 additions & 0 deletions .ci/scripts/install-tools.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
where /q curl
IF ERRORLEVEL 1 (
choco install curl -y --no-progress --skipdownloadcache
IF ERRORLEVEL 1 (
REM curl installation has failed.
exit /b 1
)
)
mkdir %WORKSPACE%\bin

IF EXIST "%PROGRAMFILES(X86)%" (
REM Force the gvm installation.
SET GVM_BIN=gvm.exe
curl -L -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.2.4/gvm-windows-amd64.exe
IF ERRORLEVEL 1 (
REM gvm installation has failed.
exit /b 1
)
) ELSE (
REM Windows 7 workers got a broken gvm installation.
curl -L -o %WORKSPACE%\bin\gvm.exe https://github.com/andrewkroh/gvm/releases/download/v0.2.4/gvm-windows-386.exe
IF ERRORLEVEL 1 (
REM gvm installation has failed.
exit /b 1
)
)

SET GVM_BIN=gvm.exe
WHERE /q %GVM_BIN%
%GVM_BIN% version

REM Install the given go version
%GVM_BIN% --debug install %GO_VERSION%

REM Configure the given go version
FOR /f "tokens=*" %%i IN ('"%GVM_BIN%" use %GO_VERSION% --format=batch') DO %%i

go env
IF ERRORLEVEL 1 (
REM go is not configured correctly.
exit /b 1
)

where /q gcc
IF ERRORLEVEL 1 (
REM Install mingw 5.3.0
choco install mingw -y -r --no-progress --version 5.3.0
IF NOT ERRORLEVEL 0 (
exit /b 1
)
)
gcc --version
where gcc
11 changes: 11 additions & 0 deletions .ci/scripts/test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
GO111MODULE=off go get -u github.com/elastic/go-licenser
go mod verify
go-licenser -d
go run .ci/scripts/check_format.go
go run .ci/scripts/check_lint.go

mkdir -p build
SET OUT_FILE=build\output-report.out
go test "./..." -v > %OUT_FILE% | type %OUT_FILE%
go get -v -u github.com/jstemmer/go-junit-report
go-junit-report > build\junit-%GO_VERSION%.xml < %OUT_FILE%

0 comments on commit 30a5e54

Please sign in to comment.