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