Skip to content

Commit 36964da

Browse files
authored
Upgrade Cake to 2.2.0 (#553)
+semver:patch
1 parent 7f9e74f commit 36964da

File tree

5 files changed

+36
-257
lines changed

5 files changed

+36
-257
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"cake.tool": {
6+
"version": "2.2.0",
7+
"commands": [
8+
"dotnet-cake"
9+
]
10+
}
11+
}
12+
}

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ branches:
2424

2525
# clone_depth: 1
2626
build_script:
27-
- ps: .\build.ps1 -Target AppVeyor -Verbosity Diagnostic
27+
- ps: .\build.ps1 --target AppVeyor --verbosity Diagnostic
2828

2929
test: off
3030

build.cake

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#addin "nuget:?package=Cake.FileHelpers&version=4.0.1"
2-
#tool "nuget:?package=GitReleaseManager&version=0.11.0"
3-
#tool "nuget:?package=GitVersion.CommandLine&version=5.8.1"
1+
#addin "nuget:?package=Cake.FileHelpers&version=5.0.0"
2+
#tool "dotnet:?package=GitReleaseManager.Tool&version=0.13.0"
3+
#tool "dotnet:?package=GitVersion.Tool&version=5.10.3"
44

55
#load "./build/parameters.cake"
66

@@ -66,7 +66,7 @@ Task("Build")
6666
.IsDependentOn("Restore")
6767
.Does(() =>
6868
{
69-
DotNetCoreBuild(SolutionPath, new DotNetCoreBuildSettings
69+
DotNetBuild(SolutionPath, new DotNetCoreBuildSettings
7070
{
7171
Configuration = parameters.Configuration,
7272
MSBuildSettings = msBuildSettings
@@ -83,15 +83,15 @@ Task("Test")
8383

8484
foreach(var project in testProjects)
8585
{
86-
DotNetCoreTest(project.ToString(), new DotNetCoreTestSettings
86+
DotNetTest(project.ToString(), new DotNetCoreTestSettings
8787
{
8888
Framework = "net461",
8989
NoBuild = true,
9090
NoRestore = true,
9191
Configuration = parameters.Configuration
9292
});
9393

94-
DotNetCoreTest(project.ToString(), new DotNetCoreTestSettings
94+
DotNetTest(project.ToString(), new DotNetCoreTestSettings
9595
{
9696
Framework = "net6.0",
9797
NoBuild = true,
@@ -176,13 +176,11 @@ Task("Publish-GitHub-Release")
176176
.Does(() =>
177177
{
178178
GitReleaseManagerAddAssets(
179-
parameters.GitHub.UserName, parameters.GitHub.Password,
180-
parameters.GitHub.Owner, parameters.GitHub.Repository,
179+
parameters.GitHub.Token, parameters.GitHub.Owner, parameters.GitHub.Repository,
181180
parameters.Version.Milestone,
182181
parameters.Paths.Files.ZipArtifactPathDesktop.ToString());
183182
GitReleaseManagerClose(
184-
parameters.GitHub.UserName, parameters.GitHub.Password,
185-
parameters.GitHub.Owner, parameters.GitHub.Repository,
183+
parameters.GitHub.Token, parameters.GitHub.Owner, parameters.GitHub.Repository,
186184
parameters.Version.Milestone);
187185
})
188186
.OnError(exception =>
@@ -195,7 +193,7 @@ Task("Create-Release-Notes")
195193
.Does(() =>
196194
{
197195
GitReleaseManagerCreate(
198-
parameters.GitHub.UserName, parameters.GitHub.Password,
196+
parameters.GitHub.Token,
199197
parameters.GitHub.Owner, parameters.GitHub.Repository,
200198
new GitReleaseManagerCreateSettings {
201199
Milestone = parameters.Version.Milestone,

build.ps1

Lines changed: 9 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -1,235 +1,13 @@
1-
##########################################################################
2-
# This is the Cake bootstrapper script for PowerShell.
3-
# This file was downloaded from https://github.com/cake-build/resources
4-
# Feel free to change this file to fit your needs.
5-
##########################################################################
1+
$ErrorActionPreference = 'Stop'
62

7-
<#
3+
Set-Location -LiteralPath $PSScriptRoot
84

9-
.SYNOPSIS
10-
This is a Powershell script to bootstrap a Cake build.
5+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
6+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
7+
$env:DOTNET_NOLOGO = '1'
118

12-
.DESCRIPTION
13-
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
14-
and execute your Cake build script with the parameters you provide.
9+
dotnet tool restore
10+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
1511

16-
.PARAMETER Script
17-
The build script to execute.
18-
.PARAMETER Target
19-
The build script target to run.
20-
.PARAMETER Configuration
21-
The build configuration to use.
22-
.PARAMETER Verbosity
23-
Specifies the amount of information to be displayed.
24-
.PARAMETER ShowDescription
25-
Shows description about tasks.
26-
.PARAMETER DryRun
27-
Performs a dry run.
28-
.PARAMETER Experimental
29-
Uses the nightly builds of the Roslyn script engine.
30-
.PARAMETER Mono
31-
Uses the Mono Compiler rather than the Roslyn script engine.
32-
.PARAMETER SkipToolPackageRestore
33-
Skips restoring of packages.
34-
.PARAMETER ScriptArgs
35-
Remaining arguments are added here.
36-
37-
.LINK
38-
https://cakebuild.net
39-
40-
#>
41-
42-
[CmdletBinding()]
43-
Param(
44-
[string]$Script = "build.cake",
45-
[string]$Target,
46-
[string]$Configuration,
47-
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
48-
[string]$Verbosity,
49-
[switch]$ShowDescription,
50-
[Alias("WhatIf", "Noop")]
51-
[switch]$DryRun,
52-
[switch]$Experimental,
53-
[switch]$Mono,
54-
[switch]$SkipToolPackageRestore,
55-
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
56-
[string[]]$ScriptArgs
57-
)
58-
59-
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
60-
function MD5HashFile([string] $filePath)
61-
{
62-
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
63-
{
64-
return $null
65-
}
66-
67-
[System.IO.Stream] $file = $null;
68-
[System.Security.Cryptography.MD5] $md5 = $null;
69-
try
70-
{
71-
$md5 = [System.Security.Cryptography.MD5]::Create()
72-
$file = [System.IO.File]::OpenRead($filePath)
73-
return [System.BitConverter]::ToString($md5.ComputeHash($file))
74-
}
75-
finally
76-
{
77-
if ($file -ne $null)
78-
{
79-
$file.Dispose()
80-
}
81-
}
82-
}
83-
84-
function GetProxyEnabledWebClient
85-
{
86-
$wc = New-Object System.Net.WebClient
87-
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
88-
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
89-
$wc.Proxy = $proxy
90-
return $wc
91-
}
92-
93-
Write-Host "Preparing to run build script..."
94-
95-
if(!$PSScriptRoot){
96-
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
97-
}
98-
99-
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
100-
$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins"
101-
$MODULES_DIR = Join-Path $TOOLS_DIR "Modules"
102-
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
103-
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
104-
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
105-
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
106-
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
107-
$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config"
108-
$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
109-
110-
# Make sure tools folder exists
111-
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
112-
Write-Verbose -Message "Creating tools directory..."
113-
New-Item -Path $TOOLS_DIR -Type directory | out-null
114-
}
115-
116-
# Make sure that packages.config exist.
117-
if (!(Test-Path $PACKAGES_CONFIG)) {
118-
Write-Verbose -Message "Downloading packages.config..."
119-
try {
120-
$wc = GetProxyEnabledWebClient
121-
$wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
122-
Throw "Could not download packages.config."
123-
}
124-
}
125-
126-
# Try find NuGet.exe in path if not exists
127-
if (!(Test-Path $NUGET_EXE)) {
128-
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
129-
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) }
130-
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
131-
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
132-
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
133-
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
134-
}
135-
}
136-
137-
# Try download NuGet.exe if not exists
138-
if (!(Test-Path $NUGET_EXE)) {
139-
Write-Verbose -Message "Downloading NuGet.exe..."
140-
try {
141-
$wc = GetProxyEnabledWebClient
142-
$wc.DownloadFile($NUGET_URL, $NUGET_EXE)
143-
} catch {
144-
Throw "Could not download NuGet.exe."
145-
}
146-
}
147-
148-
# Save nuget.exe path to environment to be available to child processed
149-
$ENV:NUGET_EXE = $NUGET_EXE
150-
151-
# Restore tools from NuGet?
152-
if(-Not $SkipToolPackageRestore.IsPresent) {
153-
Push-Location
154-
Set-Location $TOOLS_DIR
155-
156-
# Check for changes in packages.config and remove installed tools if true.
157-
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
158-
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
159-
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
160-
Write-Verbose -Message "Missing or changed package.config hash..."
161-
Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery |
162-
Remove-Item -Recurse
163-
}
164-
165-
Write-Verbose -Message "Restoring tools from NuGet..."
166-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
167-
168-
if ($LASTEXITCODE -ne 0) {
169-
Throw "An error occurred while restoring NuGet tools."
170-
}
171-
else
172-
{
173-
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
174-
}
175-
Write-Verbose -Message ($NuGetOutput | out-string)
176-
177-
Pop-Location
178-
}
179-
180-
# Restore addins from NuGet
181-
if (Test-Path $ADDINS_PACKAGES_CONFIG) {
182-
Push-Location
183-
Set-Location $ADDINS_DIR
184-
185-
Write-Verbose -Message "Restoring addins from NuGet..."
186-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""
187-
188-
if ($LASTEXITCODE -ne 0) {
189-
Throw "An error occurred while restoring NuGet addins."
190-
}
191-
192-
Write-Verbose -Message ($NuGetOutput | out-string)
193-
194-
Pop-Location
195-
}
196-
197-
# Restore modules from NuGet
198-
if (Test-Path $MODULES_PACKAGES_CONFIG) {
199-
Push-Location
200-
Set-Location $MODULES_DIR
201-
202-
Write-Verbose -Message "Restoring modules from NuGet..."
203-
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""
204-
205-
if ($LASTEXITCODE -ne 0) {
206-
Throw "An error occurred while restoring NuGet modules."
207-
}
208-
209-
Write-Verbose -Message ($NuGetOutput | out-string)
210-
211-
Pop-Location
212-
}
213-
214-
# Make sure that Cake has been installed.
215-
if (!(Test-Path $CAKE_EXE)) {
216-
Throw "Could not find Cake.exe at $CAKE_EXE"
217-
}
218-
219-
220-
221-
# Build Cake arguments
222-
$cakeArguments = @("$Script");
223-
if ($Target) { $cakeArguments += "-target=$Target" }
224-
if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
225-
if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
226-
if ($ShowDescription) { $cakeArguments += "-showdescription" }
227-
if ($DryRun) { $cakeArguments += "-dryrun" }
228-
if ($Experimental) { $cakeArguments += "-experimental" }
229-
if ($Mono) { $cakeArguments += "-mono" }
230-
$cakeArguments += $ScriptArgs
231-
232-
# Start Cake
233-
Write-Host "Running build script..."
234-
&$CAKE_EXE $cakeArguments
235-
exit $LASTEXITCODE
12+
dotnet cake @args
13+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

build/credentials.cake

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,27 @@ public class BuildGitHub
33
public string Owner { get; private set; }
44
public string Repository { get; private set; }
55
public string Url => $"https://github.com/{Owner}/{Repository}";
6-
public string UserName { get; private set; }
7-
public string Password { get; private set; }
6+
public string Token { get; private set; }
87

98
public BuildGitHub(
109
string owner,
1110
string repository,
12-
string userName,
13-
string password)
11+
string token)
1412
{
1513
Owner = owner;
1614
Repository = repository;
17-
UserName = userName;
18-
Password = password;
15+
Token = token;
1916
}
2017

2118
public static BuildGitHub GetWithCredentials(ICakeContext context, string owner, string repository)
22-
{
23-
var username = context.EnvironmentVariable("GITHUB_USERNAME");
24-
// if (string.IsNullOrEmpty(username))
25-
// {
26-
// throw new Exception("The GITHUB_USERNAME environment variable is not defined.");
27-
// }
28-
19+
{
2920
var token = context.EnvironmentVariable("GITHUB_TOKEN");
3021
// if (string.IsNullOrEmpty(token))
3122
// {
3223
// throw new Exception("The GITHUB_TOKEN environment variable is not defined.");
3324
// }
3425

35-
return new BuildGitHub(owner, repository, username, token);
26+
return new BuildGitHub(owner, repository, token);
3627
}
3728
}
3829

0 commit comments

Comments
 (0)