Skip to content

Instantly share code, notes, and snippets.

View devlead's full-sized avatar

Mattias Karlsson devlead

View GitHub Profile
@devlead
devlead / taskname.cake
Created November 25, 2020 14:19
Example use task setup/teardown to modify build state
public class BuildData
{
public string TaskName { get; set; }
}
Setup(context => new BuildData());
TaskSetup<BuildData>(
(context, data) => data.TaskName = context.Task.Name
);
@devlead
devlead / .gitignore
Last active October 5, 2020 06:07
Fluent Tasks
[Tt]ools/
[Aa]rtifacts/
[Oo]bj/
[Bb]in/
.vscode/
@devlead
devlead / teardown_errorlog.cake
Last active February 10, 2020 18:06
teardown_errorlog.cake
Task("BOOM")
.Does(() => throw new Exception("BOOM"));
Teardown(ctx => {
for(var i = 1; i <= 15; i++)
{
Information("Teardown {0}", i);
}
});
@devlead
devlead / build.ps1
Last active January 14, 2020 11:42
$CakeVersion = "0.34.1"
if (![string]::IsNullOrWhiteSpace($env:CAKE_VERSION))
{
$CakeVersion = $env:CAKE_VERSION
}
$IsRunningOnUnix = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Unix
# Make sure tools folder exists
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$ToolPath = Join-Path $PSScriptRoot "tools"
if (!(Test-Path $ToolPath)) {
// Switch expression
static string ToLevel(this Verbosity verbosity)
=> verbosity switch
{
Verbosity.Diagnostic => "[****]",
Verbosity.Verbose => "[*** ]",
Verbosity.Normal => "[** ]",
Verbosity.Minimal => "[* ]",
Verbosity.Quiet => "[ ]",
_ => throw new ArgumentOutOfRangeException(message: "invalid enum value",
@devlead
devlead / HelloWorld.s
Created July 31, 2019 08:30
Amiga HelloWorld
ExecBase = 4 ;location of the exec.lib
OpenLib = -552 ;offset to the openLibrary function
OpenLibVersion = 34 ;minimum version to use
CloseLib = -414 ;offset to closeLibrary function
PutString = -948 ;offset to putStr() function
MOVE.L #OpenLibVersion,D0 ;place version of lib in data reg 0
LEA DosName,A1 ;place dos.lib name into add reg 1
MOVE.L ExecBase,A6 ;point to exec.lib's jump table
JSR OpenLib(A6) ;make the jump from exec.lib jump table
TST.L D0 ;check to see if D0 equals zero (fail)
@devlead
devlead / Async.cake
Created July 9, 2017 18:43
Sample of using async await in a cake script using a AsyncHelper class to work with all async scenarios, currently needs "--Experimental" flag or to use the Cake.CoreCLR runner as a newer version of Roslyn is required for async to be recognized. Example invocation: cake .\AsyncHelper.cake -Experimental
#load "AsyncHelper.cake"
#r "System.Net.Http"
using System.Net.Http;
using System.Net.Http.Headers;
string url = "https://icanhazdadjoke.com/";
var result = AsyncHelpers.RunSync(
async ()=> {
using(var client = new HttpClient())
@devlead
devlead / csc.cake
Created May 18, 2017 07:17
Example utilize csc.exe from cake
DirectoryPath projectPath = MakeAbsolute(Directory("./cscTest"));
DirectoryPath outputPath = projectPath.Combine("bin/Debug");
FilePath asssemblyPath = outputPath.CombineWithFilePath("Test.dll"),
symbolsPath = outputPath.CombineWithFilePath("Test.pdb");
FilePath[] references = new FilePath[0]; // add any assembly dependencies
Task("Clean")
.Does(() => {
@devlead
devlead / DynamicTest.csproj
Last active August 21, 2020 19:10
Example .NET Core app create objects from type name
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
@devlead
devlead / a.cake
Created November 2, 2016 22:59
Sample Cake Inject Task dependency
var taskA = Task("A")
.Does(()=>Information("Hello from A"));