Skip to content

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-a committed Nov 30, 2021
2 parents eef873d + 521f1d4 commit b2377e2
Show file tree
Hide file tree
Showing 24 changed files with 332 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -23,16 +23,16 @@ jobs:

steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v2.4.0
- name: Fetch all tags and branches
run: git fetch --prune --unshallow
- name: Cache Tools
uses: actions/cache@v2
uses: actions/cache@v2.1.7
with:
path: tools
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
- name: Build project
uses: cake-build/cake-action@v1
uses: cake-build/cake-action@v1.4.0
with:
script-path: recipe.cake
target: CI
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Expand Up @@ -30,12 +30,12 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v2.4.0
with:
fetch-depth: 0

- name: Cache Tools
uses: actions/cache@v2
uses: actions/cache@v2.1.7
with:
path: tools
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
Expand All @@ -51,7 +51,7 @@ jobs:
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Build project
uses: cake-build/cake-action@v1
uses: cake-build/cake-action@v1.4.0
with:
script-path: recipe.cake
target: DotNetCore-Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-cake.yml
Expand Up @@ -10,4 +10,4 @@ jobs:
runs-on: ubuntu-latest # linux, because this is a docker-action
steps:
- name: check/update cake dependencies
uses: nils-org/dependabot-cake-action@v1
uses: nils-org/dependabot-cake-action@v1.1.0
1 change: 1 addition & 0 deletions demo/frosting/.gitignore
@@ -0,0 +1 @@
tools/
14 changes: 14 additions & 0 deletions demo/frosting/build.ps1
@@ -0,0 +1,14 @@
$ErrorActionPreference = 'Stop'

Set-Location -LiteralPath $PSScriptRoot

# make sure we always get a fresh nuget-package and nothing from cache!
dotnet nuget locals all --clear

if(Test-Path .\build\tools) {
rm -Force -Recurse .\build\tools
}

dotnet add .\build\Build.csproj package Cake.Npm.Module --prerelease
dotnet run --project build\Build.csproj -- $args
exit $LASTEXITCODE;
14 changes: 14 additions & 0 deletions demo/frosting/build/Build.csproj
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="1.2.0" />
<PackageReference Include="Cake.Npm.Module" Version="2.1.0-alpha0052" />
</ItemGroup>
<ItemGroup>
<None Remove="tools\**" />
</ItemGroup>
</Project>
43 changes: 43 additions & 0 deletions demo/frosting/build/Program.cs
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Cake.Common;
using Cake.Common.Diagnostics;
using Cake.Core;
using Cake.Core.IO;
using Cake.Frosting;

public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseModule<Cake.Npm.Module.NpmModule>()
.InstallTool(new Uri("npm://?package=yo&caketools"))
.UseWorkingDirectory("..")
.Run(args);
}
}

[TaskName("Default")]
public class DefaultTask : FrostingTask
{
public override void Run(ICakeContext context)
{
var yo = context.Tools.Resolve(context.IsRunningOnWindows() ? "yo.cmd" : "yo");
if(yo == null) {
context.Error("Something is very wrong.");
throw new Exception("yo not found!");
}
context.Information("yo installed at: " + yo.FullPath);
IEnumerable<string> version;
context.StartProcess(
yo,
new ProcessSettings {
Arguments = "--version",
RedirectStandardOutput = true
},
out version);
context.Information("yo version: " + version.First());
}
}
10 changes: 10 additions & 0 deletions demo/frosting/nuget.config
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
</config>
<packageSources>
<clear />
<add key="local pkg" value="../../BuildArtifacts/Packages/NuGet/" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
12 changes: 12 additions & 0 deletions demo/script/.config/dotnet-tools.json
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"cake.tool": {
"version": "1.2.0",
"commands": [
"dotnet-cake"
]
}
}
}
1 change: 1 addition & 0 deletions demo/script/.gitignore
@@ -0,0 +1 @@
tools/
23 changes: 23 additions & 0 deletions demo/script/build.cake
@@ -0,0 +1,23 @@
#module nuget://?package=Cake.Npm.Module&prerelease
#tool npm://?package=yo&caketools

Task("Default")
.Does(() => {
var yo = Context.Tools.Resolve(IsRunningOnWindows() ? "yo.cmd" : "yo");
if(yo == null) {
Error("Something is very wrong.");
throw new Exception("yo not found!");
}
Information("yo installed at: " + yo.FullPath);
IEnumerable<string> version;
StartProcess(
yo,
new ProcessSettings {
Arguments = "--version",
RedirectStandardOutput = true
},
out version);
Information("yo version: " + version.First());
});

RunTarget("Default");
21 changes: 21 additions & 0 deletions demo/script/build.ps1
@@ -0,0 +1,21 @@
$ErrorActionPreference = 'Stop'

Set-Location -LiteralPath $PSScriptRoot

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

# make sure we always get a fresh nuget-package and nothing from cache!
dotnet nuget locals all --clear

if(Test-Path .\tools) {
rm -Force -Recurse .\tools
}

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

dotnet cake @args
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
10 changes: 10 additions & 0 deletions demo/script/nuget.config
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
</config>
<packageSources>
<clear />
<add key="local pkg" value="../../BuildArtifacts/Packages/NuGet/" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
5 changes: 1 addition & 4 deletions docs/input/doc/cake-npm.md
Expand Up @@ -13,9 +13,6 @@ This module integrates itself into the internals of Cake meaning that tools inst

Conversely, the addin is more flexible, so you can install tools only when required and have more control over when in the script you install your required npm packages. When using the module, every `#tool` is installed every time you run, regardless of whether it's needed. The addin also supports other npm commands like `pack`, `publish` and `run`, while the module only supports `install`.

Finally, remember that while Cake will install addins for you (when using the `#addin` directive), modules need to be installed into the modules directory **before** the script runs. Cake can also do this for you, but it has to be "initialized" manually. Starting Cake with the `--bootstrap`-parameter will restore the modules in the `tools/Modules` folder.


In summary:

**Addin:**
Expand All @@ -32,4 +29,4 @@ In summary:
- Integrated into Cake directly (including tool resolution)
- Allows declaring `#tool` directives alongside other packages (i.e. NuGet, DNF, Chocolatey)

Deciding whether to install your desired packages using the module or the addin will depend on your specific build requirements, your environment and how you intend to use your packages. Remember you can always get help in [the Gitter room](https://gitter.im/cake-build/cake) if you have any questions about the addin or module.
Deciding whether to install your desired packages using the module or the addin will depend on your specific build requirements, your environment and how you intend to use your packages. Remember you can always get help at [the discussion board](https://github.com/cake-build/cake/discussions) if you have any questions about the addin or module.
2 changes: 1 addition & 1 deletion docs/input/doc/examples.md
Expand Up @@ -29,4 +29,4 @@ or to tell npm to use a SemVer-compliant range
#tool npm:?package=sax&version=">=0.1.0 <0.2.0"
```

Full parameter information is covered in the [parameters documentation](parameters.md).
Full parameter information is covered in the [parameters documentation](parameters).
2 changes: 1 addition & 1 deletion docs/input/doc/install.md
Expand Up @@ -12,7 +12,7 @@ Due to the fact that Cake Modules are extending and altering the internals of Ca
```
#module nuget:?package=Cake.Npm.Module&version=<version>
```
1. Run the build with argument `--bootstrap` (i.e. `./build.ps1 --bootrap`).
1. For Cake versions before `1.0.0`, run the build with argument `--bootstrap` (i.e. `./build.ps1 --bootrap`).

This will restore the module assembly into the `tools/Modules` folder
1. Run the build as normal. During Cake's execution, it will recognise the module assembly which has been restored into the `tools/Modules` folder, and load it.
Expand Down
12 changes: 12 additions & 0 deletions docs/input/doc/parameters.md
Expand Up @@ -67,6 +67,18 @@ This corresponds to the `--global` option, and tells npm to install this package
#tool npm:?package=yo&global
```

# CakeTool

This parameter controls the installation location of the npm package: While the default is the current working directory (unless [global](#global) is set),
setting `caketool` will set the installation location to inside the `tools` folder and thus ensure that the installed tools are automatically found as
tools in Cake.

### Example

```
#tool npm:?package=yo&caketool
```

# Save

This corresponds to the `--save*` options and controls npm's behaviour for saving dependencies. Specifying `save` with no arguments is equivalent to `--save`, while providing a value (or multiple parameters) provides fine-grained control.
Expand Down
6 changes: 3 additions & 3 deletions src/Cake.Npm.Module.Tests/Cake.Npm.Module.Tests.csproj
Expand Up @@ -5,14 +5,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Cake.Testing" Version="1.1.0" />
<PackageReference Include="Cake.Testing" Version="2.0.0" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
</ItemGroup>

Expand Down
21 changes: 20 additions & 1 deletion src/Cake.Npm.Module.Tests/NpmPackageInstallerFixture.cs
@@ -1,3 +1,4 @@
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Core.Packaging;
Expand All @@ -16,11 +17,15 @@ namespace Cake.Npm.Module.Tests
internal sealed class NpmPackageInstallerFixture
{
public IProcessRunner ProcessRunner { get; set; }

public INpmContentResolver ContentResolver { get; set; }

public ICakeLog Log { get; set; }

public PackageReference Package { get; set; }

private PackageType PackageType { get; }

public DirectoryPath InstallPath { get; set; }

public ICakeConfiguration Config { get; }
Expand All @@ -29,6 +34,11 @@ internal sealed class NpmPackageInstallerFixture

public Action<IToolLocator> ToolLocatorSetup { get; set; }

public ICakeEnvironment Environment { get; set; }

public IFileSystem FileSystem { get; set; }



/// <summary>
/// Initializes a new instance of the <see cref="NpmPackageInstallerFixture"/> class.
Expand All @@ -38,6 +48,8 @@ internal NpmPackageInstallerFixture()
ProcessRunner = Substitute.For<IProcessRunner>();
ContentResolver = Substitute.For<INpmContentResolver>();
Log = new FakeLog();
Environment = new FakeEnvironment(PlatformFamily.Linux) {WorkingDirectory = "/tmp"};
FileSystem = new FakeFileSystem(Environment);
Config = Substitute.For<ICakeConfiguration>();
Package = new PackageReference("npm:?package=yo");
PackageType = PackageType.Addin;
Expand All @@ -64,7 +76,14 @@ internal NpmPackageInstaller CreateInstaller()

setup(ToolLocator);

return new NpmPackageInstaller(ProcessRunner, Log, ContentResolver, Config, ToolLocator);
return new NpmPackageInstaller(
ProcessRunner,
Log,
ContentResolver,
Config,
ToolLocator,
Environment,
FileSystem);
}

/// <summary>
Expand Down
12 changes: 7 additions & 5 deletions src/Cake.Npm.Module/Cake.Npm.Module.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
Expand All @@ -26,21 +26,23 @@
<PackageTags>cake;build;cake-build;module;script;cake-module;cake-contrib;ci;npm;node</PackageTags>
<RepositoryUrl>https://github.com/cake-contrib/Cake.Npm.Module.git</RepositoryUrl>
<PackageReleaseNotes>https://github.com/cake-contrib/Cake.Npm.Module/releases</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="$(SolutionDir)/stylecop.json" Link="stylecop.json" />
<None Include="$(SolutionDir)/.editorconfig" Link=".editorconfig" />
<None Include="$(ProjectDir)../../README.md" Link="README.md" PackagePath="" Pack="true" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="CakeContrib.Guidelines" Version="1.1.1">
<PackageReference Include="Cake.Core" Version="2.0.0" PrivateAssets="all" />
<PackageReference Include="CakeContrib.Guidelines" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Npm.Module/INpmContentResolver.cs
Expand Up @@ -14,8 +14,8 @@ public interface INpmContentResolver
/// </summary>
/// <param name="package">The package.</param>
/// <param name="type">The package type.</param>
/// <param name="isGlobal">Whether the package is globally installed.</param>
/// <param name="installationLocation">The location to install into.</param>
/// <returns>the files installed by the given package.</returns>
IReadOnlyCollection<IFile> GetFiles(PackageReference package, PackageType type, bool isGlobal);
IReadOnlyCollection<IFile> GetFiles(PackageReference package, PackageType type, ModulesInstallationLocation installationLocation);
}
}

0 comments on commit b2377e2

Please sign in to comment.