test-windows.ps1 5.85 KB
Newer Older
1
function Check-Output {
2
3
4
  param( [bool]$success )
  if (!$success) {
    $host.SetShouldExit(-1)
5
    exit 1
6
7
8
  }
}

9
$env:CONDA_ENV = "test-env"
10
$env:LGB_VER = (Get-Content $env:BUILD_SOURCESDIRECTORY\VERSION.txt).trim()
11
12
13
14
15
16
17
# Use custom temp directory to avoid
# > warning MSB8029: The Intermediate directory or Output directory cannot reside under the Temporary directory
# > as it could lead to issues with incremental build.
# And make sure this directory is always clean
$env:TMPDIR = "$env:USERPROFILE\tmp"
Remove-Item $env:TMPDIR -Force -Recurse -ErrorAction Ignore
[Void][System.IO.Directory]::CreateDirectory($env:TMPDIR)
18

19
if ($env:TASK -eq "r-package") {
20
  & .\.ci\test-r-package-windows.ps1 ; Check-Output $?
21
22
23
  Exit 0
}

24
if ($env:TASK -eq "cpp-tests") {
25
26
27
  cmake -B build -S . -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF -DUSE_DEBUG=ON -A x64
  cmake --build build --target testlightgbm --config Debug ; Check-Output $?
  .\Debug\testlightgbm.exe ; Check-Output $?
28
29
30
  Exit 0
}

31
if ($env:TASK -eq "swig") {
32
  $env:JAVA_HOME = $env:JAVA_HOME_8_X64  # there is pre-installed Eclipse Temurin 8 somewhere
33
34
35
36
  $ProgressPreference = "SilentlyContinue"  # progress bar bug extremely slows down download speed
  Invoke-WebRequest -Uri "https://github.com/microsoft/LightGBM/releases/download/v2.0.12/swigwin-4.0.2.zip" -OutFile $env:BUILD_SOURCESDIRECTORY/swig/swigwin.zip -UserAgent "NativeHost"
  Add-Type -AssemblyName System.IO.Compression.FileSystem
  [System.IO.Compression.ZipFile]::ExtractToDirectory("$env:BUILD_SOURCESDIRECTORY/swig/swigwin.zip", "$env:BUILD_SOURCESDIRECTORY/swig")
37
  $env:PATH = "$env:BUILD_SOURCESDIRECTORY/swig/swigwin-4.0.2;" + $env:PATH
38
39
  cmake -B build -S . -A x64 -DUSE_SWIG=ON ; Check-Output $?
  cmake --build build --target ALL_BUILD --config Release ; Check-Output $?
40
  if ($env:AZURE -eq "true") {
41
    cp ./build/lightgbmlib.jar $env:BUILD_ARTIFACTSTAGINGDIRECTORY/lightgbmlib_win.jar ; Check-Output $?
42
43
44
45
  }
  Exit 0
}

46
47
48
49
# setup for Python
conda init powershell
conda activate
conda config --set always_yes yes --set changeps1 no
50
conda update -q -y conda "python=$env:PYTHON_VERSION[build=*cpython]"
51
52
53

if ($env:PYTHON_VERSION -eq "3.7") {
  $env:CONDA_REQUIREMENT_FILE = "$env:BUILD_SOURCESDIRECTORY/.ci/conda-envs/ci-core-py37.txt"
54
55
} elseif ($env:PYTHON_VERSION -eq "3.8") {
  $env:CONDA_REQUIREMENT_FILE = "$env:BUILD_SOURCESDIRECTORY/.ci/conda-envs/ci-core-py38.txt"
56
57
58
59
60
61
62
63
64
} else {
  $env:CONDA_REQUIREMENT_FILE = "$env:BUILD_SOURCESDIRECTORY/.ci/conda-envs/ci-core.txt"
}

conda create `
  -y `
  -n $env:CONDA_ENV `
  --file $env:CONDA_REQUIREMENT_FILE `
  "python=$env:PYTHON_VERSION[build=*cpython]" ; Check-Output $?
65
66
67
68

if ($env:TASK -ne "bdist") {
  conda activate $env:CONDA_ENV
}
69

70
cd $env:BUILD_SOURCESDIRECTORY
71
if ($env:TASK -eq "regular") {
72
73
  cmake -B build -S . -A x64 ; Check-Output $?
  cmake --build build --target ALL_BUILD --config Release ; Check-Output $?
74
75
76
  sh ./build-python.sh install --precompile ; Check-Output $?
  cp ./Release/lib_lightgbm.dll $env:BUILD_ARTIFACTSTAGINGDIRECTORY
  cp ./Release/lightgbm.exe $env:BUILD_ARTIFACTSTAGINGDIRECTORY
77
78
}
elseif ($env:TASK -eq "sdist") {
79
  sh ./build-python.sh sdist ; Check-Output $?
80
  sh ./.ci/check-python-dists.sh ./dist ; Check-Output $?
81
  cd dist; pip install @(Get-ChildItem *.gz) -v ; Check-Output $?
82
83
}
elseif ($env:TASK -eq "bdist") {
84
  # Import the Chocolatey profile module so that the RefreshEnv command
Andrew Ziem's avatar
Andrew Ziem committed
85
  # invoked below properly updates the current PowerShell session environment.
86
87
  $module = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
  Import-Module "$module" ; Check-Output $?
88
  RefreshEnv
89

90
91
92
93
  Write-Output "Current OpenCL drivers:"
  Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors

  conda activate $env:CONDA_ENV
94
  sh "build-python.sh" bdist_wheel --integrated-opencl ; Check-Output $?
95
  sh ./.ci/check-python-dists.sh ./dist ; Check-Output $?
96
  cd dist; pip install @(Get-ChildItem *py3-none-win_amd64.whl) ; Check-Output $?
97
  cp @(Get-ChildItem *py3-none-win_amd64.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY
98
99
} elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) {
  if ($env:COMPILER -eq "MINGW") {
100
    sh ./build-python.sh install --mingw ; Check-Output $?
101
  } else {
102
    sh ./build-python.sh install; Check-Output $?
103
  }
104
105
}

106
if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) {
107
  # cannot test C API with "sdist" task
108
  $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test"
109
} else {
110
  $tests = $env:BUILD_SOURCESDIRECTORY + "/tests"
111
112
}
if ($env:TASK -eq "bdist") {
113
114
  # Make sure we can do both CPU and GPU; see tests/python_package_test/test_dual.py
  $env:LIGHTGBM_TEST_DUAL_CPU_GPU = "1"
115
}
116

117
pytest $tests ; Check-Output $?
118

119
if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) {
120
121
  cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide
  @("import matplotlib", "matplotlib.use('Agg')") + (Get-Content "plot_example.py") | Set-Content "plot_example.py"
122
  (Get-Content "plot_example.py").replace('graph.render(view=True)', 'graph.render(view=False)') | Set-Content "plot_example.py"  # prevent interactive window mode
123
  conda install -y -n $env:CONDA_ENV "h5py>=3.10" "ipywidgets>=8.1.2" "notebook>=7.1.2"
124
  foreach ($file in @(Get-ChildItem *.py)) {
125
126
    @("import sys, warnings", "warnings.showwarning = lambda message, category, filename, lineno, file=None, line=None: sys.stdout.write(warnings.formatwarning(message, category, filename, lineno, line))") + (Get-Content $file) | Set-Content $file
    python $file ; Check-Output $?
127
  }  # run all examples
128
  cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide/notebooks
129
  (Get-Content "interactive_plot_example.ipynb").replace('INTERACTIVE = False', 'assert False, \"Interactive mode disabled\"') | Set-Content "interactive_plot_example.ipynb"
130
  jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb ; Check-Output $?  # run all notebooks
131
}