Files
MoShiro/ci/release-cross-platform.ps1
T
justme 4515d7b075
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/push/dev-image Pipeline failed
scripts: publish unified Agent artifacts and restore CI coverage [CI]
Remove Probe build jobs and release paths. Transfer Gitea publishing credentials to both Agent architecture jobs, publish each platform archive once, and run slow tests after development images are published.
2026-10-21 11:56:06 +08:00

81 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', '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'
# 版本取自 tag:写进工作区的 Directory.Build.props(仓库里的 <Version> 只是占位,发版不用再提交 bump)
$propsPath = Join-Path $backend 'Directory.Build.props'
$props = Get-Content $propsPath -Raw
Set-Content -LiteralPath $propsPath -Value ([regex]::Replace($props, '<Version>[^<]*</Version>', "<Version>$version</Version>")) -NoNewline
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' }
'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 = $env:CI_COMMIT_TAG
$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"