1
1
param (
2
2
[Parameter (Mandatory = $true )]
3
- [string ]
4
- $Version ,
3
+ [string ] $Version ,
4
+
5
5
[Parameter (Mandatory = $true )]
6
- [string ]
7
- $WorkDirectory ,
6
+ [string ] $WorkDirectory ,
8
7
9
8
[Parameter (Mandatory = $true )]
10
- [string ]
11
- $DestinationDirectory
9
+ [string ] $DestinationDirectory
12
10
)
13
11
12
+ # Fail on any built-in command failure
13
+ $ErrorActionPreference = " Stop"
14
+
14
15
if (-not (Test-Path $WorkDirectory )) {
15
16
New-Item - ItemType Directory - Path $WorkDirectory | Out-Null
16
17
}
@@ -19,42 +20,51 @@ if (-not (Test-Path $DestinationDirectory)) {
19
20
New-Item - ItemType Directory - Path $DestinationDirectory | Out-Null
20
21
}
21
22
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
+ }
24
28
25
- # extract the zip file
29
+ # Extract the zip file
26
30
Expand-Archive - Path " $WorkDirectory \codeql-bundle-$Version .zip" - DestinationPath $WorkDirectory
27
31
28
- # creates a directory named ` codeql-bundle-<version>`
32
+ # Create path to archive directory ( named codeql-bundle-<version>)
29
33
$ArchiveDirectory = Join-Path $WorkDirectory " codeql-bundle-$Version "
30
34
31
35
Push-Location $ArchiveDirectory
32
36
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
+ }
37
42
38
- # install the requirements
43
+ # Install the requirements using pip
39
44
pip install - r requirements.txt
45
+ if ($LASTEXITCODE -ne 0 ) {
46
+ throw " Failed to install requirements using pip"
47
+ }
40
48
49
+ # Move into the cli directory
41
50
Push-Location " codeql_bundle"
42
51
43
- # pyinstaller should also be installed
52
+ # Build executable with pyinstaller
44
53
pyinstaller -F - n codeql_bundle cli.py
54
+ if ($LASTEXITCODE -ne 0 ) {
55
+ throw " PyInstaller build failed"
56
+ }
45
57
46
- Pop-Location
47
- Pop-Location
58
+ Pop-Location
59
+ Pop-Location
48
60
61
+ # Determine built output binary path
49
62
if ($IsWindows ) {
50
63
$OutputFile = Join-Path $ArchiveDirectory " codeql_bundle" " dist" " codeql_bundle.exe"
51
64
}
52
65
else {
53
66
$OutputFile = Join-Path $ArchiveDirectory " codeql_bundle" " dist" " codeql_bundle"
54
67
}
55
68
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
58
70
Copy-Item - Path $OutputFile - Destination $DestinationDirectory
59
-
60
-
0 commit comments