Namespaces, assemblies, projects and directories, the solution, binaries, images, systemd units, config paths, environment variables, protocol method names, the media type and the raw chunk magic all move to MoShiro/moshiro. Existing data and deployments are not compatible and must be recreated. Also fix the architecture tests after the solution layout change and make the update tests independent of their order.
82 lines
3.0 KiB
PowerShell
82 lines
3.0 KiB
PowerShell
param(
|
|
[Parameter(Mandatory)]
|
|
[ValidateSet(
|
|
'linux-x64', 'linux-arm64',
|
|
'linux-musl-x64', 'linux-musl-arm64',
|
|
'osx-x64', 'osx-arm64', 'win-x64', 'win-arm64'
|
|
)]
|
|
[string]$RuntimeIdentifier,
|
|
[Parameter(Mandatory)]
|
|
[ValidateSet('agent', 'probe', 'fleet-enroll')]
|
|
[string]$Component
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
Set-StrictMode -Version Latest
|
|
|
|
if (-not $env:CI_COMMIT_TAG -or $env:CI_COMMIT_TAG -notmatch '^v(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$') {
|
|
throw 'Release must run from a vMAJOR.MINOR.PATCH tag.'
|
|
}
|
|
$version = $Matches[1]
|
|
$root = Split-Path -Parent $PSScriptRoot
|
|
$backend = Join-Path $root 'backend'
|
|
$projectVersion = [regex]::Match((Get-Content (Join-Path $backend 'Directory.Build.props') -Raw), '<Version>([^<]+)</Version>').Groups[1].Value
|
|
if ($version -ne $projectVersion) {
|
|
throw "Tag version $version does not match project version $projectVersion."
|
|
}
|
|
|
|
if ($RuntimeIdentifier -in @('win-x64', 'win-arm64')) {
|
|
$vcArchitecture = if ($RuntimeIdentifier -eq 'win-x64') { 'x64' } else { 'arm64' }
|
|
$vsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
|
|
$vsPath = & $vsWhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
|
if (-not $vsPath) {
|
|
throw 'Visual Studio C++ Build Tools were not found.'
|
|
}
|
|
$devCmd = Join-Path $vsPath 'Common7\Tools\VsDevCmd.bat'
|
|
$environmentLines = & cmd.exe /d /s /c "call `"$devCmd`" -no_logo -arch=$vcArchitecture -host_arch=x64 && set"
|
|
foreach ($line in $environmentLines) {
|
|
$separator = $line.IndexOf('=')
|
|
if ($separator -gt 0) {
|
|
[Environment]::SetEnvironmentVariable($line.Substring(0, $separator), $line.Substring($separator + 1), 'Process')
|
|
}
|
|
}
|
|
}
|
|
|
|
$project = switch ($Component) {
|
|
'agent' { 'agent/src/MoShiro.Agent' }
|
|
'probe' { 'probe/src/MoShiro.Probe' }
|
|
'fleet-enroll' { 'fleet/tools/fleet-enroll' }
|
|
}
|
|
$output = Join-Path $root ".release\publish\$RuntimeIdentifier\$Component"
|
|
$buildRoot = Join-Path $root ".release\build\$RuntimeIdentifier-$Component"
|
|
$null = New-Item -ItemType Directory -Force -Path $output
|
|
|
|
# 构建信息:程序里显示的 tag、提交、构建时间
|
|
$env:MOSHIRO_TAG = if ($env:CI_COMMIT_TAG) { $env:CI_COMMIT_TAG } else { "main-$($env:CI_COMMIT_SHA.Substring(0, 10))" }
|
|
$env:MOSHIRO_COMMIT = $env:CI_COMMIT_SHA.Substring(0, 10)
|
|
$env:MOSHIRO_BUILT_AT = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
|
|
|
|
Push-Location $backend
|
|
try {
|
|
& dotnet publish $project `
|
|
-m:1 `
|
|
-c Release `
|
|
-r $RuntimeIdentifier `
|
|
--self-contained true `
|
|
-p:PublishAot=true `
|
|
-p:UseAotAnywhere=true `
|
|
-p:StripSymbols=true `
|
|
-p:DebugType=none `
|
|
-p:DebugSymbols=false `
|
|
--artifacts-path $buildRoot `
|
|
-o $output
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "NativeAOT publish failed for $project ($RuntimeIdentifier)."
|
|
}
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|
|
|
|
Write-Output "built $Component for $RuntimeIdentifier"
|