1
1
# !/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
-
8
2
<#
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.
19
5
. PARAMETER Target
20
6
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.
29
7
. PARAMETER Verbosity
30
8
Specifies the amount of information to be displayed.
31
9
. PARAMETER WhatIf
32
10
Performs a dry run of the build script.
33
11
No tasks will be executed.
34
12
. PARAMETER ScriptArgs
35
13
Remaining arguments are added here.
36
-
37
- . LINK
38
- https://cakebuild.net
39
14
#>
40
15
41
16
[CmdletBinding ()]
42
17
Param (
43
- [string ]$Script = " build.cake" ,
18
+ [ValidateSet (" artifacts" , " build" , " docker" , " docs" , " publish" , " release" )]
19
+ [string ]$Stage = " build" ,
44
20
[string ]$Target = " Default" ,
45
- [string ]$Configuration = " Release" ,
46
- [string ]$DockerDistro = " " ,
47
- [string ]$DockerDotnetVersion = " " ,
48
- [switch ]$SkipUnitTest ,
49
- [ValidateSet (" Quiet" , " Minimal" , " Normal" , " Verbose" , " Diagnostic" )]
50
21
[string ]$Verbosity = " Normal" ,
51
22
[Alias (" DryRun" , " Noop" )]
52
23
[switch ]$WhatIf ,
@@ -55,159 +26,30 @@ Param(
55
26
[string []]$ScriptArgs
56
27
)
57
28
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
-
171
29
$env: DOTNET_ROLL_FORWARD = " major"
172
30
$env: DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
173
31
$env: DOTNET_CLI_TELEMETRY_OPTOUT = 1
174
32
$env: DOTNET_NOLOGO = $true
175
33
176
- # Install cake local tool
177
- dotnet tool restore
178
-
179
34
# ###########################################################################
180
35
# RUN BUILD SCRIPT
181
36
# ###########################################################################
182
37
183
38
# 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
-
193
39
$Arguments = @ {
194
40
target = $Target ;
195
- configuration = $Configuration ;
196
41
verbosity = $Verbosity ;
197
42
dryrun = $WhatIf ;
198
43
exclusive = $Exclusive ;
199
44
nuget_useinprocessclient = $true ;
200
- docker_distro = $DockerDistro ;
201
- docker_dotnetversion = $DockerDotnetVersion ;
202
45
}.GetEnumerator() | ForEach-Object {
203
46
if ($_.value -ne " " ) { " --{0}=`" {1}`" " -f $_.key , $_.value }
204
47
};
205
48
206
49
# Start Cake
207
- Write-Host " Running build script ..."
50
+ Write-Host " Running build stage $Stage ..."
208
51
209
- & dotnet run -- project build/ Build.csproj -- $Arguments
210
- # & dotnet cake $Script $Arguments
52
+ & dotnet run -- project build/ $Stage / $Stage.csproj -- $Arguments
211
53
212
54
if ($env: APPVEYOR ) {
213
55
$host.SetShouldExit ($LASTEXITCODE )
0 commit comments