-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild_codeql_bundle_dist.ps1
More file actions
75 lines (58 loc) · 2.04 KB
/
build_codeql_bundle_dist.ps1
File metadata and controls
75 lines (58 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
param(
[Parameter(Mandatory = $true)]
[string] $Version,
[Parameter(Mandatory = $true)]
[string] $WorkDirectory,
[Parameter(Mandatory = $true)]
[string] $DestinationDirectory
)
# Fail on any built-in command failure
$ErrorActionPreference = "Stop"
if (-not (Test-Path $WorkDirectory)) {
New-Item -ItemType Directory -Path $WorkDirectory | Out-Null
}
if (-not (Test-Path $DestinationDirectory)) {
New-Item -ItemType Directory -Path $DestinationDirectory | Out-Null
}
# Download a copy of the release from GitHub
gh release download "v$Version" --repo https://github.com/advanced-security/codeql-bundle -D $WorkDirectory -A zip
if ($LASTEXITCODE -ne 0) {
throw "Failed to download release from GitHub (gh)"
}
# Extract the zip file
Expand-Archive -Path "$WorkDirectory\codeql-bundle-$Version.zip" -DestinationPath $WorkDirectory
# Create path to archive directory (named codeql-bundle-<version>)
$ArchiveDirectory = Join-Path $WorkDirectory "codeql-bundle-$Version"
Push-Location $ArchiveDirectory
# Export the requirements using poetry
poetry self add poetry-plugin-export
if ($LASTEXITCODE -ne 0) {
throw "Failed to add poetry-plugin-export"
}
poetry export -f requirements.txt --output requirements.txt
if ($LASTEXITCODE -ne 0) {
throw "Failed to export requirements using poetry"
}
# Install the requirements using pip
pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
throw "Failed to install requirements using pip"
}
# Move into the cli directory
Push-Location "codeql_bundle"
# Build executable with pyinstaller
pyinstaller -F -n codeql_bundle cli.py
if ($LASTEXITCODE -ne 0) {
throw "PyInstaller build failed"
}
Pop-Location
Pop-Location
# Determine built output binary path
if ($IsWindows) {
$OutputFile = Join-Path $ArchiveDirectory "codeql_bundle" "dist" "codeql_bundle.exe"
}
else {
$OutputFile = Join-Path $ArchiveDirectory "codeql_bundle" "dist" "codeql_bundle"
}
# Copy the binary to the destination directory
Copy-Item -Path $OutputFile -Destination $DestinationDirectory