Skip to content

Commit

Permalink
Merge pull request cake-build#2875 from devlead/feature/cake-buildgh-…
Browse files Browse the repository at this point in the history
…2874

GH2874: Merge Frosting into Cake
  • Loading branch information
gep13 authored Oct 15, 2020
2 parents 0b44e97 + 35f2de7 commit 11dc243
Show file tree
Hide file tree
Showing 125 changed files with 5,612 additions and 5 deletions.
61 changes: 59 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ Task("Create-NuGet-Packages")
.Does<BuildParameters>((context, parameters) =>
{
// Build libraries
var projects = GetFiles("./src/**/*.csproj");
var projects = GetFiles("./src/*/*.csproj");
foreach(var project in projects)
{
var name = project.GetDirectory().FullPath;
if(name.EndsWith("Cake") || name.EndsWith("Tests"))
if(name.EndsWith("Cake") || name.EndsWith("Tests") || name.EndsWith("Example"))
{
continue;
}
Expand Down Expand Up @@ -585,8 +585,65 @@ Task("Prepare-Integration-Tests")
CopyDirectory(parameters.Paths.Directories.ArtifactsBinNetCore, parameters.Paths.Directories.IntegrationTestsBinNetCore);
});

Task("Frosting-Integration-Tests")
.DeferOnError()
.DoesForEach<BuildParameters, (string Framework, FilePath Project)>(
(parameters, context) => {
var project = context.MakeAbsolute(
new FilePath("tests/integration/Cake.Frosting/build/Build.csproj")
);
DotNetCoreBuild(project.FullPath,
new DotNetCoreBuildSettings
{
Verbosity = DotNetCoreVerbosity.Quiet,
Configuration = parameters.Configuration,
MSBuildSettings = parameters.MSBuildSettings
});
context.Verbose("Peeking into {0}...", project);
var targetFrameworks = context.XmlPeek(
project,
"/Project/PropertyGroup/TargetFrameworks"
);
return targetFrameworks?.Split(';')
.Where(targetFramework => context.IsRunningOnWindows()
|| !targetFramework.StartsWith("net4", StringComparison.OrdinalIgnoreCase))
.Select(targetFramework => (targetFramework, project))
.ToArray();
},
(parameters, test, context) =>
{
try
{
Information("Testing: {0}", test.Framework);
DotNetCoreRun(test.Project.FullPath,
new ProcessArgumentBuilder()
.AppendSwitchQuoted("--verbosity", "=", "quiet"),
new DotNetCoreRunSettings
{
Configuration = parameters.Configuration,
Framework = test.Framework,
NoRestore = true,
NoBuild = true
});
}
catch(Exception ex)
{
Error("While testing: {0}\r\n{1}", test.Framework, ex);
throw new Exception($"Exception while testing: {test.Framework}", ex);
}
finally
{
Information("Done testing: {0}", test.Framework);
}
});
Task("Run-Integration-Tests")
.IsDependentOn("Prepare-Integration-Tests")
.IsDependentOn("Frosting-Integration-Tests")
.DeferOnError()
.DoesForEach<BuildParameters, FilePath>(
parameters => new[] {
Expand Down
10 changes: 9 additions & 1 deletion build/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ public class BuildParameters
new [] { "cake.portable" });

var releaseNotes = string.Join("\n", ReleaseNotes.Notes.ToArray()).Replace("\"", "\"\"");
MSBuildSettings = new DotNetCoreMSBuildSettings()
MSBuildSettings = new DotNetCoreMSBuildSettings
{
WarningCodesAsMessage = { "NETSDK1138" } // EolTargetFrameworks
}
.WithProperty("Version", Version.SemVersion)
.WithProperty("AssemblyVersion", Version.Version)
.WithProperty("FileVersion", Version.Version)
.WithProperty("PackageReleaseNotes", string.Concat("\"", releaseNotes, "\""));

if (!IsLocalBuild)
{
MSBuildSettings.WithProperty("TemplateVersion", Version.SemVersion);
}
}

private static bool IsBuildTagged(BuildSystem buildSystem)
Expand Down
16 changes: 16 additions & 0 deletions src/Cake.Frosting.Example/Cake.Frosting.Example.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp2.0;netcoreapp2.1;netcoreapp3.0;net5.0</TargetFrameworks>
<AssemblyName>Cake.Frosting.Example</AssemblyName>
<OutputType>Exe</OutputType>
<LangVersion>7</LangVersion>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\Shared.msbuild" />

<ItemGroup>
<ProjectReference Include="..\Cake.Frosting\Cake.Frosting.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions src/Cake.Frosting.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Cake.Frosting.Example
{
public class Program
{
public static int Main(string[] args)
{
// Create the host.
var host = new CakeHostBuilder()
.UseStartup<Startup>()
.WithArguments(args)
.Build();

// Run the host.
return host.Run();
}
}

public class Startup : IFrostingStartup
{
public void Configure(ICakeServices services)
{
services.UseContext<Settings>();
}
}
}
21 changes: 21 additions & 0 deletions src/Cake.Frosting.Example/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Cake.Core;

namespace Cake.Frosting.Example
{
public class Settings : FrostingContext
{
public bool Magic { get; set; }

public Settings(ICakeContext context)
: base(context)
{
// You could also use a CakeLifeTime<Settings>
// to provide a Setup method to setup the context.
Magic = context.Arguments.HasArgument("magic");
}
}
}
47 changes: 47 additions & 0 deletions src/Cake.Frosting.Example/Tasks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Cake.Core;
using Cake.Core.Diagnostics;

namespace Cake.Frosting.Example
{
public sealed class Hello : FrostingTask<Settings>
{
}

[Dependency(typeof(Hello))]
public sealed class World : AsyncFrostingTask<Settings>
{
// Tasks can be asynchronous
public override async Task RunAsync(Settings context)
{
context.Log.Information("About to do something expensive");
await Task.Delay(1500);
context.Log.Information("Done");
}
}

[Dependency(typeof(World))]
public sealed class Magic : FrostingTask<Settings>
{
public override bool ShouldRun(Settings context)
{
// Don't run this task on OSX.
return context.Environment.Platform.Family != PlatformFamily.OSX;
}

public override void Run(Settings context)
{
context.Log.Information("Value is: {0}", context.Magic);
}
}

[TaskName("Default")]
[Dependency(typeof(Magic))]
public class DefaultTask : FrostingTask
{
}
}
30 changes: 30 additions & 0 deletions src/Cake.Frosting.Template/Cake.Frosting.Template.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageType>Template</PackageType>
<AssemblyName>Cake.Frosting.Template</AssemblyName>
<Title>Cake.Frosting templates for the .NET SDK.</Title>
<Description>Cake.Frosting templates for the .NET SDK.</Description>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
<NoWarn>NU5110;NU5111;NU5128</NoWarn>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\Shared.msbuild" />

<ItemGroup>
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" />
<Content Include="../../build.config" Link="templates/cakefrosting/build.config" PackagePath="/content/templates/cakefrosting/build.config" />
<Content Include="build.ps1" Link="templates/cakefrosting/build.ps1" PackagePath="/content/templates/cakefrosting/build.ps1" />
<Content Include="build.sh" Link="templates/cakefrosting/build.sh" PackagePath="/content/templates/cakefrosting/build.sh" />
<Compile Remove="**\*" />
</ItemGroup>

<Target Name="VersionBuild" BeforeTargets="PrepareForBuild" Condition="'$(TemplateVersion)'!=''">
<XmlPoke XmlInputPath="templates\cakefrosting\build\Build.csproj" Query="Project/ItemGroup/PackageReference/@Version" Value="$(TemplateVersion)" />
</Target>

</Project>
70 changes: 70 additions & 0 deletions src/Cake.Frosting.Template/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env pwsh
$DotNetInstallerUri = 'https://dot.net/v1/dotnet-install.ps1';
$DotNetUnixInstallerUri = 'https://dot.net/v1/dotnet-install.sh'
$DotNetChannel = 'LTS'
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent

[string] $DotNetVersion= ''
foreach($line in Get-Content (Join-Path $PSScriptRoot 'build.config'))
{
if ($line -like 'DOTNET_VERSION=*') {
$DotNetVersion =$line.SubString(15)
}
}


if ([string]::IsNullOrEmpty($DotNetVersion)) {
'Failed to parse .NET Core SDK Version'
exit 1
}

$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1";

# Make sure tools folder exists
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$ToolPath = Join-Path $PSScriptRoot "tools"
if (!(Test-Path $ToolPath)) {
Write-Verbose "Creating tools directory..."
New-Item -Path $ToolPath -Type directory | out-null
}

###########################################################################
# INSTALL .NET CORE CLI
###########################################################################

Function Remove-PathVariable([string]$VariableToRemove)
{
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
$newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
$newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
}

# Get .NET Core CLI path if installed.
$FoundDotNetCliVersion = $null;
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
$FoundDotNetCliVersion = dotnet --version;
}

if($FoundDotNetCliVersion -ne $DotNetVersion) {
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
if (!(Test-Path $InstallPath)) {
mkdir -Force $InstallPath | Out-Null;
}
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
& $InstallPath\dotnet-install.ps1 -Version $DotNetVersion -InstallDir $InstallPath;

Remove-PathVariable "$InstallPath"
$env:PATH = "$InstallPath;$env:PATH"
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
}

###########################################################################
# RUN BUILD SCRIPT
###########################################################################

dotnet run --project build/Build.csproj -- $args
exit $LASTEXITCODE;
38 changes: 38 additions & 0 deletions src/Cake.Frosting.Template/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Define varibles
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPT_DIR/build.config

if [ "$DOTNET_VERSION" = "" ]; then
echo "An error occured while parsing .NET Core SDK version."
exit 1
fi

###########################################################################
# INSTALL .NET CORE CLI
###########################################################################

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
export DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2

DOTNET_INSTALLED_VERSION=$(dotnet --version 2>&1)

if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then
echo "Installing .NET CLI..."
if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then
mkdir "$SCRIPT_DIR/.dotnet"
fi
curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://dot.net/v1/dotnet-install.sh
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --install-dir .dotnet --no-path
export PATH="$SCRIPT_DIR/.dotnet":$PATH
export DOTNET_ROOT="$SCRIPT_DIR/.dotnet"
fi

###########################################################################
# RUN BUILD SCRIPT
###########################################################################

echo "Running build script.."
dotnet run --project ./build/Build.csproj -- "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"author": "Patrik Svensson, Mattias Karlsson, Gary Ewan Park, Alistair Chapman, Martin Björkström, Dave Glick, Pascal Berger, Jérémie Desautels, Enrico Campidoglio and contributors",
"classifications": [ "Cake", "Frosting" ],
"name": "Cake Frosting Build Script",
"identity": "Cake.Frosting",
"shortName": "cakefrosting",
"sourceName": "temp",
"tags": {
"language": "C#"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackAsTool>true</PackAsTool>
<!-- Make sure start same folder .NET Core CLI and Visual Studio -->
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="1.0.0" />
</ItemGroup>
</Project>
Loading

0 comments on commit 11dc243

Please sign in to comment.