forked from GateCrafter/DSharpPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild-lib.ps1
executable file
·169 lines (150 loc) · 4.18 KB
/
rebuild-lib.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env pwsh
# Rebuild-lib
#
# Rebuilds the entire DSharpPlus project, and places artifacts in specified directory.
#
# Author: Emzi0767
# Version: 2017-09-11 14:20
#
# Arguments:
# .\rebuild-lib.ps1 <output path> [version suffix]
#
# Run as:
# .\rebuild-lib.ps1 .\path\to\artifact\location version-suffix
#
# or
# .\rebuild-lib.ps1 .\path\to\artifact\location
param
(
[parameter(Mandatory = $true)]
[string] $ArtifactLocation,
[parameter(Mandatory = $false)]
[string] $VersionSuffix,
[parameter(Mandatory = $true)]
[string] $Configuration
)
# Check if configuration is valid
if ($Configuration -ne "Debug" -and $Configuration -ne "Release")
{
Write-Host "Invalid configuration specified. Must be Release or Debug."
Exit 1
}
# Restores the environment
function Restore-Environment()
{
Write-Host "Restoring environment"
Remove-Item ./NuGet.config
}
# Prepares the environment
function Prepare-Environment([string] $target_dir_path)
{
# Prepare the environment
Copy-Item ./.nuget/NuGet.config ./
# Check if the target directory exists
# If it does, remove it
if (Test-Path "$target_dir_path")
{
Write-Host "Target directory exists, deleting"
Remove-Item -recurse -force "$target_dir_path"
}
# Create target directory
$dir = New-Item -type directory "$target_dir_path"
}
# Builds everything
function Build-All([string] $target_dir_path, [string] $version_suffix, [string] $bcfg)
{
# Form target path
$dir = Get-Item "$target_dir_path"
$target_dir = $dir.FullName
Write-Host "Will place packages in $target_dir"
# Clean previous build results
Write-Host "Cleaning previous build"
& dotnet clean -v minimal -c "$bcfg" | Out-Host
if ($LastExitCode -ne 0)
{
Write-Host "Cleanup failed"
Return $LastExitCode
}
# Restore nuget packages
Write-Host "Restoring NuGet packages"
& dotnet restore -v minimal | Out-Host
if ($LastExitCode -ne 0)
{
Write-Host "Restoring packages failed"
Return $LastExitCode
}
if ($Env:OS -eq $null)
{
# Build and package (if Release) in specified configuration but Linux
Write-Host "Building everything"
if (-not $version_suffix)
{
& .\rebuild-linux.ps1 "$target_dir" -Configuration "$bcfg" | Out-Host
}
else
{
& .\rebuild-linux.ps1 "$target_dir" -VersionSuffix "$version_suffix" -Configuration "$bcfg" | Out-Host
}
if ($LastExitCode -ne 0)
{
Write-Host "Packaging failed"
Return $LastExitCode
}
}
else
{
# Build in specified configuration
Write-Host "Building everything"
if (-not $version_suffix)
{
& dotnet build -v minimal -c "$bcfg" | Out-Host
}
else
{
& dotnet build -v minimal -c "$bcfg" --version-suffix "$version_suffix" | Out-Host
}
if ($LastExitCode -ne 0)
{
Write-Host "Build failed"
Return $LastExitCode
}
# Package for NuGet
Write-Host "Creating NuGet packages"
if (-not $version_suffix)
{
& dotnet pack -v minimal -c "$bcfg" --no-build -o "$target_dir" --include-symbols | Out-Host
}
else
{
& dotnet pack -v minimal -c "$bcfg" --version-suffix "$version_suffix" --no-build -o "$target_dir" --include-symbols | Out-Host
}
if ($LastExitCode -ne 0)
{
Write-Host "Packaging failed"
Return $LastExitCode
}
}
Return 0
}
# Check if building a beta package
if ($VersionSuffix)
{
Write-Host "Building beta package with version suffix of `"$VersionSuffix`""
}
# Prepare environment
Prepare-Environment "$ArtifactLocation"
# Build everything
$BuildResult = Build-All "$ArtifactLocation" "$VersionSuffix" "$Configuration"
# Restore environment
Restore-Environment
# Check if there were any errors
if ($BuildResult -ne 0)
{
Write-Host "Build failed with code $BuildResult"
$host.SetShouldExit($BuildResult)
Exit $BuildResult
}
else
{
Exit 0
}