Skip to content

Commit

Permalink
Merge pull request #64 from nils-a/release/4.0.0
Browse files Browse the repository at this point in the history
Release/4.0.0
  • Loading branch information
nils-a authored Jul 31, 2024
2 parents 6af6fa6 + d1bea01 commit 48bee16
Show file tree
Hide file tree
Showing 18 changed files with 237 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- "feature/**"
- "release/**"
- "hotfix/**"
- "support/**"
tags:
- "*"
paths-ignore:
Expand Down
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<CakeVersion>3.0.0</CakeVersion>
<CakeVersion>4.0.0</CakeVersion>
</PropertyGroup>
</Project>
13 changes: 13 additions & 0 deletions demo/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"cake.tool": {
"version": "4.0.0",
"commands": [
"dotnet-cake"
],
"rollForward": false
}
}
}
3 changes: 3 additions & 0 deletions demo/choco-source/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.exe
!*.nupkg
// do not exlude the nupkg - we need it for testing and don't want to have to rebuild it every time
53 changes: 53 additions & 0 deletions demo/choco-source/build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var target = Argument("target", "Default");

Task("Clean")
.Does(() =>
{
DeleteFiles("**/*.exe");
DeleteFiles("**/*.nupkg");
});

Task("Build-EXEs")
.DoesForEach(GetFiles("**/*.rs"), (f) =>
{
using(var p = StartAndReturnProcess("rustc", new ProcessSettings
{
Arguments = f.FullPath
}))
{
p.WaitForExit();
if(p.GetExitCode() != 0)
{
throw new Exception($"Failed to compile {f.FullPath}");
}

var exe = f.GetFilenameWithoutExtension() + ".exe";
MoveFile(exe, $"cake-demo/tools/{exe}");
}
});

Task("Build-Choco")
.IsDependentOn("Build-EXEs")
.Does(() =>
{
using(var p = StartAndReturnProcess("choco", new ProcessSettings
{
Arguments = "pack",
WorkingDirectory = "cake-demo",
}))
{
p.WaitForExit();
if(p.GetExitCode() != 0)
{
throw new Exception("Failed to pack choco package");
}

MoveFiles(GetFiles("**/*.nupkg"), "./");
}
});

Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Build-Choco");

RunTarget(target);
13 changes: 13 additions & 0 deletions demo/choco-source/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$ErrorActionPreference = 'Stop'

Set-Location -LiteralPath $PSScriptRoot

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
$env:DOTNET_NOLOGO = '1'

dotnet tool restore
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

dotnet cake build.cake @args
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Binary file added demo/choco-source/cake-demo.0.1.0.nupkg
Binary file not shown.
11 changes: 11 additions & 0 deletions demo/choco-source/cake-demo/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Summary

This is the test-package, to be used in tests with Cake.Chocolatey.Module.
It contains the following parts:

- The choco package
- hello-world.exe
This exe does nothing really, but it can be used as a simple tool in tests.
- build.cake
This script builds the hello-world.exe (using rust) and then creates the choco package
The choco package is "checked in" - so it does not need to be re-created every time.
18 changes: 18 additions & 0 deletions demo/choco-source/cake-demo/cake-demo.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>cake-demo</id>
<version>0.1.0</version>
<owners>nils-a</owners>
<title>cake-demo (Portable)</title>
<authors>Nils Andresen</authors>
<projectUrl>https://github.com/cake-contrib/Cake.Chocolatey.Module</projectUrl>
<copyright>2024 - present Cake Contributors</copyright>
<tags>cake choco demo not-a-real-package do-not-use</tags>
<summary>This is only a demo project to be used in the Cake.Chocolatey.Module demo</summary>
<description>This is only a demo project to be used in the Cake.Chocolatey.Module demo</description>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
8 changes: 8 additions & 0 deletions demo/choco-source/cake-demo/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$ErrorActionPreference = 'Stop' # stop on all errors
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"

## Adding a shim when not automatically found - Chocolatey automatically shims exe files found in package directory.
## - https://docs.chocolatey.org/en-us/create/functions/install-binfile
## - https://docs.chocolatey.org/en-us/create/create-packages#how-do-i-exclude-executables-from-getting-shims
#Install-BinFile

3 changes: 3 additions & 0 deletions demo/choco-source/hello-world/hello.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, World!");
}
1 change: 1 addition & 0 deletions demo/dsl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.toolpath.env
12 changes: 12 additions & 0 deletions demo/dsl/build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// do not reference Cake.Chocolatey.Module.dll directly, prepare.cake will place it in the modules folder
#tool choco:?package=cake-demo&version=0.1.0

var target = Argument("target", "Build");

Task("Build")
.Does(() =>
{
StartProcess("hello.exe");
});

RunTarget(target);
34 changes: 34 additions & 0 deletions demo/dsl/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Set-Location -LiteralPath $PSScriptRoot

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
$env:DOTNET_NOLOGO = '1'

dotnet tool restore
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

@("tools", ".cake") | % {
if (Test-Path $_) {
Remove-Item -Recurse -Force $_
}
}

Write-Host "`npreparing the module`n"
dotnet cake prepare.cake
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

# Set the choco dir to somethin local, so installing the test package
# does not screw up your system. We'll need this only on windows
# so, adding it to the .ps1 is probably enough.
$toolPath = "$(pwd)/tools"
if (Test-Path .toolpath.env) {
# that file is written by the prepare.cake script
$toolPath = Get-Content .toolpath.env
}
$chocoPath = "$toolPath/choco"
Write-Host "`nSetting ChocolateyInstallDir to $chocoPath`n"
Remove-Item -Path $chocoPath -Force -ErrorAction Ignore
$env:ChocolateyInstallDir = "$chocoPath"
Write-Host "`nNow running the build script`n"
dotnet cake build.cake @args
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
24 changes: 24 additions & 0 deletions demo/dsl/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_NOLOGO=1

dotnet tool restore

rm -rf tools 2>/dev/null || true
rm -rf .cake 2>/dev/null || true

echo ""
echo "preparing the module"
echo ""
dotnet cake prepare.cake

echo ""
echo "Now running the build script"
echo ""
# no need to set the CakeInstallDir, as
dotnet cake build.cake "$@"
4 changes: 4 additions & 0 deletions demo/dsl/cake.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; The configuration file for Cake.

[Chocolatey]
Source=../choco-source/
37 changes: 37 additions & 0 deletions demo/dsl/prepare.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

const string tfm = "net6.0";

private DirectoryPath GetModulesPath()
{
var env = Context.Environment;
var root = Directory(".").Path.MakeAbsolute(env);
return Context.Configuration.GetModulePath(root, env);
}

private DirectoryPath GetToolPath()
{
var env = Context.Environment;
var root = Directory(".").Path.MakeAbsolute(env);
return Context.Configuration.GetToolPath(root, env);
}

Task("Build-Module")
.Does(() =>
{
// dotnet clean will only clean things that will be creted by dotnet build. "old" files will not be removed.
CleanDirectory("../../Source/Cake.Chocolatey.Module/bin");
DotNetBuild("../../Source/Cake.Chocolatey.Module/Cake.Chocolatey.Module.csproj");
var moduleFolder = GetModulesPath();
if(!DirectoryExists(moduleFolder))
{
CreateDirectory(moduleFolder);
}

var target = moduleFolder + $"/Cake.Chocolatey.Module.0.0.0/lib/{tfm}";
System.IO.File.WriteAllText(".toolpath.env", GetToolPath().FullPath);
CleanDirectory(target); // this will NOT WORK if the dll existed before cake was started.
CopyFiles($"../../Source/Cake.Chocolatey.Module/bin/Debug/{tfm}/Cake.Chocolatey.Module.dll", target);
Information("Module copied to " + target);
});

RunTarget("Build-Module");
1 change: 1 addition & 0 deletions demo/dsl/toolspath.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:/_dev/cake/cake-contrib/Cake.Chocolatey.Module/demo/dsl/.cake

0 comments on commit 48bee16

Please sign in to comment.