11param (
22 [Parameter (Mandatory = $true )]
3- [string ]
4- $Version ,
3+ [string ] $Version ,
4+
55 [Parameter (Mandatory = $true )]
6- [string ]
7- $WorkDirectory ,
6+ [string ] $WorkDirectory ,
87
98 [Parameter (Mandatory = $true )]
10- [string ]
11- $DestinationDirectory
9+ [string ] $DestinationDirectory
1210)
1311
12+ # Fail on any built-in command failure
13+ $ErrorActionPreference = " Stop"
14+
1415if (-not (Test-Path $WorkDirectory )) {
1516 New-Item - ItemType Directory - Path $WorkDirectory | Out-Null
1617}
@@ -19,42 +20,51 @@ if (-not (Test-Path $DestinationDirectory)) {
1920 New-Item - ItemType Directory - Path $DestinationDirectory | Out-Null
2021}
2122
22- # download a copy of the release from GitHub
23- gh release download " v$Version " -- repo https:// github.com / advanced- security/ codeql- bundle - D $WorkDirectory - A zip
23+ # Download a copy of the release from GitHub
24+ gh release download " v$Version " -- repo https:// github.com / advanced- security/ codeql- bundle - D $WorkDirectory - A zip
25+ if ($LASTEXITCODE -ne 0 ) {
26+ throw " Failed to download release from GitHub (gh)"
27+ }
2428
25- # extract the zip file
29+ # Extract the zip file
2630Expand-Archive - Path " $WorkDirectory \codeql-bundle-$Version .zip" - DestinationPath $WorkDirectory
2731
28- # creates a directory named ` codeql-bundle-<version>`
32+ # Create path to archive directory ( named codeql-bundle-<version>)
2933$ArchiveDirectory = Join-Path $WorkDirectory " codeql-bundle-$Version "
3034
3135Push-Location $ArchiveDirectory
3236
33- # at this point python should already be installed as well as poetry
34- # export the requirements
35- poetry self add poetry- plugin- export
36- poetry export -f requirements.txt > requirements.txt
37+ # Export the requirements using poetry
38+ poetry export -f requirements.txt -- output requirements.txt
39+ if ($LASTEXITCODE -ne 0 ) {
40+ throw " Failed to export requirements using poetry"
41+ }
3742
38- # install the requirements
43+ # Install the requirements using pip
3944pip install - r requirements.txt
45+ if ($LASTEXITCODE -ne 0 ) {
46+ throw " Failed to install requirements using pip"
47+ }
4048
49+ # Move into the cli directory
4150Push-Location " codeql_bundle"
4251
43- # pyinstaller should also be installed
52+ # Build executable with pyinstaller
4453pyinstaller -F - n codeql_bundle cli.py
54+ if ($LASTEXITCODE -ne 0 ) {
55+ throw " PyInstaller build failed"
56+ }
4557
46- Pop-Location
47- Pop-Location
58+ Pop-Location
59+ Pop-Location
4860
61+ # Determine built output binary path
4962if ($IsWindows ) {
5063 $OutputFile = Join-Path $ArchiveDirectory " codeql_bundle" " dist" " codeql_bundle.exe"
5164}
5265else {
5366 $OutputFile = Join-Path $ArchiveDirectory " codeql_bundle" " dist" " codeql_bundle"
5467}
5568
56-
57- # this will output the binary in the `dist` directory - we should copy that binary the toplevel directory.
69+ # Copy the binary to the destination directory
5870Copy-Item - Path $OutputFile - Destination $DestinationDirectory
59-
60-
0 commit comments