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,56 @@ 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
37
+ # Export the requirements using poetry
35
38
poetry 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
+ }
37
47
38
- # install the requirements
48
+ # Install the requirements using pip
39
49
pip install - r requirements.txt
50
+ if ($LASTEXITCODE -ne 0 ) {
51
+ throw " Failed to install requirements using pip"
52
+ }
40
53
54
+ # Move into the cli directory
41
55
Push-Location " codeql_bundle"
42
56
43
- # pyinstaller should also be installed
57
+ # Build executable with pyinstaller
44
58
pyinstaller -F - n codeql_bundle cli.py
59
+ if ($LASTEXITCODE -ne 0 ) {
60
+ throw " PyInstaller build failed"
61
+ }
45
62
46
- Pop-Location
47
- Pop-Location
63
+ Pop-Location
64
+ Pop-Location
48
65
66
+ # Determine built output binary path
49
67
if ($IsWindows ) {
50
68
$OutputFile = Join-Path $ArchiveDirectory " codeql_bundle" " dist" " codeql_bundle.exe"
51
69
}
52
70
else {
53
71
$OutputFile = Join-Path $ArchiveDirectory " codeql_bundle" " dist" " codeql_bundle"
54
72
}
55
73
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
58
75
Copy-Item - Path $OutputFile - Destination $DestinationDirectory
59
-
60
-
0 commit comments