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,56 @@ 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
37+ # Export the requirements using poetry
3538poetry self add poetry- plugin- export
36- poetry export -f requirements.txt > requirements.txt
39+ if ($LASTEXITCODE -ne 0 ) {
40+ throw " Failed to add poetry-plugin-export"
41+ }
42+
43+ poetry export -f requirements.txt -- output requirements.txt
44+ if ($LASTEXITCODE -ne 0 ) {
45+ throw " Failed to export requirements using poetry"
46+ }
3747
38- # install the requirements
48+ # Install the requirements using pip
3949pip install - r requirements.txt
50+ if ($LASTEXITCODE -ne 0 ) {
51+ throw " Failed to install requirements using pip"
52+ }
4053
54+ # Move into the cli directory
4155Push-Location " codeql_bundle"
4256
43- # pyinstaller should also be installed
57+ # Build executable with pyinstaller
4458pyinstaller -F - n codeql_bundle cli.py
59+ if ($LASTEXITCODE -ne 0 ) {
60+ throw " PyInstaller build failed"
61+ }
4562
46- Pop-Location
47- Pop-Location
63+ Pop-Location
64+ Pop-Location
4865
66+ # Determine built output binary path
4967if ($IsWindows ) {
5068 $OutputFile = Join-Path $ArchiveDirectory " codeql_bundle" " dist" " codeql_bundle.exe"
5169}
5270else {
5371 $OutputFile = Join-Path $ArchiveDirectory " codeql_bundle" " dist" " codeql_bundle"
5472}
5573
56-
57- # this will output the binary in the `dist` directory - we should copy that binary the toplevel directory.
74+ # Copy the binary to the destination directory
5875Copy-Item - Path $OutputFile - Destination $DestinationDirectory
59-
60-
0 commit comments