-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.ps1
57 lines (46 loc) · 1.91 KB
/
build.ps1
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
param(
[Parameter(Position = 0, ValueFromPipeline = $true)]
[ValidateSet("Publish", "Set-Snapx-Token")]
[string] $Target = "Publish",
[Parameter(Position = 0, ValueFromPipeline = $true)]
[string] $Version = "0.0.0",
[Parameter(Position = 1, ValueFromPipeline = $true)]
[ValidateSet("Debug", "Release")]
[string] $Configuration = "Release",
[Parameter(Position = 2, ValueFromPipeline = $true)]
[string] $SnapxToken = $null,
[Parameter(Position = 3, Mandatory=$true, ValueFromPipeline = $true)]
[ValidateSet("win-x86", "win-x64", "linux-x64", "linux-arm64")]
[string] $Rid
)
$WorkingDirectory = Split-Path -parent $MyInvocation.MyCommand.Definition
. $WorkingDirectory\common.ps1
$Framework = "net8.0"
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
$BuildOutputDirectory = Join-Path $WorkingDirectory .snapx\artifacts\demoapp-$Rid\$Rid\$Version
$SnapxYmlFilenamePath = Join-Path $WorkingDirectory .snapx\snapx.yml
switch($Target) {
"Publish" {
Resolve-Shell-Dependency dotnet
Invoke-Command-Colored dotnet @(
("publish {0}" -f (Join-Path $WorkingDirectory src/demoapp/demoapp.csproj))
"/p:Version=$Version"
"--runtime $Rid"
"--self-contained"
"--framework $Framework"
"--output $BuildOutputDirectory"
"--configuration $Configuration"
)
}
"Set-Snapx-Token" {
Write-Output-Colored "Replacing snapx lock token"
$SnapxYmlContent = (Get-Content $SnapxYmlFilenamePath) -replace "token:.*", "token: ${SnapxToken}"
if($SnapxYmlContent -match "token: ${SnapxToken}") {
$SnapxYmlContent | Out-File $SnapxYmlFilenamePath -Encoding $Utf8NoBomEncoding
Write-Output "Successfully replaced snapx lock token"
exit 0
}
Write-Error "Unknown error replacing snapx lock token"
exit 0
}
}