Skip to content

Commit 935cd6c

Browse files
committed
(build) change build.ps1 to run the new build infra
1 parent a3bf796 commit 935cd6c

File tree

2 files changed

+7
-165
lines changed

2 files changed

+7
-165
lines changed

build.ps1

Lines changed: 6 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,23 @@
11
#!/usr/bin/pwsh
2-
##########################################################################
3-
# This is the Cake bootstrapper script for PowerShell.
4-
# This file was downloaded from https://github.com/cake-build/resources
5-
# Feel free to change this file to fit your needs.
6-
##########################################################################
7-
82
<#
9-
10-
.SYNOPSIS
11-
This is a Powershell script to bootstrap a Cake build.
12-
13-
.DESCRIPTION
14-
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
15-
and execute your Cake build script with the parameters you provide.
16-
17-
.PARAMETER Script
18-
The build script to execute.
3+
.PARAMETER Stage
4+
The build stage to execute.
195
.PARAMETER Target
206
The build script target to run.
21-
.PARAMETER Configuration
22-
The build configuration to use.
23-
.PARAMETER DockerDistro
24-
The docker ditro to use.
25-
.PARAMETER DockerDotnetVersion
26-
The dotnet version for docker to use.
27-
.PARAMETER SkipUnitTest
28-
Skip executing the tests.
297
.PARAMETER Verbosity
308
Specifies the amount of information to be displayed.
319
.PARAMETER WhatIf
3210
Performs a dry run of the build script.
3311
No tasks will be executed.
3412
.PARAMETER ScriptArgs
3513
Remaining arguments are added here.
36-
37-
.LINK
38-
https://cakebuild.net
3914
#>
4015

4116
[CmdletBinding()]
4217
Param(
43-
[string]$Script = "build.cake",
18+
[ValidateSet("artifacts", "build", "docker", "docs", "publish", "release")]
19+
[string]$Stage = "build",
4420
[string]$Target = "Default",
45-
[string]$Configuration = "Release",
46-
[string]$DockerDistro = "",
47-
[string]$DockerDotnetVersion = "",
48-
[switch]$SkipUnitTest,
49-
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
5021
[string]$Verbosity = "Normal",
5122
[Alias("DryRun","Noop")]
5223
[switch]$WhatIf,
@@ -55,159 +26,30 @@ Param(
5526
[string[]]$ScriptArgs
5627
)
5728

58-
Write-Host "Preparing to run build script..."
59-
$DotNetInstallerUri = 'https://dot.net/v1/dotnet-install.ps1';
60-
$DotNetUnixInstallerUri = 'https://dot.net/v1/dotnet-install.sh'
61-
$DotNetChannel = 'LTS'
62-
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
63-
64-
[string[]] $DotNetVersion= ''
65-
foreach($line in Get-Content (Join-Path $PSScriptRoot 'build' 'build.config'))
66-
{
67-
if ($line -like 'DOTNET_VERSION=*') {
68-
$DotNetVersion = $line.SubString("DOTNET_VERSION=".Length).Split(',')
69-
}
70-
}
71-
72-
# Make sure tools folder exists
73-
$ToolPath = Join-Path $PSScriptRoot "tools"
74-
if (!(Test-Path $ToolPath)) {
75-
Write-Verbose "Creating tools directory..."
76-
New-Item -Path $ToolPath -Type Directory -Force | out-null
77-
}
78-
79-
# SSL FIX
80-
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
81-
82-
###########################################################################
83-
# INSTALL .NET CORE CLI
84-
###########################################################################
85-
86-
Function Remove-PathVariable([string]$VariableToRemove)
87-
{
88-
$SplitChar = ';'
89-
if ($IsMacOS -or $IsLinux) {
90-
$SplitChar = ':'
91-
}
92-
93-
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
94-
if ($path -ne $null)
95-
{
96-
$newItems = $path.Split($SplitChar, [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
97-
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join($SplitChar, $newItems), "User")
98-
}
99-
100-
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
101-
if ($path -ne $null)
102-
{
103-
$newItems = $path.Split($SplitChar, [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
104-
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join($SplitChar, $newItems), "Process")
105-
}
106-
}
107-
108-
Function Add-PathVariable([string]$PathToAdd)
109-
{
110-
$SplitChar = ';'
111-
if ($IsMacOS -or $IsLinux) {
112-
$SplitChar = ':'
113-
}
114-
115-
$env:PATH = "$($PathToAdd)$($SplitChar)$env:PATH"
116-
}
117-
118-
Function Install-Dotnet($DotNetVersion)
119-
{
120-
#if (!(Check-DotnetInstalled $DotNetVersion))
121-
#{
122-
if ($IsMacOS -or $IsLinux) {
123-
$ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
124-
if (!(Test-Path $ScriptPath)) {
125-
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
126-
}
127-
128-
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path
129-
}
130-
else {
131-
$ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
132-
if (!(Test-Path $ScriptPath)) {
133-
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath);
134-
}
135-
136-
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
137-
}
138-
#}
139-
}
140-
141-
Function Check-DotnetInstalled($version)
142-
{
143-
if (Get-Command dotnet -errorAction SilentlyContinue)
144-
{
145-
$sdk = dotnet --list-sdks
146-
$result = $sdk | ? { $v = $_.Split(" ")[0]; $v -eq $version }
147-
if ($result -ne $null)
148-
{
149-
Write-Host "The dotnet version $version was installed globally, not installing";
150-
return $true;
151-
}
152-
}
153-
return $false;
154-
}
155-
156-
# Get .NET Core CLI path if installed.
157-
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
158-
if (!(Test-Path $InstallPath)) {
159-
New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null;
160-
}
161-
162-
foreach($version in $DotNetVersion)
163-
{
164-
Install-Dotnet $version
165-
}
166-
167-
Remove-PathVariable "$InstallPath"
168-
Add-PathVariable "$InstallPath"
169-
$env:DOTNET_ROOT=$InstallPath
170-
17129
$env:DOTNET_ROLL_FORWARD="major"
17230
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
17331
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
17432
$env:DOTNET_NOLOGO=$true
17533

176-
# Install cake local tool
177-
dotnet tool restore
178-
17934
# ###########################################################################
18035
# RUN BUILD SCRIPT
18136
# ###########################################################################
18237

18338
# Build the argument list.
184-
185-
$env:ENABLED_UNIT_TESTS = !$SkipUnitTest
186-
if ($env:ENABLED_DIAGNOSTICS -and $env:ENABLED_DIAGNOSTICS -eq $true) {
187-
Write-Host "Diagnostics enabled: Yes"
188-
$Verbosity = "Diagnostic"
189-
} else {
190-
Write-Host "Diagnostics enabled: No"
191-
}
192-
19339
$Arguments = @{
19440
target=$Target;
195-
configuration=$Configuration;
19641
verbosity=$Verbosity;
19742
dryrun=$WhatIf;
19843
exclusive=$Exclusive;
19944
nuget_useinprocessclient=$true;
200-
docker_distro=$DockerDistro;
201-
docker_dotnetversion=$DockerDotnetVersion;
20245
}.GetEnumerator() | ForEach-Object {
20346
if ($_.value -ne "") { "--{0}=`"{1}`"" -f $_.key, $_.value }
20447
};
20548

20649
# Start Cake
207-
Write-Host "Running build script..."
50+
Write-Host "Running build stage $Stage..."
20851

209-
& dotnet run --project build/Build.csproj -- $Arguments
210-
# & dotnet cake $Script $Arguments
52+
& dotnet run --project build/$Stage/$Stage.csproj -- $Arguments
21153

21254
if ($env:APPVEYOR) {
21355
$host.SetShouldExit($LASTEXITCODE)

build/common/Tasks/Default.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override void Run(ICakeContext context)
2020
context.Information($"Available targets:{Environment.NewLine}");
2121
foreach (var task in tasks)
2222
{
23-
context.Information($"./build.ps1 --stage={entryAssembly?.GetName().Name} --target={task.GetTaskName()} # ({task.GetTaskDescription()})");
23+
context.Information($"./build.ps1 -Stage {entryAssembly?.GetName().Name} -Target {task.GetTaskName()} # ({task.GetTaskDescription()})");
2424
}
2525
}
2626
}

0 commit comments

Comments
 (0)