Fail windows bundle when cargo about fails (#48056)

Conrad Irwin created

Release Notes:

- N/A

Change summary

script/bundle-windows.ps1    |  3 ---
script/generate-licenses.ps1 | 20 ++++++++++++++++----
2 files changed, 16 insertions(+), 7 deletions(-)

Detailed changes

script/bundle-windows.ps1 🔗

@@ -96,10 +96,7 @@ function PrepareForBundle {
 }
 
 function GenerateLicenses {
-    $oldErrorActionPreference = $ErrorActionPreference
-    $ErrorActionPreference = 'Continue'
     . $PSScriptRoot/generate-licenses.ps1
-    $ErrorActionPreference = $oldErrorActionPreference
 }
 
 function BuildZedAndItsFriends {

script/generate-licenses.ps1 🔗

@@ -1,3 +1,6 @@
+$ErrorActionPreference = 'Stop'
+$PSNativeCommandUseErrorActionPreference = $true
+
 $CARGO_ABOUT_VERSION="0.8.2"
 $outputFile=$args[0] ? $args[0] : "$(Get-Location)/assets/licenses.md"
 $templateFile="script/licenses/template.md.hbs"
@@ -12,12 +15,21 @@ New-Item -Path "$outputFile" -ItemType File -Value "" -Force
     "\n# ###### CODE LICENSES ######\n"
 ) | Add-Content -Path $outputFile
 
-$versionOutput = cargo about --version
-if (-not ($versionOutput -match "cargo-about $CARGO_ABOUT_VERSION")) {
+$needsInstall = $false
+try {
+    $versionOutput = cargo about --version
+    if (-not ($versionOutput -match "cargo-about $CARGO_ABOUT_VERSION")) {
+        $needsInstall = $true
+    } else {
+        Write-Host "cargo-about@$CARGO_ABOUT_VERSION is already installed"
+    }
+} catch {
+    $needsInstall = $true
+}
+
+if ($needsInstall) {
     Write-Host "Installing cargo-about@$CARGO_ABOUT_VERSION..."
     cargo install "cargo-about@$CARGO_ABOUT_VERSION"
-} else {
-    Write-Host "cargo-about@$CARGO_ABOUT_VERSION" is already installed
 }
 
 Write-Host "Generating cargo licenses"