ci: win: enable powershell's strict mode

Give variables a default value to pass strict mode.
$ErrorActionPreference defines the default behavior
if a powershell command fails.
If it's set to 'stop', then it aborts the script
on the first unresolved error.
This behavior extends to native programs like cmake
but do not depend on it.

https://github.com/PowerShell/PowerShell/issues/3996
This commit is contained in:
Jan Edmund Lazo
2018-10-19 00:07:58 -04:00
parent 9929af47fe
commit 8ce3d0174e

View File

@@ -1,4 +1,5 @@
Set-PSDebug -Trace 1 $ErrorActionPreference = 'stop'
Set-PSDebug -Strict -Trace 1
$env:CONFIGURATION -match '^(?<compiler>\w+)_(?<bits>32|64)(?:-(?<option>\w+))?$' $env:CONFIGURATION -match '^(?<compiler>\w+)_(?<bits>32|64)(?:-(?<option>\w+))?$'
$compiler = $Matches.compiler $compiler = $Matches.compiler
@@ -12,6 +13,7 @@ $nvimCmakeVars = @{
CMAKE_BUILD_TYPE = $cmakeBuildType; CMAKE_BUILD_TYPE = $cmakeBuildType;
BUSTED_OUTPUT_TYPE = 'nvim'; BUSTED_OUTPUT_TYPE = 'nvim';
} }
$uploadToCodeCov = $false
# For pull requests, skip some build configurations to save time. # For pull requests, skip some build configurations to save time.
if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT -and $env:CONFIGURATION -match '^(MSVC_64|MINGW_32|MINGW_64-gcov)$') { if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT -and $env:CONFIGURATION -match '^(MSVC_64|MINGW_32|MINGW_64-gcov)$') {
@@ -20,6 +22,7 @@ if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT -and $env:CONFIGURATION -match '^(MSV
function exitIfFailed() { function exitIfFailed() {
if ($LastExitCode -ne 0) { if ($LastExitCode -ne 0) {
Set-PSDebug -Off
exit $LastExitCode exit $LastExitCode
} }
} }
@@ -72,18 +75,20 @@ python -c "import neovim; print(str(neovim))" ; exitIfFailed
python3 -c "import neovim; print(str(neovim))" ; exitIfFailed python3 -c "import neovim; print(str(neovim))" ; exitIfFailed
$env:PATH = "C:\Ruby24\bin;$env:PATH" $env:PATH = "C:\Ruby24\bin;$env:PATH"
cmd /c gem.cmd install neovim ; exitIfFailed gem.cmd install neovim
where.exe neovim-ruby-host.bat ; exitIfFailed Get-Command -CommandType Application neovim-ruby-host.bat
cmd /c npm.cmd install -g neovim ; exitIfFailed npm.cmd install -g neovim
where.exe neovim-node-host.cmd ; exitIfFailed Get-Command -CommandType Application neovim-node-host.cmd
cmd /c npm link neovim npm.cmd link neovim
function convertToCmakeArgs($vars) { function convertToCmakeArgs($vars) {
return $vars.GetEnumerator() | foreach { "-D$($_.Key)=$($_.Value)" } return $vars.GetEnumerator() | foreach { "-D$($_.Key)=$($_.Value)" }
} }
mkdir .deps if (-Not (Test-Path -PathType container .deps)) {
mkdir .deps
}
cd .deps cd .deps
cmake -G $cmakeGenerator $(convertToCmakeArgs($depsCmakeVars)) ..\third-party\ ; exitIfFailed cmake -G $cmakeGenerator $(convertToCmakeArgs($depsCmakeVars)) ..\third-party\ ; exitIfFailed
cmake --build . --config $cmakeBuildType -- $cmakeGeneratorArgs ; exitIfFailed cmake --build . --config $cmakeBuildType -- $cmakeGeneratorArgs ; exitIfFailed
@@ -104,10 +109,10 @@ Set-PSDebug -Off
cmake --build . --config $cmakeBuildType --target functionaltest -- $cmakeGeneratorArgs 2>&1 | cmake --build . --config $cmakeBuildType --target functionaltest -- $cmakeGeneratorArgs 2>&1 |
foreach { $failed = $failed -or foreach { $failed = $failed -or
$_ -match 'functional tests failed with error'; $_ } $_ -match 'functional tests failed with error'; $_ }
Set-PSDebug -Trace 1
if ($failed) { if ($failed) {
exit $LastExitCode exit $LastExitCode
} }
Set-PSDebug -Strict -Trace 1
if ($uploadToCodecov) { if ($uploadToCodecov) {