forked from Lachee/discord-rpc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
156 lines (131 loc) · 3.49 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
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
[CmdletBinding()]
Param(
[string]$Target,
[switch]$MakeUnityPackage,
[switch]$MakeNugetPackage,
[switch]$IgnoreLibraryBuild,
[switch]$MakeDocs,
[switch]$ReleaseDocs,
[int]$BuildCount,
[string]$BuildTag,
[string]$Certificate
)
function GatherArtifacts([string] $dest_root, [string] $target, [bool]$include_unity, [bool]$include_nuget)
{
$project = "DiscordRPC";
#Prepare the DLL and package names
$manage_dll = "$project.dll";
$unity_pack = "$project.unitypackage";
#prepare the source folders
$source_managed = "./$project/bin/$target";
$source_unity = "./";
$source_nuget = "./nupkg"
#create the directories for the dest
mkdir -Force $dest_root
#copy the files
copy -Force "$source_managed/$manage_dll" "$dest_root/$manage_dll"
Write-Host "Artifact: $dest_root/$manage_dll"
if ($include_unity)
{
Move-Item -Force "$source_unity/$unity_pack" "$dest_root/$unity_pack";
Write-Host "Artifact: $dest_root/$unity_pack";
}
if ($include_nuget)
{
Move-Item -Force "$source_nuget/*" "$dest_root/"
Write-Host "Artifact: NUGET"
}
}
function BuildLibrary($buildCount, $buildTag, [bool]$makeNuget)
{
Write-Host "-buildCounter=$buildCount",'-buildType="Release"'
$args = "-buildCounter=$buildCount",'-buildType="Release"',"-Verbosity=diagnostic"
if (![string]::IsNullOrEmpty($buildTag)) { $args += "-buildTag=$buildTag" }
if (![string]::IsNullOrEmpty($Certificate))
{
$args += "-signCertificate=$Certificate"
$args += "-signPassword=$env:CERTIFICATE_PASSWORD"
}
if ($makeNuget)
{
.\build-lib.ps1 -Target "NugetBuild" -ScriptArgs $args
}
else
{
.\build-lib.ps1 -Target "Default" -ScriptArgs $args
}
if ($LASTEXITCODE -ne 0)
{
Write-Host "Exit Failure: $LASTEXITCODE"
Throw "Failed to build library."
}
}
function BuildUnity()
{
.\build-unity.ps1
if ($LASTEXITCODE -ne 0)
{
Throw "Failed to build unity package."
}
}
function BuildDocs()
{
Write-Host "Removing Doc Folder"
Remove-Item -Path docs -Recurse
Write-Host "Building Documentation"
.\build-docs.ps1
if ($LASTEXITCODE -ne 0)
{
Throw "Failed to build docs."
}
if ($ReleaseDocs)
{
Write-Host "Configuring Git Credentials"
git config --global credential.helper store
Add-Content "$HOME\.git-credentials" "https://$($env:access_token):[email protected]`n"
git config --global user.email "$($env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL)"
git config --global user.name "Lachee - AppVeyor"
git config core.autocrlf true
Write-Host "Commiting Changes"
git add -A
git status
git commit -m "Doc Changes"
git show-ref
Write-Host "Pushing Changes"
git push -f origin HEAD:gh-pages
}
}
#Build the library
if (!($IgnoreLibraryBuild)) {
Write-Host ">>> Building Library";
BuildLibrary $BuildCount $BuildTag $MakeNugetPackage
if ($LASTEXITCODE -ne 0)
{
throw "Error occured while building the project.";
}
}
#Build the Unity package
if ($MakeUnityPackage)
{
Write-Host ">>> Building Unity Package";
BuildUnity
if ($LASTEXITCODE -ne 0)
{
throw "Error occured while building the unity package.";
}
}
#Build the documentation
if ($MakeDocs)
{
Write-Host ">>> Building Documenation";
BuildDocs
if ($LASTEXITCODE -ne 0)
{
throw "Error occured while building the docs.";
}
}
#Gather artifacts
Write-Host ">>> Copying Packages";
GatherArtifacts "./artifacts/net35" "Release/net35" $MakeUnityPackage $MakeNugetPackage
GatherArtifacts "./artifacts/netstandard2.0" "Release/netstandard2.0" $MakeUnityPackage $MakeNugetPackage
Write-Host ">>> Build Complete"