Repository navigation
Expand file tree
/
Copy pathBuild.ps1
More file actions
69 lines (69 loc) · 4.38 KB
/
Copy pathBuild.ps1
File metadata and controls
69 lines (69 loc) · 4.38 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
param(
[ValidateSet('win-x64','win-arm64')][string]$RuntimeIdentifier = 'win-x64',
[string]$ConfigPath = '',
[string]$OutputPath = '',
[string]$DotNetPath = 'dotnet',
[switch]$RunTests
)
$ErrorActionPreference = 'Stop'
$repository = $PSScriptRoot
if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) { throw 'This build script is validated on Windows. WPF execution/tests require Windows.' }
$sdkVersion = (& $DotNetPath --version).Trim()
if ($LASTEXITCODE -ne 0 -or [int]($sdkVersion.Split('.')[0]) -lt 10) { throw '.NET 10 SDK or newer is required.' }
if (!$ConfigPath) {
$localConfig = Join-Path $repository 'public-build-config.local.json'
$ConfigPath = if (Test-Path -LiteralPath $localConfig) { $localConfig } else { Join-Path $repository 'public-build-config.json' }
}
$config = Get-Content -LiteralPath $ConfigPath -Raw | ConvertFrom-Json
if (![Guid]::TryParse($config.MS_CLIENT_ID, [ref]([Guid]::Empty))) { throw 'MS_CLIENT_ID must be a public OAuth application/client GUID, not a client secret.' }
foreach ($endpoint in $config.LINK_SERVER_ROOT.Split('|')) {
if (!$endpoint) { continue }
$uri = [Uri]$endpoint
if (!$uri.IsAbsoluteUri -or $uri.Scheme -ne 'https') { throw 'Lobby roots must be absolute HTTPS URLs.' }
}
if (!$OutputPath) { $OutputPath = Join-Path $repository ('artifacts\' + $RuntimeIdentifier) }
$OutputPath = [IO.Path]::GetFullPath($OutputPath)
if ($OutputPath.TrimEnd('\') -eq $repository.TrimEnd('\')) { throw 'Publish output must not be the source root.' }
$previousEnvironment = @{}
foreach ($name in @([Environment]::GetEnvironmentVariables('Process').Keys)) {
if ($name.StartsWith('PCL_')) { $previousEnvironment[$name] = [Environment]::GetEnvironmentVariable($name, 'Process'); [Environment]::SetEnvironmentVariable($name, $null, 'Process') }
}
Push-Location $repository
try {
# The public build embeds only these non-secret values, never arbitrary inherited PCL_* variables.
$env:PCL_WRITE_SECRET = '1'
$env:PCL_MS_CLIENT_ID = $config.MS_CLIENT_ID
$env:PCL_LINK_SERVER_ROOT = $config.LINK_SERVER_ROOT
$sourceRevision = $config.GITHUB_SHA
if ($env:GITHUB_SHA -match '^[0-9a-fA-F]{40}$') { $sourceRevision = $env:GITHUB_SHA }
elseif (Test-Path -LiteralPath (Join-Path $repository '.git')) {
$gitRevision = & git -C $repository rev-parse HEAD
if ($LASTEXITCODE -eq 0 -and $gitRevision -match '^[0-9a-fA-F]{40}$') { $sourceRevision = $gitRevision.Trim() }
}
if ($sourceRevision -notmatch '^[0-9a-fA-F]{40}$') { throw 'A source revision is required for build metadata.' }
$env:PCL_GITHUB_SHA = $sourceRevision
& $DotNetPath publish 'Plain Craft Launcher 2/Plain Craft Launcher 2.csproj' -c Release -r $RuntimeIdentifier `
--self-contained true -p:UseSharedCompilation=false -nodeReuse:false -o $OutputPath
if ($LASTEXITCODE -ne 0) { throw 'Publish failed.' }
$exe = Join-Path $OutputPath 'Plain Craft Launcher 2.exe'
$ultraExe = Join-Path $OutputPath 'PCL Ultra.exe'
Copy-Item -LiteralPath $exe -Destination $ultraExe -Force
if ($RunTests) {
if ($RuntimeIdentifier -ne 'win-x64') { throw 'The documented test run currently targets Windows x64.' }
$filter = 'FullyQualifiedName~BedrockOnlineTest|FullyQualifiedName~BedrockLibraryTest|FullyQualifiedName~DependencyHealthTest|FullyQualifiedName~ModSafetyScanTest|FullyQualifiedName~DnsFallbackTest|FullyQualifiedName~SnapshotThemeStyleTest|FullyQualifiedName~ThemePaletteTest'
& $DotNetPath test 'PCL.Core.Test/PCL.Core.Test.csproj' -c Release -p:UseSharedCompilation=false -nodeReuse:false `
--filter $filter --logger 'trx;LogFileName=ultra-feature-tests.trx' --results-directory (Join-Path $OutputPath 'TestResults')
if ($LASTEXITCODE -ne 0) { throw 'Feature tests failed.' }
}
$hash = (Get-FileHash -LiteralPath $ultraExe -Algorithm SHA256).Hash
[IO.File]::WriteAllText((Join-Path $OutputPath 'SHA256SUMS.txt'), $hash + ' PCL Ultra.exe' + [Environment]::NewLine)
Write-Output "Build complete: $ultraExe"
Write-Output "SHA256: $hash"
}
finally {
Pop-Location
foreach ($name in @([Environment]::GetEnvironmentVariables('Process').Keys)) {
if ($name.StartsWith('PCL_')) { [Environment]::SetEnvironmentVariable($name, $null, 'Process') }
}
foreach ($name in $previousEnvironment.Keys) { [Environment]::SetEnvironmentVariable($name, $previousEnvironment[$name], 'Process') }
}