XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWorkflow

【WinUI】XFE基于windows的工作流

公开
关注 0 Fork 0 Star 0
UTF-8
param([ValidateSet('x64','x86','ARM64')] [string]$Platform = 'x64', [switch]$IncludeLinuxServer, [string]$Output)
$ErrorActionPreference = 'Stop'
$repoRoot = Split-Path $PSScriptRoot
Set-Location -LiteralPath $repoRoot
if (!$Output) { $Output = Join-Path $repoRoot ('.artifacts/release/' + (Get-Date -Format 'yyyyMMdd-HHmmss') + '-' + $Platform) }
$releaseRoot = [IO.Path]::GetFullPath($Output)
if (Test-Path -LiteralPath $releaseRoot) { throw '发布目录已存在,请指定新的 Output,避免覆盖已有发布。' }
New-Item -ItemType Directory -Path $releaseRoot | Out-Null
$rid = 'win-' + $Platform.ToLowerInvariant()
function Invoke-DotNetCli([string[]]$Arguments) { & dotnet @Arguments; if ($LASTEXITCODE -ne 0) { throw "dotnet 执行失败:$($Arguments -join ' ')" } }
function CopyTree([string]$source, [string]$destination, [string[]]$excludedDirectories = @()) {
    New-Item -ItemType Directory -Force -Path $destination | Out-Null
    Get-ChildItem -LiteralPath $source -Force | ForEach-Object {
        if ($_.PSIsContainer) {
            if ($_.Name -notin $excludedDirectories) { CopyTree $_.FullName (Join-Path $destination $_.Name) $excludedDirectories }
        } else { Copy-Item -LiteralPath $_.FullName -Destination $destination -Force }
    }
}
function NewPortableArchive([string]$source, [string]$destination) {
    $sourceRoot = [IO.Path]::GetFullPath($source).TrimEnd('\','/') + [IO.Path]::DirectorySeparatorChar
    $archive = [IO.Compression.ZipFile]::Open($destination, [IO.Compression.ZipArchiveMode]::Create)
    try {
        Get-ChildItem -LiteralPath $sourceRoot -File -Recurse -Force | ForEach-Object {
            $entryName = $_.FullName.Substring($sourceRoot.Length).Replace('\','/')
            [IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, $_.FullName, $entryName, [IO.Compression.CompressionLevel]::Optimal) | Out-Null
        }
    } finally { $archive.Dispose() }
}
Invoke-DotNetCli -Arguments @('build','XFEWorkflow.slnx','-c','Release',('-p:Platform=' + $Platform),'-nr:false','-m:1','--nologo')
$desktop = Join-Path $releaseRoot ('XFEWorkflow-' + $rid)
Invoke-DotNetCli -Arguments @('publish','XFEWorkflow/XFEWorkflow/XFEWorkflow.csproj','-c','Release',('-p:Platform=' + $Platform),'-r',$rid,'--self-contained','true','--no-build','--no-restore','-o',$desktop,'-nr:false')
$buildRoot = Join-Path $repoRoot ('XFEWorkflow/XFEWorkflow/bin/' + $Platform + '/Release/net10.0-windows10.0.22621.0/' + $rid)
CopyTree (Join-Path $buildRoot 'Runner') (Join-Path $desktop 'Runner')
CopyTree (Join-Path $buildRoot 'BundledPlugins') (Join-Path $desktop 'BundledPlugins')
CopyTree (Join-Path $buildRoot 'NativeBridge') (Join-Path $desktop 'NativeBridge')
$packages = Join-Path $releaseRoot 'Plugins'; New-Item -ItemType Directory -Path $packages | Out-Null
Add-Type -AssemblyName System.IO.Compression, System.IO.Compression.FileSystem
Get-ChildItem -LiteralPath (Join-Path $desktop 'BundledPlugins') -Filter 'plugin.json' -Recurse | ForEach-Object {
    $manifest = Get-Content -LiteralPath $_.FullName -Raw -Encoding UTF8 | ConvertFrom-Json
    NewPortableArchive $_.DirectoryName (Join-Path $packages ($manifest.id + '-' + $manifest.version + '.xfeplugin'))
}
$serverRids = @($rid); if ($IncludeLinuxServer) { $serverRids += 'linux-x64' }
foreach ($serverRid in $serverRids) {
    Invoke-DotNetCli -Arguments @('publish','XFEWorkflow/XFEWorkflow.Space.Server/XFEWorkflow.Space.Server.csproj','-c','Release','-r',$serverRid,'--self-contained','true','-o',(Join-Path $releaseRoot ('XFEWorkflow.Space-' + $serverRid)),'-nr:false')
}
CopyTree (Join-Path $repoRoot 'docs') (Join-Path $desktop 'docs')
CopyTree (Join-Path $repoRoot 'samples') (Join-Path $desktop 'samples') @('bin','obj')
CopyTree (Join-Path $repoRoot 'vendor') (Join-Path $desktop 'vendor')
Copy-Item -LiteralPath (Join-Path $repoRoot 'README.md'), (Join-Path $repoRoot 'THIRD-PARTY-NOTICES.md'), (Join-Path $repoRoot 'LICENSE.txt') -Destination $desktop
foreach ($directory in Get-ChildItem -LiteralPath $releaseRoot -Directory | Where-Object Name -ne 'Plugins') {
    NewPortableArchive $directory.FullName ($directory.FullName + '.zip')
}
Get-ChildItem -LiteralPath $releaseRoot -File -Recurse | Where-Object Extension -in '.zip','.xfeplugin' | ForEach-Object {
    $hash = Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256
    $hash.Hash.ToLowerInvariant() + '  ' + $_.FullName.Substring($releaseRoot.TrimEnd('\','/').Length + 1)
} | Set-Content -LiteralPath (Join-Path $releaseRoot 'SHA256SUMS.txt') -Encoding utf8
Write-Output "发布完成:$releaseRoot"