-
Notifications
You must be signed in to change notification settings - Fork 7
/
Build.ps1
150 lines (131 loc) · 4.35 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
param
(
[Switch]$Archive,
[Switch]$BuildAll,
[String]$CommitID,
[String]$Configuration = "Release",
[Switch]$Clean,
[Switch]$Help,
[String]$Profile,
[Switch]$UseFullCommitID,
[String]$Version
)
$work = $pwd
$profiles = @("win-x86", "win-x64", "linux-x64", "osx-x64")
$buildPaths = @("Marathon.CLI\bin\Publish\")
$patchVersion = ".github\workflows\Patch-Version.ps1"
if ($Help)
{
echo "Marathon Build Script"
echo ""
echo "All your platforms are belong to us."
echo ""
echo "Usage:"
echo "-Archive - archives the build artifacts."
echo "-BuildAll - build Marathon with all available profiles."
echo "-CommitID [id] - set the commit ID to use from GitHub for the version number."
echo "-Configuration [name] - build Marathon with a specific configuration."
echo "-Clean - cleans the solution before building Marathon."
echo "-Help - display help."
echo "-Profile [name] - build Marathon with a specific profile."
echo "-UseFullCommitID - use the full 40 character commit ID for the version number."
echo "-Version [major].[minor].[revision] - set the version number for this build of Marathon."
exit
}
# Check if the .NET SDK is installed.
if (!(Get-Command -Name dotnet -ErrorAction SilentlyContinue))
{
echo ".NET SDK is required to build Marathon."
echo "You can install the required .NET SDK for Windows from here: https://dotnet.microsoft.com/en-us/download/dotnet/8.0"
exit
}
if ([System.String]::IsNullOrEmpty($Version))
{
foreach ($project in [System.IO.Directory]::EnumerateFiles(".", "*.csproj", [System.IO.SearchOption]::AllDirectories))
{
& "${patchVersion}" -ProjectPath "${project}" -Version "1.0.0"
}
}
if ($Clean)
{
dotnet clean
}
function PatchVersionInformation([String]$commitID, [Boolean]$useFullCommitID, [String]$version)
{
# Patch the version number for all projects.
if (![System.String]::IsNullOrEmpty($version))
{
foreach ($project in [System.IO.Directory]::EnumerateFiles(".", "*.csproj", [System.IO.SearchOption]::AllDirectories))
{
& "${patchVersion}" -CommitID $commitID -ProjectPath "${project}" -Version $version
}
}
}
function Build([String]$configuration, [String]$profile)
{
# Patch version number before building.
PatchVersionInformation $CommitID $UseFullCommitID $Version
dotnet publish /p:Configuration="${configuration}" /p:PublishProfile="${profile}"
# Restore default version number.
PatchVersionInformation "" $false "1.0.0"
if ($Archive)
{
foreach ($buildPath in $buildPaths)
{
foreach ($artifact in [System.IO.Directory]::EnumerateDirectories($buildPath))
{
# Creates a full path to the artifact using the current build path and profile name.
$artifactPath = [System.IO.Path]::Combine([System.IO.Directory]::CreateDirectory([System.IO.Path]::Combine($buildPath, "artifacts")).FullName, $buildPath.Split('\')[0] + "-${profile}")
# We only want to archive the most recent build.
if ([System.IO.Path]::GetFileName($artifact) -ne $profile)
{
continue
}
# Enter artifact directory.
cd $artifact
if ($profile.StartsWith("win"))
{
# Use *.zip files for Windows.
Compress-Archive -Force * "${artifactPath}.zip"
}
else
{
# Use *.tar.gz files for Linux and macOS.
tar -c -z -f "${artifactPath}.tar.gz" *
}
# Return to working directory.
cd $work
}
}
}
}
if (![System.String]::IsNullOrEmpty($Profile))
{
if ([System.Array]::IndexOf($profiles, $Profile) -eq -1)
{
echo "No such profile exists: ${Profile}"
exit
}
Build $Configuration $Profile
if (!$BuildAll)
{
exit
}
}
if ($BuildAll)
{
foreach ($currentProfile in $profiles)
{
# Skip profile if it was already specified and built.
if ($currentProfile -eq $Profile)
{
continue
}
Build $Configuration $currentProfile
}
}
else
{
Build $Configuration "win-x86"
Build $Configuration "win-x64"
}