Skip to content

Commit

Permalink
added a test/demo to test the module
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-a committed Jul 29, 2024
1 parent c99b4db commit bd5542c
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 0 deletions.
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!");
}
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", "Default");

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

RunTarget(target);
20 changes: 20 additions & 0 deletions demo/dsl/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 $_
}
}

dotnet cake prepare.cake
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

dotnet cake build.cake @args
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
23 changes: 23 additions & 0 deletions demo/dsl/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/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 ""
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/
29 changes: 29 additions & 0 deletions demo/dsl/prepare.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

const string tfm = "net6.0";

private DirectoryPath GetModulesPath()
{
var env = Context.Environment;
var root = Directory(".").Path.MakeAbsolute(env);
return Context.Configuration.GetModulePath(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}";
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");

0 comments on commit bd5542c

Please sign in to comment.