-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.ps1
77 lines (58 loc) · 2.33 KB
/
publish.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<#
.DESCRIPTION
Script for publishing applications. Requires .sln and Directory.Build.props
.EXAMPLE
./script.ps1 -p "publish" -i "proj1/proj1.csproj","proj2/proj2.csproj"
.LINK
https://github.com/Gigas002/dotnet_gh_deploy
#>
[CmdletBinding(PositionalBinding = $false)]
param (
# Output (publish) path
[Parameter ()]
[ValidateNotNullOrEmpty ()]
[Alias("p", "publish-path")]
[string] $publishPath = "artifacts/publish",
# Paths to projects to publish
[Parameter ()]
[ValidateNotNullOrEmpty ()]
[string[]] $inputs = ("Deploy.Cli/Deploy.Cli.csproj",
"Deploy.Benchmarks/Deploy.Benchmarks.csproj",
"Deploy.Gui/Deploy.Gui.csproj",
"Deploy.Server/Deploy.Server.csproj",
"Deploy.Client/Deploy.Client.csproj")
)
#region Functions
function DotnetPublish([string] $project, [string] $pub, [string] $rid) {
Write-Host "Publishing $project into $pub..." -ForegroundColor Yellow
dotnet publish --tl "$project" -c Release -r $rid -o "$pub" --sc false --verbosity quiet
Write-Host "Publishing $project finished" -ForegroundColor Green
}
function CopyDocs([string] $pub) {
Write-Host "Copying docs into $pub..." -ForegroundColor Yellow
Copy-Item "*.md" "$pub/"
Remove-Item "$pub/*.pdb"
Write-Host "Finished copying docs" -ForegroundColor Green
}
function ZipArtifacts([string] $project, [string] $pub, [string] $rid) {
Write-Host "Zip artifacts for $pub..." -ForegroundColor Yellow
$artifactPath = "$publishPath/${project}_${rid}.zip"
Remove-Item -Path $artifactPath -Force -ErrorAction SilentlyContinue
Compress-Archive -Path "$pub/*" -Destination "$artifactPath"
Write-Host "Finished zip artifacts" -ForegroundColor Green
}
#endregion
switch ($true) {
$IsWindows { $rid = "win-x64"; break }
$IsLinux { $rid = "linux-x64"; break }
$IsMacOS { $rid = "osx-x64"; break }
}
Write-Host "Publishing native binaries for: $rid" -ForegroundColor Yellow
foreach ($project in $inputs) {
$projectName = Split-Path -Path "$project" -Leaf -Resolve | Split-Path -LeafBase
$pub = "$publishPath/$projectName/$rid"
DotnetPublish $project $pub $rid
CopyDocs $pub
ZipArtifacts $projectName $pub $rid
}
Write-Host "Publish binaries finished" -ForegroundColor Green