-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublish-release.ps1
More file actions
101 lines (85 loc) · 4.35 KB
/
Copy pathpublish-release.ps1
File metadata and controls
101 lines (85 loc) · 4.35 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<#
.SYNOPSIS
Build, test, and package a self-contained BruceEDR release for Windows x64.
.DESCRIPTION
Produces artifacts/BruceEDR-<version>-win-x64.zip containing single-file,
self-contained BruceEDR.exe (console) and BruceEDR.Gui.exe (desktop),
plus the sample config, YARA rules, and docs. No .NET runtime required on the target.
.EXAMPLE
./publish-release.ps1 -Version 1.0
#>
[CmdletBinding()]
param(
[string]$Version = "1.0",
[string]$Rid = "win-x64"
)
$ErrorActionPreference = "Stop"
$root = $PSScriptRoot
$name = "BruceEDR-v$Version-$Rid"
$artifacts = Join-Path $root "artifacts"
$stage = Join-Path $artifacts $name
Write-Host "== BruceEDR release $Version ($Rid) ==" -ForegroundColor Cyan
# Clean prior artifacts
if (Test-Path $stage) { Remove-Item $stage -Recurse -Force }
New-Item -ItemType Directory -Force -Path $stage | Out-Null
# 1) Gate on a clean build + green tests
Write-Host "-- build + test" -ForegroundColor Cyan
dotnet build "$root/BruceEDR.sln" -c Release --nologo
if ($LASTEXITCODE -ne 0) { throw "build failed" }
dotnet test "$root/tests/BruceEDR.Tests/BruceEDR.Tests.csproj" -c Release --nologo
if ($LASTEXITCODE -ne 0) { throw "tests failed" }
$common = @(
"-c", "Release", "-r", $Rid,
"--self-contained", "true",
"-p:PublishSingleFile=true",
"-p:EnableCompressionInSingleFile=true",
"-p:DebugType=none"
)
# 2) Publish the console agent (single self-contained exe)
Write-Host "-- publish console" -ForegroundColor Cyan
$conOut = Join-Path $artifacts "_console"
if (Test-Path $conOut) { Remove-Item $conOut -Recurse -Force }
dotnet publish "$root/BruceEDR.csproj" @common -o $conOut
if ($LASTEXITCODE -ne 0) { throw "console publish failed" }
# 3) Publish the WPF GUI into a gui/ subfolder
Write-Host "-- publish gui" -ForegroundColor Cyan
$guiOut = Join-Path $artifacts "_gui"
if (Test-Path $guiOut) { Remove-Item $guiOut -Recurse -Force }
dotnet publish "$root/gui/BruceEDR.Gui/BruceEDR.Gui.csproj" @common -o $guiOut
if ($LASTEXITCODE -ne 0) { throw "gui publish failed" }
# 4) Stage: console exe at the root, gui exe under gui/, plus config/rules/docs
Write-Host "-- stage" -ForegroundColor Cyan
Copy-Item (Join-Path $conOut "BruceEDR.exe") $stage -Force
New-Item -ItemType Directory -Force -Path (Join-Path $stage "gui") | Out-Null
Copy-Item (Join-Path $guiOut "BruceEDR.Gui.exe") (Join-Path $stage "gui") -Force
Copy-Item (Join-Path $root "bruce.config.json") $stage -Force
# rules/ carries both the YARA samples and the JSON detection packs the agent loads at
# startup; Replay/scenarios and intel/feeds are what make --selftest and the intel feature
# work out of the box in the shipped layout.
Copy-Item (Join-Path $root "rules") (Join-Path $stage "rules") -Recurse -Force
New-Item -ItemType Directory -Force -Path (Join-Path $stage "Replay") | Out-Null
Copy-Item (Join-Path $root "Replay/scenarios") (Join-Path $stage "Replay/scenarios") -Recurse -Force
New-Item -ItemType Directory -Force -Path (Join-Path $stage "intel") | Out-Null
Copy-Item (Join-Path $root "intel/feeds") (Join-Path $stage "intel/feeds") -Recurse -Force
# intel/geo is what the GUI's Network map resolves addresses against. Without it the tab
# degrades to "map data missing" -- shipping the feature but not its data.
Copy-Item (Join-Path $root "intel/geo") (Join-Path $stage "intel/geo") -Recurse -Force
foreach ($doc in "README.md","LICENSE","GETTING_STARTED.md") {
Copy-Item (Join-Path $root $doc) $stage -Force
}
Copy-Item (Join-Path $root "docs") (Join-Path $stage "docs") -Recurse -Force
# 4b) Gate the release on the packaged content actually working. This runs the shipped
# exe against the shipped rules and scenarios, so a rule pack that got left out of the
# zip fails the build rather than the user's first run.
Write-Host "-- self-test the staged build" -ForegroundColor Cyan
& (Join-Path $stage "BruceEDR.exe") --selftest
if ($LASTEXITCODE -ne 0) { throw "self-test failed against the staged release" }
# 5) Zip
Write-Host "-- zip" -ForegroundColor Cyan
$zip = Join-Path $artifacts "$name.zip"
if (Test-Path $zip) { Remove-Item $zip -Force }
Compress-Archive -Path (Join-Path $stage "*") -DestinationPath $zip -CompressionLevel Optimal
# cleanup intermediate publish dirs
Remove-Item $conOut,$guiOut -Recurse -Force -ErrorAction SilentlyContinue
$size = "{0:N1} MB" -f ((Get-Item $zip).Length / 1MB)
Write-Host "== done: $zip ($size) ==" -ForegroundColor Green