diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..831d039 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "3.0.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..fef76f2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: Build and Test +on: + push: + pull_request: + branches: [ main ] + paths: + - '**.cs' + - '**.csproj' +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macOS-latest] + steps: + - name: Get the sources + uses: actions/checkout@v2 + with: + fetch-depth: 0 # avoid shallow clone so nbgv can do its work. + - name: Nerdbank.GitVersioning + uses: dotnet/nbgv@v0.4.0 + with: + setAllVars: true + - name: Run the build script + uses: cake-build/cake-action@v1 + with: + target: Pack + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.0 + if: runner.os == 'Windows' + with: + if-no-files-found: warn + name: packages + path: ./artifacts/*.nupkg diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..47d214c --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,34 @@ +name: Publish + +on: + push: + branches: + - main + +jobs: + release: + name: Release + if: "!contains(github.event.head_commit.message, 'skip-ci')" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + + - name: Nerdbank.GitVersioning + uses: dotnet/nbgv@v0.4.0 + with: + setAllVars: true + + - name: Build + uses: cake-build/cake-action@v1 + env: + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + with: + target: Github \ No newline at end of file diff --git a/Cake.Coverlet.sln b/Cake.Coverlet.sln index af22d81..fc44559 100644 --- a/Cake.Coverlet.sln +++ b/Cake.Coverlet.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.32804.182 MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0CB0BC0-F7D4-4D3B-97C3-15C790FFC71D}" EndProject @@ -10,7 +10,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A651E8AD-703B-4B21-B344-68F5F09CDA67}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig - appveyor.yml = appveyor.yml build.cake = build.cake readme.md = readme.md version.json = version.json @@ -18,7 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EEC95ADF-2D7A-4B97-9D4E-27F2F198FFC6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.Coverlet.Tests", "test\Cake.Coverlet.Tests\Cake.Coverlet.Tests.csproj", "{77208523-570A-4419-B4C9-F26B33D3BAA0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.Coverlet.Tests", "test\Cake.Coverlet.Tests\Cake.Coverlet.Tests.csproj", "{77208523-570A-4419-B4C9-F26B33D3BAA0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index b231c99..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: 1.0.1000000.{build} -image: Visual Studio 2017 -configuration: Release -install: -- cmd: git submodule update --init --recursive -- ps: >- - dotnet --info -build_script: -- ps: .\build.ps1 -Target Appveyor -artifacts: -- path: .\artifacts\*.nupkg -test: off -deploy: -- provider: NuGet - api_key: - secure: F2XoBC5Dq633+XJVmP8Lzd2Ii8PZfT5zsa55ISograD4vEm7IxppfjUUVa6D3ukf - on: - APPVEYOR_REPO_TAG: true diff --git a/build.cake b/build.cake index 21a37d2..0eb48be 100644 --- a/build.cake +++ b/build.cake @@ -25,32 +25,53 @@ Task("Restore") .IsDependentOn("Clean") .Does(() => { - DotNetCoreRestore("./Cake.Coverlet.sln"); + DotNetRestore("./Cake.Coverlet.sln"); }); Task("Build") .IsDependentOn("Restore") .Does((data) => { - DotNetCoreBuild("./Cake.Coverlet.sln", data.BuildSettings); + DotNetBuild("./Cake.Coverlet.sln", data.BuildSettings); }); Task("Test") .IsDependentOn("Build") .Does((data) => { - DotNetCoreTest("./test/Cake.Coverlet.Tests", data.TestSettings); + DotNetTest("./test/Cake.Coverlet.Tests", data.TestSettings); }); Task("Pack") .IsDependentOn("Test") .Does((data) => { - DotNetCorePack("./src/Cake.Coverlet/Cake.Coverlet.csproj", data.PackSettings); + DotNetPack("./src/Cake.Coverlet/Cake.Coverlet.csproj", data.PackSettings); }); -Task("AppVeyor") - .IsDependentOn("Pack"); +Task("Publish") + .IsDependentOn("Pack") + .Does((ICakeContext context, MyBuildData data) => +{ + // Make sure that there is an API key. + var apiKey = context.EnvironmentVariable("NUGET_API_KEY"); + if (string.IsNullOrWhiteSpace(apiKey)) { + throw new CakeException("No NuGet API key specified."); + } + + // Publish all projects + foreach(var file in GetFiles($"./{data.ArtifactsDirectory}/*.nupkg")) + { + context.Information("Publishing {0}...", file.GetFilename().FullPath); + context.NuGetPush(file, new NuGetPushSettings { + ApiKey = apiKey, + Source = "https://api.nuget.org/v3/index.json" + }); + } +}); + +Task("Github") + .IsDependentOn("Publish"); Task("Default") .IsDependentOn("Pack"); @@ -61,9 +82,9 @@ public class MyBuildData { public string Configuration { get; } public ConvertableDirectoryPath ArtifactsDirectory { get; } - public DotNetCoreBuildSettings BuildSettings { get; } - public DotNetCorePackSettings PackSettings { get; } - public DotNetCoreTestSettings TestSettings { get; } + public DotNetBuildSettings BuildSettings { get; } + public DotNetPackSettings PackSettings { get; } + public DotNetTestSettings TestSettings { get; } public IReadOnlyList BuildDirs { get; } public MyBuildData( @@ -75,20 +96,20 @@ public class MyBuildData ArtifactsDirectory = artifactsDirectory; BuildDirs = buildDirectories; - BuildSettings = new DotNetCoreBuildSettings { + BuildSettings = new DotNetBuildSettings { Configuration = configuration, NoRestore = true, ArgumentCustomization = args => args.Append("/property:WarningLevel=0") // Until Warnings are fixed in StyleCop }; - PackSettings = new DotNetCorePackSettings + PackSettings = new DotNetPackSettings { OutputDirectory = ArtifactsDirectory, NoBuild = true, Configuration = Configuration, }; - TestSettings = new DotNetCoreTestSettings + TestSettings = new DotNetTestSettings { NoBuild = true, Configuration = Configuration diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index dc42c45..0000000 --- a/build.ps1 +++ /dev/null @@ -1,236 +0,0 @@ -########################################################################## -# This is the Cake bootstrapper script for PowerShell. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -<# - -.SYNOPSIS -This is a Powershell script to bootstrap a Cake build. - -.DESCRIPTION -This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) -and execute your Cake build script with the parameters you provide. - -.PARAMETER Script -The build script to execute. -.PARAMETER Target -The build script target to run. -.PARAMETER Configuration -The build configuration to use. -.PARAMETER Verbosity -Specifies the amount of information to be displayed. -.PARAMETER ShowDescription -Shows description about tasks. -.PARAMETER DryRun -Performs a dry run. -.PARAMETER Experimental -Uses the nightly builds of the Roslyn script engine. -.PARAMETER Mono -Uses the Mono Compiler rather than the Roslyn script engine. -.PARAMETER SkipToolPackageRestore -Skips restoring of packages. -.PARAMETER ScriptArgs -Remaining arguments are added here. - -.LINK -https://cakebuild.net - -#> - -[CmdletBinding()] -Param( - [string]$Script = "build.cake", - [string]$Target, - [string]$Configuration, - [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity, - [switch]$ShowDescription, - [Alias("WhatIf", "Noop")] - [switch]$DryRun, - [switch]$Experimental, - [switch]$Mono, - [switch]$SkipToolPackageRestore, - [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] - [string[]]$ScriptArgs -) - -[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null -function MD5HashFile([string] $filePath) -{ - if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf)) - { - return $null - } - - [System.IO.Stream] $file = $null; - [System.Security.Cryptography.MD5] $md5 = $null; - try - { - $md5 = [System.Security.Cryptography.MD5]::Create() - $file = [System.IO.File]::OpenRead($filePath) - return [System.BitConverter]::ToString($md5.ComputeHash($file)) - } - finally - { - if ($file -ne $null) - { - $file.Dispose() - } - } -} - -function GetProxyEnabledWebClient -{ - $wc = New-Object System.Net.WebClient - $proxy = [System.Net.WebRequest]::GetSystemWebProxy() - $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials - $wc.Proxy = $proxy - return $wc -} - -Write-Host "Preparing to run build script..." - -if(!$PSScriptRoot){ - $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent -} - -$TOOLS_DIR = Join-Path $PSScriptRoot "tools" -$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins" -$MODULES_DIR = Join-Path $TOOLS_DIR "Modules" -$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" -$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" -$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" -$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum" -$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config" -$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config" - -# Make sure tools folder exists -if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { - Write-Verbose -Message "Creating tools directory..." - New-Item -Path $TOOLS_DIR -Type directory | out-null -} - -# Make sure that packages.config exist. -if (!(Test-Path $PACKAGES_CONFIG)) { - Write-Verbose -Message "Downloading packages.config..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) - } catch { - Throw "Could not download packages.config." - } -} - -# Try find NuGet.exe in path if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Trying to find nuget.exe in PATH..." - $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) } - $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 - if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { - Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." - $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName - } -} - -# Try download NuGet.exe if not exists -if (!(Test-Path $NUGET_EXE)) { - Write-Verbose -Message "Downloading NuGet.exe..." - try { - $wc = GetProxyEnabledWebClient - $wc.DownloadFile($NUGET_URL, $NUGET_EXE) - } catch { - Throw "Could not download NuGet.exe." - } -} - -# Save nuget.exe path to environment to be available to child processed -$ENV:NUGET_EXE = $NUGET_EXE - -# Restore tools from NuGet? -if(-Not $SkipToolPackageRestore.IsPresent) { - Push-Location - Set-Location $TOOLS_DIR - - # Check for changes in packages.config and remove installed tools if true. - [string] $md5Hash = MD5HashFile($PACKAGES_CONFIG) - if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or - ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) { - Write-Verbose -Message "Missing or changed package.config hash..." - Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery | - Remove-Item -Recurse - } - - Write-Verbose -Message "Restoring tools from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet tools." - } - else - { - $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII" - } - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Restore addins from NuGet -if (Test-Path $ADDINS_PACKAGES_CONFIG) { - Push-Location - Set-Location $ADDINS_DIR - - Write-Verbose -Message "Restoring addins from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet addins." - } - - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Restore modules from NuGet -if (Test-Path $MODULES_PACKAGES_CONFIG) { - Push-Location - Set-Location $MODULES_DIR - - Write-Verbose -Message "Restoring modules from NuGet..." - $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`"" - - if ($LASTEXITCODE -ne 0) { - Throw "An error occurred while restoring NuGet modules." - } - - Write-Verbose -Message ($NuGetOutput | out-string) - - Pop-Location -} - -# Make sure that Cake has been installed. -if (!(Test-Path $CAKE_EXE)) { - Throw "Could not find Cake.exe at $CAKE_EXE" -} - - - -# Build Cake arguments -$cakeArguments = @("$Script"); -if ($Target) { $cakeArguments += "-target=$Target" } -if ($Configuration) { $cakeArguments += "-configuration=$Configuration" } -if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" } -if ($ShowDescription) { $cakeArguments += "-showdescription" } -if ($DryRun) { $cakeArguments += "-dryrun" } -if ($Experimental) { $cakeArguments += "-experimental" } -if ($Mono) { $cakeArguments += "-mono" } -$cakeArguments += $ScriptArgs - -# Start Cake -Write-Host "Running build script..." -&$CAKE_EXE $cakeArguments -exit $LASTEXITCODE diff --git a/build.sh b/build.sh deleted file mode 100755 index b9e1252..0000000 --- a/build.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash - -########################################################################## -# This is the Cake bootstrapper script for Linux and OS X. -# This file was downloaded from https://github.com/cake-build/resources -# Feel free to change this file to fit your needs. -########################################################################## - -# Define directories. -SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -TOOLS_DIR=$SCRIPT_DIR/tools -ADDINS_DIR=$TOOLS_DIR/Addins -MODULES_DIR=$TOOLS_DIR/Modules -NUGET_EXE=$TOOLS_DIR/nuget.exe -CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe -PACKAGES_CONFIG=$TOOLS_DIR/packages.config -PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum -ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config -MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config - -# Define md5sum or md5 depending on Linux/OSX -MD5_EXE= -if [[ "$(uname -s)" == "Darwin" ]]; then - MD5_EXE="md5 -r" -else - MD5_EXE="md5sum" -fi - -# Define default arguments. -SCRIPT="build.cake" -CAKE_ARGUMENTS=() - -# Parse arguments. -for i in "$@"; do - case $1 in - -s|--script) SCRIPT="$2"; shift ;; - --) shift; CAKE_ARGUMENTS+=("$@"); break ;; - *) CAKE_ARGUMENTS+=("$1") ;; - esac - shift -done - -# Make sure the tools folder exist. -if [ ! -d "$TOOLS_DIR" ]; then - mkdir "$TOOLS_DIR" -fi - -# Make sure that packages.config exist. -if [ ! -f "$TOOLS_DIR/packages.config" ]; then - echo "Downloading packages.config..." - curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages - if [ $? -ne 0 ]; then - echo "An error occurred while downloading packages.config." - exit 1 - fi -fi - -# Download NuGet if it does not exist. -if [ ! -f "$NUGET_EXE" ]; then - echo "Downloading NuGet..." - curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - if [ $? -ne 0 ]; then - echo "An error occurred while downloading nuget.exe." - exit 1 - fi -fi - -# Restore tools from NuGet. -pushd "$TOOLS_DIR" >/dev/null -if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then - find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf -fi - -mono "$NUGET_EXE" install -ExcludeVersion -if [ $? -ne 0 ]; then - echo "Could not restore NuGet tools." - exit 1 -fi - -$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5" - -popd >/dev/null - -# Restore addins from NuGet. -if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then - pushd "$ADDINS_DIR" >/dev/null - - mono "$NUGET_EXE" install -ExcludeVersion - if [ $? -ne 0 ]; then - echo "Could not restore NuGet addins." - exit 1 - fi - - popd >/dev/null -fi - -# Restore modules from NuGet. -if [ -f "$MODULES_PACKAGES_CONFIG" ]; then - pushd "$MODULES_DIR" >/dev/null - - mono "$NUGET_EXE" install -ExcludeVersion - if [ $? -ne 0 ]; then - echo "Could not restore NuGet modules." - exit 1 - fi - - popd >/dev/null -fi - -# Make sure that Cake has been installed. -if [ ! -f "$CAKE_EXE" ]; then - echo "Could not find Cake.exe at '$CAKE_EXE'." - exit 1 -fi - -# Start Cake -exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}" diff --git a/readme.md b/readme.md index d80815a..bcca9fb 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ Task("Test") .IsDependentOn("Build") .Does((data) => { - var testSettings = new DotNetCoreTestSettings { + var testSettings = new DotNetTestSettings { }; var coverletSettings = new CoverletSettings { @@ -30,7 +30,7 @@ Task("Test") CoverletOutputName = $"results-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}" }; - DotNetCoreTest("./test/My.Project.Tests/My.Project.Tests.csproj", testSetting, coverletSettings); + DotNetTest("./test/My.Project.Tests/My.Project.Tests.csproj", testSetting, coverletSettings); } ``` @@ -77,7 +77,7 @@ Task("Test") .IsDependentOn("Build") .Does((data) => { - var testSettings = new DotNetCoreTestSettings { + var testSettings = new DotNetTestSettings { }; var coverletSettings = new CoverletSettings { @@ -88,7 +88,7 @@ Task("Test") OutputNameTransformer = (fileName, directory) => $@"{directory}\{fileName}-HelloWorld" }; - DotNetCoreTest("./test/Stubble.Core.Tests/Stubble.Core.Tests.csproj", testSetting, coverletSettings); + DotNetTest("./test/Stubble.Core.Tests/Stubble.Core.Tests.csproj", testSetting, coverletSettings); } ``` diff --git a/src/Cake.Coverlet/Cake.Coverlet.csproj b/src/Cake.Coverlet/Cake.Coverlet.csproj index a139856..70a3b3a 100644 --- a/src/Cake.Coverlet/Cake.Coverlet.csproj +++ b/src/Cake.Coverlet/Cake.Coverlet.csproj @@ -2,7 +2,7 @@ Coverlet extensions for Cake Build - netstandard2.0 + net6.0 true Cake.Coverlet Cake.Coverlet @@ -31,13 +31,17 @@ - - - + + + all + runtime; build; native; contentfiles; analyzers + + + - + diff --git a/src/Cake.Coverlet/CoverletAliases.cs b/src/Cake.Coverlet/CoverletAliases.cs index e6d0678..9cce2c7 100644 --- a/src/Cake.Coverlet/CoverletAliases.cs +++ b/src/Cake.Coverlet/CoverletAliases.cs @@ -1,22 +1,21 @@ -using Cake.Core; +using System; +using System.Linq; +using Cake.Common.Tools.DotNet; +using Cake.Common.Tools.DotNet.Test; +using Cake.Core; using Cake.Core.Annotations; using Cake.Core.IO; -using Cake.Common.Tools.DotNetCore; -using Cake.Common.Tools.DotNetCore.Test; -using System; -using System.Linq; -using System.Collections.Generic; namespace Cake.Coverlet { /// - /// Several extension methods when using DotNetCoreTest. + /// Several extension methods when using DotNetTest. /// - [CakeAliasCategory("DotNetCore")] + [CakeAliasCategory("DotNet")] public static class CoverletAliases { /// - /// Runs DotNetCoreTest using the given + /// Runs DotNetTest using the given /// /// /// @@ -24,26 +23,26 @@ public static class CoverletAliases /// [CakeMethodAlias] [CakeAliasCategory("Test")] - - public static void DotNetCoreTest( + public static void DotNetTest( this ICakeContext context, FilePath project, - DotNetCoreTestSettings settings, + DotNetTestSettings settings, CoverletSettings coverletSettings) { - if (context == null) { + if (context == null) + { throw new ArgumentNullException(nameof(context)); } var currentCustomization = settings.ArgumentCustomization; settings.ArgumentCustomization = (args) => ArgumentsProcessor.ProcessMSBuildArguments( coverletSettings, - context.Environment, - currentCustomization?.Invoke(args) ?? args, + context.Environment, + currentCustomization?.Invoke(args) ?? args, project); - context.DotNetCoreTest(project.FullPath, settings); + context.DotNetTest(project.FullPath, settings); } - + /// /// Runs coverlet with the given dll, test project and settings /// @@ -59,13 +58,12 @@ public static void Coverlet( FilePath testProject, CoverletSettings settings) { - if (context == null) { + if (context == null) + { throw new ArgumentNullException(nameof(context)); } - if (settings == null) { - settings = new CoverletSettings(); - } + settings ??= new CoverletSettings(); new CoverletTool(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools) .Run(testFile, testProject, settings); @@ -87,13 +85,12 @@ public static void Coverlet( CoverletSettings settings, string configuration = "Debug") { - if (context == null) { + if (context == null) + { throw new ArgumentNullException(nameof(context)); } - if (settings == null) { - settings = new CoverletSettings(); - } + settings ??= new CoverletSettings(); var debugFile = FindDebugDll(context, testProject.GetDirectory(), testProject, configuration); @@ -117,14 +114,13 @@ public static void Coverlet( CoverletSettings settings, string configuration = "Debug") { - if (context == null) { + if (context == null) + { throw new ArgumentNullException(nameof(context)); } - if (settings == null) { - settings = new CoverletSettings(); - } - + settings ??= new CoverletSettings(); + var projFile = context.Globber.GetFiles($"{testProjectDir}/*.*proj") .FirstOrDefault(); @@ -145,7 +141,7 @@ private static FilePath FindDebugDll(ICakeContext context, DirectoryPath path, F var debugFile = context.Globber.GetFiles($"{path.MakeAbsolute(context.Environment)}/bin/**/{configuration}/**/{nameWithoutExtension}.dll") .FirstOrDefault(); - if (debugFile == null) + if (debugFile == null) { throw new Exception($"Could not find {configuration} dll with name {nameWithoutExtension}.dll"); } diff --git a/src/Cake.Coverlet/CoverletSettings.cs b/src/Cake.Coverlet/CoverletSettings.cs index f24732b..10f6d14 100644 --- a/src/Cake.Coverlet/CoverletSettings.cs +++ b/src/Cake.Coverlet/CoverletSettings.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using Cake.Common.Tools.DotNetCore; -using Cake.Core; +using Cake.Common.Tools.DotNet; using Cake.Core.IO; namespace Cake.Coverlet @@ -18,7 +16,7 @@ namespace Cake.Coverlet /// /// Settings used by Cake.Coverlet /// - public class CoverletSettings : DotNetCoreSettings + public class CoverletSettings : DotNetSettings { /// /// Gets or sets if coverage should be collected @@ -165,7 +163,7 @@ public CoverletSettings WithDateTimeTransformer() OutputTransformer = (fileName, directory) => $@"{directory}\{fileName}-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}"; return this; } - + /// /// Sets the output format to be a specific value /// diff --git a/src/Cake.Coverlet/CoverletTool.cs b/src/Cake.Coverlet/CoverletTool.cs index afdc731..8f3707b 100644 --- a/src/Cake.Coverlet/CoverletTool.cs +++ b/src/Cake.Coverlet/CoverletTool.cs @@ -1,95 +1,95 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Cake.Core; -using Cake.Core.IO; -using Cake.Core.Tooling; - -namespace Cake.Coverlet -{ - /// - /// A class for the coverlet tool - /// - public sealed class CoverletTool : Tool - { - private readonly ICakeEnvironment _environment; - - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - public CoverletTool(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools) - : base(fileSystem, environment, processRunner, tools) - { - _environment = environment; - } - - /// - /// Gets the name of the tool. - /// - /// The name of the tool - protected override string GetToolName() => "coverlet"; - - /// - /// Runs the tool with the given test file, test project and settings - /// - /// - /// - /// - public void Run(FilePath testFile, FilePath testProject, CoverletSettings settings) - { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } - - if (testFile == null) - { - throw new ArgumentNullException(nameof(testFile)); - } - - Run(settings, GetArguments(testFile, testProject, settings)); - } - - private ProcessArgumentBuilder GetArguments( - FilePath coverageFile, - FilePath testProject, - CoverletSettings settings) - { - var argumentBuilder = new ProcessArgumentBuilder(); - - argumentBuilder.AppendQuoted(coverageFile.MakeAbsolute(_environment).FullPath); - - argumentBuilder.AppendSwitchQuoted("--target", "dotnet"); - argumentBuilder.AppendSwitchQuoted($"--targetargs", $"test {testProject.MakeAbsolute(_environment)} --no-build"); - - ArgumentsProcessor.ProcessToolArguments(settings, _environment, argumentBuilder, testProject); - - return argumentBuilder; - } - - /// - /// Gets the possible executable names - /// - /// - protected override IEnumerable GetToolExecutableNames() => new [] { "coverlet", "coverlet.exe" }; - - /// - /// Gets the alternative tool paths for the tool - /// - /// - /// The alternate tool paths - protected override IEnumerable GetAlternativeToolPaths(CoverletSettings settings) - { - var globalToolLocation = _environment.Platform.IsUnix() - ? new DirectoryPath(_environment.GetEnvironmentVariable("HOME")) - : new DirectoryPath(_environment.GetEnvironmentVariable("USERPROFILE")); - - return GetToolExecutableNames() - .Select(name => globalToolLocation.Combine(".dotnet/tools").GetFilePath(name)); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Cake.Core; +using Cake.Core.IO; +using Cake.Core.Tooling; + +namespace Cake.Coverlet +{ + /// + /// A class for the coverlet tool + /// + public sealed class CoverletTool : Tool + { + private readonly ICakeEnvironment _environment; + + /// + /// Initializes a new instance of the class. + /// + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + public CoverletTool(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools) + : base(fileSystem, environment, processRunner, tools) + { + _environment = environment; + } + + /// + /// Gets the name of the tool. + /// + /// The name of the tool + protected override string GetToolName() => "coverlet"; + + /// + /// Runs the tool with the given test file, test project and settings + /// + /// + /// + /// + public void Run(FilePath testFile, FilePath testProject, CoverletSettings settings) + { + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + if (testFile == null) + { + throw new ArgumentNullException(nameof(testFile)); + } + + Run(settings, GetArguments(testFile, testProject, settings)); + } + + private ProcessArgumentBuilder GetArguments( + FilePath coverageFile, + FilePath testProject, + CoverletSettings settings) + { + var argumentBuilder = new ProcessArgumentBuilder(); + + argumentBuilder.AppendQuoted(coverageFile.MakeAbsolute(_environment).FullPath); + + argumentBuilder.AppendSwitchQuoted("--target", "dotnet"); + argumentBuilder.AppendSwitchQuoted($"--targetargs", $"test {testProject.MakeAbsolute(_environment)} --no-build"); + + ArgumentsProcessor.ProcessToolArguments(settings, _environment, argumentBuilder, testProject); + + return argumentBuilder; + } + + /// + /// Gets the possible executable names + /// + /// + protected override IEnumerable GetToolExecutableNames() => new [] { "coverlet", "coverlet.exe" }; + + /// + /// Gets the alternative tool paths for the tool + /// + /// + /// The alternate tool paths + protected override IEnumerable GetAlternativeToolPaths(CoverletSettings settings) + { + var globalToolLocation = _environment.Platform.IsUnix() + ? new DirectoryPath(_environment.GetEnvironmentVariable("HOME")) + : new DirectoryPath(_environment.GetEnvironmentVariable("USERPROFILE")); + + return GetToolExecutableNames() + .Select(name => globalToolLocation.Combine(".dotnet/tools").GetFilePath(name)); + } + } +} diff --git a/test/Cake.Coverlet.Tests/Cake.Coverlet.Tests.csproj b/test/Cake.Coverlet.Tests/Cake.Coverlet.Tests.csproj index acf3774..426b89e 100644 --- a/test/Cake.Coverlet.Tests/Cake.Coverlet.Tests.csproj +++ b/test/Cake.Coverlet.Tests/Cake.Coverlet.Tests.csproj @@ -1,18 +1,25 @@ - netcoreapp2.1 - + net6.0 false - - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all runtime; build; native; contentfiles; analyzers diff --git a/tools/packages.config b/tools/packages.config deleted file mode 100644 index 945c3e8..0000000 --- a/tools/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/version.json b/version.json index 580ff01..f255562 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "2.6", + "version": "3.0", "publicReleaseRefSpec": [ "^refs/tags/v\\d\\.\\d" // we also release tags starting with vN.N ],