diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..31e896e --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "2.0.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f0aa9d7..35dbd1e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,39 +14,32 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-18.04, ubuntu-latest, macos-latest] + os: [ubuntu-18.04, ubuntu-latest, macos-latest, windows-2019, windows-2022] steps: - name: Get the sources uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Install .NET SDKs - uses: actions/setup-dotnet@v1.9.0 + - name: Install .NET Core SDK 3.1.x + uses: actions/setup-dotnet@v1 with: - dotnet-version: | - 3.1.x - 5.0.x - 6.0.x + dotnet-version: '3.1.x' - - if: matrix.os == 'windows-latest' - name: Run Cake script Windows - run: | - ./build.ps1 - - - if: matrix.os != 'windows-latest' - name: Run Cake script Posix - run: | - ./build.sh + - name: Install .NET Core SDK 5.0.x + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '5.0.x' - - name: Upload Artifacts - uses: actions/upload-artifact@v2 + - name: Install .NET Core SDK (global.json) + uses: actions/setup-dotnet@v1 with: - name: artifacts - path: artifacts + include-prerelease: 'true' - - name: Upload NuGet Package - uses: actions/upload-artifact@v2 + - name: Run Cake script + uses: cake-build/cake-action@v1 + env: + matrix-os: ${{ matrix.os }} with: - name: nuget - path: nuget \ No newline at end of file + target: GitHubActions + cake-version: tool-manifest \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 8376421..a7c8654 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ osx_image: xcode11.2 mono: - 5.12.0 -dotnet: 5.0.102 +dotnet: 6.0.100 before_install: - git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags diff --git a/appveyor.yml b/appveyor.yml index 0fe0f8f..16305fb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ os: Visual Studio 2022 # Build script build_script: - - ps: .\build.ps1 -Target AppVeyor + - ps: .\build.ps1 --target AppVeyor # Tests test: off diff --git a/build.cake b/build.cake index b1a0797..02d0b5e 100644 --- a/build.cake +++ b/build.cake @@ -1,38 +1,45 @@ -// Install modules -#module nuget:?package=Cake.DotNetTool.Module&version=1.0.1 - - -// Install .NET Global tools. -#tool "dotnet:https://api.nuget.org/v3/index.json?package=Cake.Tool&version=1.0.0" +#tool nuget:?package=NuGet.CommandLine&version=6.0.0 /////////////////////////////////////////////////////////////////////////////// // ARGUMENTS /////////////////////////////////////////////////////////////////////////////// var target = Argument("target", "Default"); -var configuration = Argument("configuration", "Release"); /////////////////////////////////////////////////////////////////////////////// -// GLOBAL VARIABLES +// GITHUB ACTION Grouping /////////////////////////////////////////////////////////////////////////////// -var isLocalBuild = !AppVeyor.IsRunningOnAppVeyor; -var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest; -var solutions = GetFiles("./**/*.sln"); -var solutionPaths = solutions.Select(solution => solution.GetDirectory()); -var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md"); -var version = releaseNotes.Version.ToString(); -var binDir = MakeAbsolute(Directory("./src/Cake.Git/bin/" + configuration + "/net461")); -var nugetRoot = "./nuget/"; -var artifactsRoot = MakeAbsolute(Directory("./artifacts/")); -var semVersion = isLocalBuild || (AppVeyor.Environment.Repository.Tag.IsTag - && !string.IsNullOrWhiteSpace(AppVeyor.Environment.Repository.Tag.Name)) - ? version - : string.Concat(version, "-build-", AppVeyor.Environment.Build.Number.ToString("0000")); - -var assemblyInfo = new AssemblyInfoSettings { + +if (BuildSystem.GitHubActions.IsRunningOnGitHubActions) +{ + TaskSetup(context => System.Console.WriteLine($"::group::{context.Task.Name.Quote()}")); + TaskTeardown(context => System.Console.WriteLine("::endgroup::")); +} + + +/////////////////////////////////////////////////////////////////////////////// +// SETUP / TEARDOWN +/////////////////////////////////////////////////////////////////////////////// + +Setup(ctx => +{ + var isLocalBuild = !AppVeyor.IsRunningOnAppVeyor; + var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md"); + var version = releaseNotes.Version.ToString(); + var semVersion = isLocalBuild || (AppVeyor.Environment.Repository.Tag.IsTag + && !string.IsNullOrWhiteSpace(AppVeyor.Environment.Repository.Tag.Name)) + ? version + : string.Concat(version, "-build-", AppVeyor.Environment.Build.Number.ToString("0000")); + + if (!isLocalBuild) + { + AppVeyor.UpdateBuildVersion(semVersion); + } + + var assemblyInfo = new AssemblyInfoSettings { Title = "Cake.Git", Description = "Cake Git AddIn", - Product = "Cake.Git", + Product = "Cake.Git", Company = "WCOM AB", Version = version, FileVersion = version, @@ -40,7 +47,34 @@ var assemblyInfo = new AssemblyInfoSettings { Copyright = string.Format("Copyright © WCOM AB {0}", DateTime.Now.Year), CLSCompliant = true }; -var nuGetPackSettings = new NuGetPackSettings { + + + var configuration = Argument("configuration", "Release"); + + + // Executed BEFORE the first task. + Information("Building {0} version {1} of {2} ({3}).", + configuration, + version, + assemblyInfo.Product, + semVersion); + + var artifactsRoot = MakeAbsolute(Directory("./artifacts/")); + var nugetRoot = MakeAbsolute(Directory("./nuget/")); + + return new BuildData( + isLocalBuild, + configuration, + target, + new[]{ "netcoreapp3.1", "net5.0", "net6.0" }, + new DotNetMSBuildSettings() + .WithProperty("Version", semVersion) + .WithProperty("AssemblyVersion", version) + .WithProperty("FileVersion", version) + .WithProperty("PackageReleaseNotes", string.Concat("\"", string.Concat(releaseNotes.Notes.ToArray()), "\"")) + .WithProperty("ContinuousIntegrationBuild", AppVeyor.IsRunningOnAppVeyor ? "true" : "false") + .WithProperty("EmbedUntrackedSources", "true"), + new NuGetPackSettings { Id = assemblyInfo.Product, Version = assemblyInfo.InformationalVersion, Title = assemblyInfo.Title, @@ -55,62 +89,22 @@ var nuGetPackSettings = new NuGetPackSettings { License = new NuSpecLicense { Type = "expression", Value = "MIT" }, Copyright = assemblyInfo.Copyright, ReleaseNotes = releaseNotes.Notes.ToArray(), - Tags = new [] { "Cake", "Script", "Build", "Git", "cake-addin" }, + Tags = new [] { "cake", "script", "build", "git", "cake-addin", "cake-build" }, RequireLicenseAcceptance= false, Symbols = false, NoPackageAnalysis = true, - Files = new NuSpecContent[0], // is set dynamically + Files = Array.Empty(), // is set dynamically BasePath = artifactsRoot, OutputDirectory = nugetRoot - }; - -var msBuildSettings = new DotNetCoreMSBuildSettings() - .WithProperty("Version", semVersion) - .WithProperty("AssemblyVersion", version) - .WithProperty("FileVersion", version) - .WithProperty("PackageReleaseNotes", string.Concat("\"", string.Concat(releaseNotes.Notes.ToArray()), "\"")) - .WithProperty("ContinuousIntegrationBuild", AppVeyor.IsRunningOnAppVeyor ? "true" : "false") - .WithProperty("EmbedUntrackedSources", "true"); - -Context.Tools.RegisterFile("./tools/nuget.exe"); - -if (!isLocalBuild) -{ - AppVeyor.UpdateBuildVersion(semVersion); -} - -if (BuildSystem.GitHubActions.IsRunningOnGitHubActions) -{ - TaskSetup(context=> System.Console.WriteLine($"::group::{context.Task.Name.Quote()}")); - TaskTeardown(context=>System.Console.WriteLine("::endgroup::")); -} - -/////////////////////////////////////////////////////////////////////////////// -// SETUP / TEARDOWN -/////////////////////////////////////////////////////////////////////////////// - -Setup(ctx => -{ - // Executed BEFORE the first task. - Information("Running tasks..."); - - var buildStartMessage = string.Format( - "Building version {0} of {1} ({2}).", - version, - assemblyInfo.Product, - semVersion - ); - - Information(buildStartMessage); - - if(!IsRunningOnWindows()) - { - var frameworkPathOverride = new FilePath(typeof(object).Assembly.Location).GetDirectory().FullPath + "/"; - - // Use FrameworkPathOverride when not running on Windows. - Information("Build will use FrameworkPathOverride={0} since not building on Windows.", frameworkPathOverride); - msBuildSettings.WithProperty("FrameworkPathOverride", frameworkPathOverride); - } + }, + assemblyInfo, + new BuildPaths( + artifactsRoot, + nugetRoot, + nugetRoot.CombineWithFilePath("Cake.Git." + semVersion + ".nupkg"), + GetFiles("./**/*.sln") + .ToArray(), + MakeAbsolute(Directory("./tools/Addins/Cake.Git/Cake.Git")))); }); Teardown(ctx => @@ -124,35 +118,35 @@ Teardown(ctx => /////////////////////////////////////////////////////////////////////////////// Task("Clean") - .Does(() => + .Does(static (context, data) => { // Clean solution directories. - foreach(var path in solutionPaths) + foreach(var path in data.BuildPaths.SolutionPaths) { - Information("Cleaning {0}", path); - CleanDirectories(path + "/**/bin/" + configuration); - CleanDirectories(path + "/**/obj/" + configuration); + context.Information("Cleaning {0}", path); + context.CleanDirectories(path + "/**/bin/" + data.Configuration); + context.CleanDirectories(path + "/**/obj/" + data.Configuration); } - Information("Cleaning {0}", nugetRoot); - CleanDirectory(MakeAbsolute(Directory(nugetRoot))); + context.Information("Cleaning {0}", data.BuildPaths.NuGetRoot); + context.CleanDirectory(data.BuildPaths.NuGetRoot); - Information("Cleaning {0}", artifactsRoot); - CleanDirectory(artifactsRoot); + context.Information("Cleaning {0}", data.BuildPaths.ArtifactsRoot); + context.CleanDirectory(data.BuildPaths.ArtifactsRoot); }); Task("Restore") - .Does(() => + .Does(static (context, data) => { // Restore all NuGet packages. - foreach(var solution in solutions) + foreach(var solution in data.BuildPaths.Solutions) { - Information("Restoring {0}...", solution); - DotNetCoreRestore( + context.Information("Restoring {0}...", solution); + context.DotNetRestore( solution.FullPath, - new DotNetCoreRestoreSettings { - Verbosity = DotNetCoreVerbosity.Minimal, - MSBuildSettings = msBuildSettings + new DotNetRestoreSettings { + Verbosity = DotNetVerbosity.Minimal, + MSBuildSettings = data.MSBuildSettings }); } }); @@ -160,191 +154,150 @@ Task("Restore") Task("SolutionInfo") .IsDependentOn("Clean") .IsDependentOn("Restore") - .Does(() => + .Does(static (context, data) => { var file = "./src/SolutionInfo.cs"; - CreateAssemblyInfo(file, assemblyInfo); + context.CreateAssemblyInfo(file, data.AssemblyInfoSettings); }); Task("Build") .IsDependentOn("Clean") .IsDependentOn("Restore") .IsDependentOn("SolutionInfo") - .Does(() => + .Does(static (context, data) => { // Build all solutions. - foreach(var solution in solutions) + foreach(var solution in data.BuildPaths.Solutions) { - Information("Building {0}", solution); - DotNetCoreBuild( + context.Information("Building {0}", solution); + context.DotNetBuild( solution.FullPath, - new DotNetCoreBuildSettings { - Configuration = configuration, + new DotNetBuildSettings { + Configuration = data.Configuration, NoRestore = true, - MSBuildSettings = msBuildSettings + MSBuildSettings = data.MSBuildSettings }); } }); Task("Publish-Artifacts") .IsDependentOn("Build") - .Does(() => + .DoesForEach( + static (data, context) => { + context.EnsureDirectoryExists(data.BuildPaths.ArtifactsRoot); + return data.TargetFrameworks; + }, + static (data, targetFramework, context) => { - if (!DirectoryExists(artifactsRoot)) - { - CreateDirectory(artifactsRoot); - } - - DotNetCorePublish("./src/Cake.Git", new DotNetCorePublishSettings - { - NoRestore = true, - Framework = "net461", - MSBuildSettings = msBuildSettings, - OutputDirectory = artifactsRoot + "/net461" - }); - - DotNetCorePublish("./src/Cake.Git", new DotNetCorePublishSettings + context.DotNetPublish("./src/Cake.Git", new DotNetPublishSettings { NoRestore = true, - Framework = "netstandard2.0", - MSBuildSettings = msBuildSettings, - OutputDirectory = artifactsRoot + "/netstandard2.0" - }); - - DotNetCorePublish("./src/Cake.Git", new DotNetCorePublishSettings - { - NoRestore = true, - Framework = "net5.0", - MSBuildSettings = msBuildSettings, - OutputDirectory = artifactsRoot + "/net5.0" + Framework = targetFramework, + MSBuildSettings = data.MSBuildSettings, + OutputDirectory = data.BuildPaths.ArtifactsRoot.Combine(targetFramework) }); }); Task("Create-NuGet-Package") .IsDependentOn("Publish-Artifacts") - .Does(() => + .Does(static (context, data) => { - var native = GetFiles(artifactsRoot.FullPath + "/net461/lib/**/*"); - var cakeGit = GetFiles(artifactsRoot.FullPath + "/**/Cake.Git.dll"); - var cakeGitDoc = GetFiles(artifactsRoot.FullPath + "/**/Cake.Git.xml"); - var libGit = GetFiles(artifactsRoot.FullPath + "/**/LibGit2Sharp*"); - var coreNative = GetFiles(artifactsRoot.FullPath + "/net5.0/runtimes/**/*") - - GetFiles(artifactsRoot.FullPath + "/net5.0/runtimes/win-x86/**/*"); - - nuGetPackSettings.Files = (native + libGit + cakeGit + cakeGitDoc) - .Where(file=>!file.FullPath.Contains("Cake.Core.") && !file.FullPath.Contains("/runtimes/")) - .Select(file=>file.FullPath.Substring(artifactsRoot.FullPath.Length+1)) + var cakeGit = context.GetFiles(data.BuildPaths.ArtifactsRoot.FullPath + "/**/Cake.Git.dll"); + var cakeGitDoc = context.GetFiles(data.BuildPaths.ArtifactsRoot.FullPath + "/**/Cake.Git.xml"); + var libGit = context.GetFiles(data.BuildPaths.ArtifactsRoot.FullPath + "/**/LibGit2Sharp*"); + var unmanaged = context.GetFiles(data.BuildPaths.ArtifactsRoot.FullPath + "/net6.0/runtimes/**/*"); + + data.NuGetPackSettings.Files = (libGit + cakeGit + cakeGitDoc) + .Select(file=>file.FullPath.Substring(data.BuildPaths.ArtifactsRoot.FullPath.Length+1)) .Select(file=>new NuSpecContent {Source = file, Target = "lib/" + file}) - .Union( - coreNative - .Where(file=>file.FullPath.Contains("/linux-x64/") || file.FullPath.Contains("/win-x64/") || file.FullPath.Contains("/osx/")) - .Select(file=>new NuSpecContent { - Source = file.FullPath.Substring(artifactsRoot.FullPath.Length+1), - Target = "lib/netstandard2.0/" + file.GetFilename() - }) - ).Union( - coreNative - .Where(file=>file.FullPath.Contains("/linux-x64/") || file.FullPath.Contains("/win-x64/") || file.FullPath.Contains("/osx/")) - .Select(file=>new NuSpecContent { - Source = file.FullPath.Substring(artifactsRoot.FullPath.Length+1), - Target = "lib/net5.0/" + file.GetFilename() - }) - ) - .Concat(new [] + // add unmanaged dlls to the "right" place in the nuget + .Union(unmanaged + .Select(file=>file.FullPath.Substring(data.BuildPaths.ArtifactsRoot.FullPath.Length+1)) + .Select(file=>new NuSpecContent {Source = file, Target = "/" + file.Substring(7)})) + // cake scripting needs the unmanaged dlls to be in the "wrong" place for some reason.. + .Union(unmanaged + .Where(file=>file.FullPath.Contains("/linux-x64/") || file.FullPath.Contains("/win-x64/") || file.FullPath.Contains("/osx/")) + .SelectMany(file => data.TargetFrameworks.Select(tfm => + new NuSpecContent { + Source = file.FullPath.Substring(data.BuildPaths.ArtifactsRoot.FullPath.Length+1), + Target = $"lib/{tfm}/{file.GetFilename()}" + }))) + // add the icon + .Union(new [] { new NuSpecContent { - Source = MakeAbsolute(File("./asset/cake-contrib-addin-medium.png")).FullPath, + Source = context.MakeAbsolute(context.File("./asset/cake-contrib-addin-medium.png")).FullPath, Target = "images/icon.png", }, }) .ToArray(); - if (!DirectoryExists(nugetRoot)) - { - CreateDirectory(nugetRoot); - } - NuGetPack(nuGetPackSettings); + context.EnsureDirectoryExists(data.BuildPaths.NuGetRoot); + + context.NuGetPack(data.NuGetPackSettings); }); Task("Test") .IsDependentOn("Create-NuGet-Package") - .WithCriteria(() => StringComparer.OrdinalIgnoreCase.Equals(configuration, "Release")) - .Does(() => -{ - var package = nugetRoot + "Cake.Git." + semVersion + ".nupkg"; - var addinDir = MakeAbsolute(Directory("./tools/Addins/Cake.Git/Cake.Git")); - if (DirectoryExists(addinDir)) - { - DeleteDirectory(addinDir, new DeleteDirectorySettings { - Recursive = true, - Force = true - }); - } - Unzip(package, addinDir); - - Action executeTests = ()=> { - var testArguments = new Dictionary{ - {"target", target == "Default" ? "Default-Tests" : "Local-Tests"} - }; - - Information("Testing net461"); - - CakeExecuteScript( - "./testnet461.cake", - new CakeSettings{ - Arguments = testArguments, - ToolPath = Context.Tools.Resolve("Cake.exe") - } - ); - - Information("Testing net5.0"); - - CakeExecuteScript( - "./testnet50.cake", - new CakeSettings{ - Arguments = testArguments, - ToolPath = IsRunningOnWindows() - ? "./tools/dotnet-cake.exe" - : "./tools/dotnet-cake" + .WithCriteria(data => StringComparer.OrdinalIgnoreCase.Equals(data.Configuration, "Release")) + .DoesForEach( + static (data, context) => { + if (context.DirectoryExists(data.BuildPaths.AddinDir)) + { + context.DeleteDirectory(data.BuildPaths.AddinDir, new DeleteDirectorySettings { + Recursive = true, + Force = true }); + } + + context.Unzip(data.BuildPaths.Package, data.BuildPaths.AddinDir); + + var cakeSettings = new CakeSettings { + Arguments = new Dictionary { + { "target", data.Target == "Default" ? "Default-Tests" : "Local-Tests"} + } + }; + + return data + .TargetFrameworks + .Select(targetFramework => new TestCase(targetFramework, cakeSettings)) + .ToArray(); + }, + static (data, testCase, context) => +{ + context.Information("Testing {0}", testCase.TargetFramework); - Information("Testing netstandard2"); - - DotNetCoreExecute( - "./tools/Cake.CoreCLR/Cake.dll", - testArguments.Aggregate( - ProcessArgumentBuilder.FromString("testnetstandard2.cake"), - (args, kv) => args.AppendSwitchQuoted(string.Concat("--", kv.Key), "=", kv.Value), - args => args - ) - ); - }; - - if (TravisCI.IsRunningOnTravisCI) - { - using(TravisCI.Fold("Execute-Tests")) - { - executeTests(); - return; - } - } - - executeTests(); + context.CakeExecuteScript( + testCase.FilePath, + testCase.CakeSettings + ); }); Task("Upload-AppVeyor-Artifacts") .IsDependentOn("Create-NuGet-Package") .IsDependentOn("Test") - .WithCriteria(() => !isLocalBuild) - .Does(() => + .WithCriteria(static data => !data.IsLocalBuild) + .Does(data => { - // Get the path to the package. - var package = nugetRoot + "Cake.Git." + semVersion + ".nupkg"; - // Upload Artifact - AppVeyor.UploadArtifact(package); + AppVeyor.UploadArtifact(data.BuildPaths.Package); +}); + + +Task("Upload-GitHubActions-Artifacts") + .IsDependentOn("Create-NuGet-Package") + .IsDependentOn("Test") + .WithCriteria(() => GitHubActions.IsRunningOnGitHubActions) + .Does(async data => +{ + // Upload Artifacts + var suffix = EnvironmentVariable("matrix-os") + ?? GitHubActions.Environment.Runner.OS; + Information("Uploading artifacts for {0}...", suffix); + await GitHubActions.Commands.UploadArtifact(data.BuildPaths.Package, string.Concat("NuGet-", suffix)); + await GitHubActions.Commands.UploadArtifact(data.BuildPaths.ArtifactsRoot, string.Concat("Artifacts-", suffix)); }); @@ -359,11 +312,45 @@ Task("Local-Tests") Task("AppVeyor") .IsDependentOn("Upload-AppVeyor-Artifacts"); -Task("Travis") - .IsDependentOn("Test"); +Task("GitHubActions") + .IsDependentOn("Upload-GitHubActions-Artifacts"); /////////////////////////////////////////////////////////////////////////////// // EXECUTION /////////////////////////////////////////////////////////////////////////////// RunTarget(target); + + +/////////////////////////////////////////////////////////////////////////////// +// RECORDS +/////////////////////////////////////////////////////////////////////////////// + +public record BuildPaths( + DirectoryPath ArtifactsRoot, + DirectoryPath NuGetRoot, + FilePath Package, + ICollection Solutions, + DirectoryPath AddinDir) +{ + public ICollection SolutionPaths { get; } = Solutions + .Select(solution => solution.GetDirectory()) + .ToArray(); +} + +public record BuildData( + bool IsLocalBuild, + string Configuration, + string Target, + ICollection TargetFrameworks, + DotNetMSBuildSettings MSBuildSettings, + NuGetPackSettings NuGetPackSettings, + AssemblyInfoSettings AssemblyInfoSettings, + BuildPaths BuildPaths); + +public record TestCase( + string TargetFramework, + CakeSettings CakeSettings) +{ + public FilePath FilePath { get; } = $"./test_{TargetFramework}.cake"; +} \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 412c72e..21821d2 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,94 +1,13 @@ -<# +$ErrorActionPreference = 'Stop' -.SYNOPSIS -This is a Powershell script to bootstrap a Cake build. +Set-Location -LiteralPath $PSScriptRoot -.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. +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1' +$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1' +$env:DOTNET_NOLOGO = '1' -.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 WhatIf -Performs a dry run of the build script. -No tasks will be executed. -.PARAMETER Experimental -Tells Cake to use the latest Roslyn release. +dotnet tool restore +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } -.LINK -http://cakebuild.net -#> - -Param( - [string]$Script = "build.cake", - [string]$Target = "Default", - [string]$Configuration = "Release", - [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] - [string]$Verbosity = "Verbose", - [Alias("DryRun","Noop")] - [switch]$WhatIf -) - -$TOOLS_DIR = Join-Path $PSScriptRoot "tools" -$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" -$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" -$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" - -# Is this a dry run? -$UseDryRun = ""; -if($WhatIf.IsPresent) { - $UseDryRun = "-dryrun" -} - -# Make sure tools folder exists -if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { - New-Item -path $TOOLS_DIR -name logfiles -itemtype directory -} - -# Try download NuGet.exe if not exists -if (!(Test-Path $NUGET_EXE)) { - Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $NUGET_EXE -} - -# Make sure NuGet exists where we expect it. -if (!(Test-Path $NUGET_EXE)) { - Throw "Could not find NuGet.exe" -} - -# Save nuget.exe path to environment to be available to child processed -$ENV:NUGET_EXE = $NUGET_EXE - -# Restore tools from NuGet. -Push-Location -Set-Location $TOOLS_DIR - -# Restore packages -if (Test-Path $PACKAGES_CONFIG) -{ - Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion" -} -# Install just Cake if missing config -else -{ - Invoke-Expression "&`"$NUGET_EXE`" install Cake -ExcludeVersion" -} -Pop-Location -if ($LASTEXITCODE -ne 0) -{ - exit $LASTEXITCODE -} - -# Make sure that Cake has been installed. -if (!(Test-Path $CAKE_EXE)) { - Throw "Could not find Cake.exe" -} - -# Start Cake -Invoke-Expression "$CAKE_EXE `"$Script`" --target=`"$Target`" --configuration=`"$Configuration`" --verbosity=`"$Verbosity`" $UseDryRun" -exit $LASTEXITCODE +dotnet cake @args +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } diff --git a/build.sh b/build.sh index 2b700e0..31be886 100755 --- a/build.sh +++ b/build.sh @@ -1,84 +1,12 @@ #!/usr/bin/env bash -############################################################### -# This is the Cake bootstrapper script that is responsible for -# downloading Cake and all specified tools from NuGet. -############################################################### +set -euox pipefail -# Define directories. -SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -TOOLS_DIR=$SCRIPT_DIR/tools -NUGET_EXE=$TOOLS_DIR/nuget.exe -CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe +cd "$(dirname "${BASH_SOURCE[0]}")" -# Define default arguments. -SCRIPT="build.cake" -TARGET="Travis" -CONFIGURATION="Release" -VERBOSITY="verbose" -DRYRUN= -SHOW_VERSION=false -SCRIPT_ARGUMENTS=() +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +export DOTNET_NOLOGO=1 -export PATH=$TOOLS_DIR:$PATH +dotnet tool restore -# Parse arguments. -for i in "$@"; do - case $1 in - -s|--script) SCRIPT="$2"; shift ;; - -t|--target) TARGET="$2"; shift ;; - -c|--configuration) CONFIGURATION="$2"; shift ;; - -v|--verbosity) VERBOSITY="$2"; shift ;; - -d|--dryrun) DRYRUN="--dryrun" ;; - --version) SHOW_VERSION=true ;; - --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; - *) SCRIPT_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 http://cakebuild.net/download/bootstrapper/packages - if [ $? -ne 0 ]; then - echo "An error occured 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 occured while downloading nuget.exe." - exit 1 - fi -fi - -# Restore tools from NuGet. -pushd $TOOLS_DIR >/dev/null -mono $NUGET_EXE install -ExcludeVersion -if [ $? -ne 0 ]; then - echo "Could not restore NuGet packages." - exit 1 -fi -popd >/dev/null - -# 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 -if $SHOW_VERSION; then - exec mono $CAKE_EXE --version -else - exec mono $CAKE_EXE $SCRIPT --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" -fi \ No newline at end of file +dotnet cake "$@" diff --git a/src/Cake.Git/Cake.Git.csproj b/src/Cake.Git/Cake.Git.csproj index e5a3f9f..19a1901 100644 --- a/src/Cake.Git/Cake.Git.csproj +++ b/src/Cake.Git/Cake.Git.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net461;net5.0 + netcoreapp3.1;net5.0;net6.0 false $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb @@ -18,17 +18,10 @@ {08F0A5C3-0E9C-451D-B003-14FF73699BE1} - - - - - - - - - + + diff --git a/test.cake b/test.cake index f993074..d8b09b4 100644 --- a/test.cake +++ b/test.cake @@ -10,7 +10,7 @@ var target = Argument("target", "Default-Tests"); /////////////////////////////////////////////////////////////////////////////// var testRepo = MakeAbsolute(Directory("./TestRepo")); -var testInitalRepo = MakeAbsolute(Directory("./TestRepo/InitalRepo")); +var testInitialRepo = MakeAbsolute(Directory("./TestRepo/InitialRepo")); var testCloneRepo = MakeAbsolute(Directory("./TestRepo/CloneRepo")); var isLocalBuild = !AppVeyor.IsRunningOnAppVeyor; var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md"); @@ -23,7 +23,7 @@ var testUserEmail = "john@doe.com"; FilePath[] testFiles = null, testDeleteFiles = null, testModifyFiles = null; -GitCommit initalCommit = null, +GitCommit initialCommit = null, removeCommit = null, modifiedCommit = null; @@ -69,7 +69,7 @@ Teardown(ctx => } catch(Exception ex) { - Error("Failed to clean up test reop {0}\r\n{1}", testRepo, ex); + Error("Failed to clean up test repo {0}\r\n{1}", testRepo, ex); } }); @@ -94,8 +94,8 @@ Task("Git-Init") { Information("Creating repository..."); CreateDirectory(testRepo); - CreateDirectory(testInitalRepo); - var repo = GitInit(testInitalRepo); + CreateDirectory(testInitialRepo); + var repo = GitInit(testInitialRepo); if (!DirectoryExists(repo)) { throw new DirectoryNotFoundException (string.Format("Failed to create repository {0}", @@ -110,9 +110,9 @@ Task("Git-IsValidRepository-LocalRepo") .Does(() => { Information("Checking if local repository is recognized as a valid repository..."); - if (!GitIsValidRepository(testInitalRepo)) { + if (!GitIsValidRepository(testInitialRepo)) { throw new Exception(string.Format("Initialized repository at '{0}' is not a valid Git repository.", - testInitalRepo)); + testInitialRepo)); } }); @@ -136,7 +136,7 @@ Task("Create-Test-Files") .Range(1, 10) .Select( index=> { - FilePath filePath = testInitalRepo.CombineWithFilePath(string.Format("{0}.{1:000}", + FilePath filePath = testInitialRepo.CombineWithFilePath(string.Format("{0}.{1:000}", Guid.NewGuid(), index )); @@ -158,7 +158,7 @@ Task("Create-Untracked-Test-Files") .Range(1, 10) .Select( index=> { - FilePath filePath = testInitalRepo.CombineWithFilePath(string.Format("{0}.{1:000}", + FilePath filePath = testInitialRepo.CombineWithFilePath(string.Format("{0}.{1:000}", Guid.NewGuid(), index )); @@ -177,7 +177,7 @@ Task("Git-Init-Add") .Does(() => { Information("Adding test files..."); - GitAdd(testInitalRepo, testFiles); + GitAdd(testInitialRepo, testFiles); }); Task("Git-Init-Commit") @@ -185,18 +185,18 @@ Task("Git-Init-Commit") .Does(() => { Information("Committing files..."); - initalCommit = GitCommit(testInitalRepo, testUser, testUserEmail, "Inital commit"); - Information("Commit created:\r\n{0}", initalCommit); + initialCommit = GitCommit(testInitialRepo, testUser, testUserEmail, "Initial commit"); + Information("Commit created:\r\n{0}", initialCommit); }); Task("Git-Second-Commit") .IsDependentOn("Git-Init-Commit") .Does(() => { - var filePath = testInitalRepo.CombineWithFilePath(string.Format("{0}.new", Guid.NewGuid())); + var filePath = testInitialRepo.CombineWithFilePath(string.Format("{0}.new", Guid.NewGuid())); CreateRandomDataFile(Context, filePath); - GitAdd(testInitalRepo, filePath); - var secondCommit = GitCommit(testInitalRepo, testUser, testUserEmail, "Second commit"); + GitAdd(testInitialRepo, filePath); + var secondCommit = GitCommit(testInitialRepo, testUser, testUserEmail, "Second commit"); Information("Commit created:\r\n{0}", secondCommit); }); @@ -205,7 +205,7 @@ Task("Git-HasUncommitedChanges-Dirty") .Does(() => { Information("Checking if repository has uncommited changes..."); - if (!GitHasUncommitedChanges(testInitalRepo)) + if (!GitHasUncommitedChanges(testInitialRepo)) { throw new Exception("Repository doesn't report uncommited changes."); }; @@ -216,7 +216,7 @@ Task("Git-HasUncommitedChanges-Clean") .Does(() => { Information("Checking if repository has uncommited changes..."); - if (GitHasUncommitedChanges(testInitalRepo)) + if (GitHasUncommitedChanges(testInitialRepo)) { throw new Exception("Repository reports uncommited changes after commiting all files."); }; @@ -226,7 +226,7 @@ Task("Git-Init-Diff") .IsDependentOn("Git-Init-Commit") .Does(() => { - var diffFiles = GitDiff(testInitalRepo); + var diffFiles = GitDiff(testInitialRepo); foreach(var diffFile in diffFiles) { Information("{0}", diffFile); @@ -236,8 +236,8 @@ Task("Git-Init-Diff") Task("Git-Log-TipToCommitId") .IsDependentOn("Git-Second-Commit") .Does(() => -{ - var commits = GitLog(testInitalRepo, initalCommit.Sha); +{ + var commits = GitLog(testInitialRepo, initialCommit.Sha); foreach(var commit in commits) { Information("{0}", commit); @@ -248,7 +248,7 @@ Task("Git-Log-Tip") .IsDependentOn("Git-Init-Commit") .Does(() => { - var commit = GitLogTip(testInitalRepo); + var commit = GitLogTip(testInitialRepo); Information("{0}", commit); }); @@ -256,7 +256,7 @@ Task("Git-Log-TipToRange") .IsDependentOn("Git-Init-Commit") .Does(() => { - var commits = GitLog(testInitalRepo, byte.MaxValue); + var commits = GitLog(testInitialRepo, byte.MaxValue); foreach(var commit in commits) { Information("{0}", commit); @@ -267,7 +267,7 @@ Task("Git-Log-Lookup") .IsDependentOn("Git-Init-Commit") .Does(() => { - var commit = GitLogLookup(testInitalRepo, initalCommit.Sha); + var commit = GitLogLookup(testInitialRepo, initialCommit.Sha); Information("{0}", commit); }); @@ -277,7 +277,7 @@ Task("Git-Remove") { Information("Removing files..."); testDeleteFiles = testFiles.Take(5).ToArray(); - GitRemove(testInitalRepo, true, testDeleteFiles); + GitRemove(testInitialRepo, true, testDeleteFiles); var existingFiles = testDeleteFiles.Where(FileExists).ToList(); if (existingFiles.Count > 0) { @@ -296,7 +296,7 @@ Task("Git-Remove-Commit") .Does(() => { Information("Committing removed files..."); - removeCommit = GitCommit(testInitalRepo, testUser, testUserEmail, "Remove commit"); + removeCommit = GitCommit(testInitialRepo, testUser, testUserEmail, "Remove commit"); Information("Commit created:\r\n{0}", removeCommit); }); @@ -304,7 +304,7 @@ Task("Git-Remove-Diff") .IsDependentOn("Git-Remove-Commit") .Does(() => { - var diffFiles = GitDiff(testInitalRepo, removeCommit.Sha); + var diffFiles = GitDiff(testInitialRepo, removeCommit.Sha); foreach(var diffFile in diffFiles) { Information("{0}", diffFile); @@ -346,7 +346,7 @@ Task("Git-Modify-Add") .Does(() => { Information("Adding modified test files..."); - GitAdd(testInitalRepo, testModifyFiles); + GitAdd(testInitialRepo, testModifyFiles); }); Task("Git-Modify-AddAll") @@ -354,7 +354,7 @@ Task("Git-Modify-AddAll") .Does(() => { Information("Adding modified test files..."); - GitAddAll(testInitalRepo); + GitAddAll(testInitialRepo); }); Task("Git-Modify-Unstage") @@ -362,16 +362,16 @@ Task("Git-Modify-Unstage") .Does(() => { Information("Unstaging added test files..."); - if (!GitHasStagedChanges(testInitalRepo)) + if (!GitHasStagedChanges(testInitialRepo)) { throw new Exception("Repository doesn't report indexed changes."); }; - GitUnstageAll(testInitalRepo); - if (GitHasStagedChanges(testInitalRepo)) + GitUnstageAll(testInitialRepo); + if (GitHasStagedChanges(testInitialRepo)) { throw new Exception("Repository does report indexed changes."); }; - GitAdd(testInitalRepo, testModifyFiles); + GitAdd(testInitialRepo, testModifyFiles); }); Task("Git-Modify-Commit") @@ -379,7 +379,7 @@ Task("Git-Modify-Commit") .Does(() => { Information("Committing modified files..."); - modifiedCommit = GitCommit(testInitalRepo, testUser, testUserEmail, "Modified commit"); + modifiedCommit = GitCommit(testInitialRepo, testUser, testUserEmail, "Modified commit"); Information("Commit created:\r\n{0}", modifiedCommit); }); @@ -387,7 +387,7 @@ Task("Git-Modify-Diff") .IsDependentOn("Git-Modify-Commit") .Does(() => { - var diffFiles = GitDiff(testInitalRepo, modifiedCommit.Sha); + var diffFiles = GitDiff(testInitialRepo, modifiedCommit.Sha); foreach(var diffFile in diffFiles) { Information("{0}", diffFile); @@ -469,16 +469,16 @@ Task("Git-Find-Root-From-Path") .IsDependentOn("Git-Modify-Commit") .Does(() => { - var deepFolder = testInitalRepo.Combine("test-folder/deep"); + var deepFolder = testInitialRepo.Combine("test-folder/deep"); CreateDirectory(deepFolder); var rootFolder = GitFindRootFromPath(deepFolder); Information("Git root folder found: {0}", rootFolder); - if (rootFolder.FullPath != testInitalRepo.FullPath) - throw new Exception(string.Format("Wrong git root found (actual: {0}, expected: {1})", rootFolder, testInitalRepo)); + if (rootFolder.FullPath != testInitialRepo.FullPath) + throw new Exception(string.Format("Wrong git root found (actual: {0}, expected: {1})", rootFolder, testInitialRepo)); }); Task("Git-Find-Root-From-Path-TempDirectory") - .Does(() => + .Does(() => { var tempPath = System.IO.Path.GetTempPath(); Information("Attempting to resolve Git root directory from temp directory '{0}'...", tempPath); @@ -500,35 +500,35 @@ Task("Git-Tag-Apply-Objectish") .IsDependentOn("Git-Modify-Commit") .Does(() => { - GitTag(testInitalRepo, "test-tag-objectish", modifiedCommit.Sha); + GitTag(testInitialRepo, "test-tag-objectish", modifiedCommit.Sha); }); Task("Git-Annotated-Tag-Apply-Objectish") .IsDependentOn("Git-Modify-Commit") .Does(() => { - GitTag(testInitalRepo, "test-annotated-tag-objectish", modifiedCommit.Sha, testUser, testUserEmail, "Test annotated tag. (objectish)"); + GitTag(testInitialRepo, "test-annotated-tag-objectish", modifiedCommit.Sha, testUser, testUserEmail, "Test annotated tag. (objectish)"); }); Task("Git-Tag-Apply") .IsDependentOn("Git-Tag-Apply-Objectish") .Does(() => { - GitTag(testInitalRepo, "test-tag"); + GitTag(testInitialRepo, "test-tag"); }); Task("Git-Annotated-Tag-Apply") .IsDependentOn("Git-Modify-Commit") .Does(() => { - GitTag(testInitalRepo, "test-annotated-tag", testUser, testUserEmail, "Test annotated tag."); + GitTag(testInitialRepo, "test-annotated-tag", testUser, testUserEmail, "Test annotated tag."); }); Task("Git-AllTags") .IsDependentOn("Git-Tag") .Does(()=> { - var tags = GitTags(testInitalRepo); + var tags = GitTags(testInitialRepo); if(tags.Count(t=>t.FriendlyName == "test-tag") < 1) throw new Exception("test-tag not found"); if(tags.Count(t=>t.FriendlyName == "test-tag-objectish") < 1) @@ -539,7 +539,7 @@ Task("Git-AllTags-Annotated") .IsDependentOn("Git-Tag-Annotated") .Does(()=> { - var tags = GitTags(testInitalRepo); + var tags = GitTags(testInitialRepo); if(tags.Count(t=>t.FriendlyName == "test-annotated-tag") < 1) throw new Exception("test-annotated-tag not found"); if(tags.Count(t=>t.FriendlyName == "test-annotated-tag-objectish") < 1) @@ -550,7 +550,7 @@ Task("Git-AllTags-Targets") .IsDependentOn("Git-Tag-Annotated") .Does(() => { - var tags = GitTags(testInitalRepo, loadTargets: true); + var tags = GitTags(testInitialRepo, loadTargets: true); foreach (var tag in tags) { @@ -564,7 +564,7 @@ Task("Git-Describe-Generic") .IsDependentOn("Git-Tag") .Does(() => { - var tag = GitDescribe(testInitalRepo); + var tag = GitDescribe(testInitialRepo); Information("Describe returned: [{0}]", tag); if (!tag.Contains("test-tag")) throw new Exception("Wrong described tag: " + tag); @@ -574,7 +574,7 @@ Task("Git-Describe-Tags") .IsDependentOn("Git-Tag") .Does(() => { - var tag = GitDescribe(testInitalRepo, GitDescribeStrategy.Tags); + var tag = GitDescribe(testInitialRepo, GitDescribeStrategy.Tags); Information("Describe returned: [{0}]", tag); if (!tag.Contains("test-tag")) throw new Exception("Wrong described tag: " + tag); @@ -584,8 +584,8 @@ Task("Git-Describe-Long") .IsDependentOn("Git-Tag") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, true, GitDescribeStrategy.Tags); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, false, GitDescribeStrategy.Tags); + var tagAlwaysLong = GitDescribe(testInitialRepo, true, GitDescribeStrategy.Tags); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, false, GitDescribeStrategy.Tags); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!tagAlwaysLong.StartsWith("test-tag")) throw new Exception("Wrong described tagAlwaysLong: " + tagAlwaysLong); @@ -597,8 +597,8 @@ Task("Git-Describe-Abbrev") .IsDependentOn("Git-Tag") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, true, GitDescribeStrategy.Tags, 16); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, false, GitDescribeStrategy.Tags, 16); + var tagAlwaysLong = GitDescribe(testInitialRepo, true, GitDescribeStrategy.Tags, 16); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, false, GitDescribeStrategy.Tags, 16); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!tagAlwaysLong.StartsWith("test-tag")) throw new Exception("Wrong described tagAlwaysLong: " + tagAlwaysLong); @@ -610,8 +610,8 @@ Task("Git-Describe-Commit") .IsDependentOn("Git-Tag") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, modifiedCommit.Sha, true, GitDescribeStrategy.Tags, 16); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, modifiedCommit.Sha, false, GitDescribeStrategy.Tags, 16); + var tagAlwaysLong = GitDescribe(testInitialRepo, modifiedCommit.Sha, true, GitDescribeStrategy.Tags, 16); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, modifiedCommit.Sha, false, GitDescribeStrategy.Tags, 16); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!tagAlwaysLong.StartsWith("test-tag")) throw new Exception("Wrong described tagAlwaysLong: " + tagAlwaysLong); @@ -623,8 +623,8 @@ Task("Git-Describe-Commit-NoTag") .IsDependentOn("Git-Tag") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, initalCommit.Sha, true, GitDescribeStrategy.Tags, 16); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, initalCommit.Sha, false, GitDescribeStrategy.Tags, 16); + var tagAlwaysLong = GitDescribe(testInitialRepo, initialCommit.Sha, true, GitDescribeStrategy.Tags, 16); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, initialCommit.Sha, false, GitDescribeStrategy.Tags, 16); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!string.IsNullOrEmpty(tagAlwaysLong)) throw new Exception("Wrong described tagAlwaysLong: " + tagAlwaysLong); @@ -636,8 +636,8 @@ Task("Git-Describe-Master") .IsDependentOn("Git-Tag") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, "master", true, GitDescribeStrategy.Tags, 16); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, "master", false, GitDescribeStrategy.Tags, 16); + var tagAlwaysLong = GitDescribe(testInitialRepo, "master", true, GitDescribeStrategy.Tags, 16); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, "master", false, GitDescribeStrategy.Tags, 16); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!tagAlwaysLong.StartsWith("test-tag")) throw new Exception("Wrong describe"); @@ -649,7 +649,7 @@ Task("Git-Describe-Generic-Annotated") .IsDependentOn("Git-Tag-Annotated") .Does(() => { - var tag = GitDescribe(testInitalRepo); + var tag = GitDescribe(testInitialRepo); Information("Describe returned: [{0}]", tag); if (!tag.Contains("test-annotated-tag")) throw new Exception("Wrong described tag: " + tag); @@ -659,7 +659,7 @@ Task("Git-Describe-Tags-Annotated") .IsDependentOn("Git-Tag-Annotated") .Does(() => { - var tag = GitDescribe(testInitalRepo, GitDescribeStrategy.Tags); + var tag = GitDescribe(testInitialRepo, GitDescribeStrategy.Tags); Information("Describe returned: [{0}]", tag); if (!tag.Contains("test-annotated-tag")) throw new Exception("Wrong described tag: " + tag); @@ -669,8 +669,8 @@ Task("Git-Describe-Long-Annotated") .IsDependentOn("Git-Tag-Annotated") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, true, GitDescribeStrategy.Tags); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, false, GitDescribeStrategy.Tags); + var tagAlwaysLong = GitDescribe(testInitialRepo, true, GitDescribeStrategy.Tags); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, false, GitDescribeStrategy.Tags); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!tagAlwaysLong.StartsWith("test-annotated-tag")) throw new Exception("Wrong described tagAlwaysLong: " + tagAlwaysLong); @@ -682,8 +682,8 @@ Task("Git-Describe-Abbrev-Annotated") .IsDependentOn("Git-Tag-Annotated") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, true, GitDescribeStrategy.Tags, 16); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, false, GitDescribeStrategy.Tags, 16); + var tagAlwaysLong = GitDescribe(testInitialRepo, true, GitDescribeStrategy.Tags, 16); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, false, GitDescribeStrategy.Tags, 16); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!tagAlwaysLong.StartsWith("test-annotated-tag")) throw new Exception("Wrong described tagAlwaysLong: " + tagAlwaysLong); @@ -695,8 +695,8 @@ Task("Git-Describe-Commit-Annotated") .IsDependentOn("Git-Tag-Annotated") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, modifiedCommit.Sha, true, GitDescribeStrategy.Tags, 16); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, modifiedCommit.Sha, false, GitDescribeStrategy.Tags, 16); + var tagAlwaysLong = GitDescribe(testInitialRepo, modifiedCommit.Sha, true, GitDescribeStrategy.Tags, 16); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, modifiedCommit.Sha, false, GitDescribeStrategy.Tags, 16); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!tagAlwaysLong.StartsWith("test-annotated-tag")) throw new Exception("Wrong described tagAlwaysLong: " + tagAlwaysLong); @@ -708,8 +708,8 @@ Task("Git-Describe-Commit-NoTag-Annotated") .IsDependentOn("Git-Tag-Annotated") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, initalCommit.Sha, true, GitDescribeStrategy.Tags, 16); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, initalCommit.Sha, false, GitDescribeStrategy.Tags, 16); + var tagAlwaysLong = GitDescribe(testInitialRepo, initialCommit.Sha, true, GitDescribeStrategy.Tags, 16); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, initialCommit.Sha, false, GitDescribeStrategy.Tags, 16); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!string.IsNullOrEmpty(tagAlwaysLong)) throw new Exception("Wrong described tagAlwaysLong: " + tagAlwaysLong); @@ -721,8 +721,8 @@ Task("Git-Describe-Master-Annotated") .IsDependentOn("Git-Tag-Annotated") .Does(() => { - var tagAlwaysLong = GitDescribe(testInitalRepo, "master", true, GitDescribeStrategy.Tags, 16); - var tagNotAlwaysLong = GitDescribe(testInitalRepo, "master", false, GitDescribeStrategy.Tags, 16); + var tagAlwaysLong = GitDescribe(testInitialRepo, "master", true, GitDescribeStrategy.Tags, 16); + var tagNotAlwaysLong = GitDescribe(testInitialRepo, "master", false, GitDescribeStrategy.Tags, 16); Information("Describe returned long: [{0}], !long: [{1}]", tagAlwaysLong, tagNotAlwaysLong); if (!tagAlwaysLong.StartsWith("test-annotated-tag")) throw new Exception("Wrong describe"); @@ -733,7 +733,7 @@ Task("Git-Describe-Master-Annotated") Task("Git-Current-Branch") .Does(() => { - var branch = GitBranchCurrent(testInitalRepo); + var branch = GitBranchCurrent(testInitialRepo); Information("Current branch: {0}", branch); }); @@ -741,10 +741,10 @@ Task("Git-Create-Branch-With-Checkout") .Does(() => { var branchName = "Foo-With-Checkout"; - var createdBranch = GitCreateBranch(testInitalRepo, branchName, true); + var createdBranch = GitCreateBranch(testInitialRepo, branchName, true); if (createdBranch.FriendlyName != branchName) throw new Exception($"Incorrect Branch returned. Expected {branchName} and got {createdBranch.FriendlyName}"); - var branch = GitBranchCurrent(testInitalRepo); + var branch = GitBranchCurrent(testInitialRepo); if (branch.FriendlyName != branchName) throw new Exception($"Incorrect Branch created. Expected {branchName} and got {branch.FriendlyName}"); }); @@ -753,11 +753,11 @@ Task("Git-Create-Branch-Without-Checkout") .Does(() => { var branchName = "Foo-Without-Checkout"; - var createdBranch = GitCreateBranch(testInitalRepo, branchName, false); + var createdBranch = GitCreateBranch(testInitialRepo, branchName, false); if (createdBranch.FriendlyName != branchName) throw new Exception($"Incorrect Branch returned. Expected {branchName} and got {createdBranch.FriendlyName}"); - GitCheckout(testInitalRepo, branchName); - var branch = GitBranchCurrent(testInitalRepo); + GitCheckout(testInitialRepo, branchName); + var branch = GitBranchCurrent(testInitialRepo); if (branch.FriendlyName != branchName) throw new Exception($"Incorrect Branch created. Expected {branchName} and got {branch.FriendlyName}"); }); @@ -772,8 +772,8 @@ Task("Git-Remote-Branch") Task("Git-Checkout") .Does(() => { - GitCheckout(testInitalRepo, "master"); - var branch = GitBranchCurrent(testInitalRepo); + GitCheckout(testInitialRepo, "master"); + var branch = GitBranchCurrent(testInitialRepo); if (branch.FriendlyName != "master") throw new Exception(string.Format("branch is incorrect. Expected master and got {0}", branch.FriendlyName)); }); @@ -795,7 +795,7 @@ Task("Git-Reset-Stage-File") .Does(() => { Information("Staging files..."); - GitAdd(testInitalRepo, testModifyFiles); + GitAdd(testInitialRepo, testModifyFiles); }); Task("Git-Reset-Hard") @@ -803,7 +803,7 @@ Task("Git-Reset-Hard") .Does(() => { Information("Performing hard reset on files..."); - GitReset(testInitalRepo, GitResetMode.Hard); + GitReset(testInitialRepo, GitResetMode.Hard); }); Task("Git-Clean") @@ -812,12 +812,12 @@ Task("Git-Clean") { Information("Performing hard reset on files..."); - if (!GitHasUntrackedFiles(testInitalRepo)) + if (!GitHasUntrackedFiles(testInitialRepo)) throw new InvalidOperationException("Repo contains no untracked files"); - GitClean(testInitalRepo); + GitClean(testInitialRepo); - if (GitHasUntrackedFiles(testInitalRepo)) + if (GitHasUntrackedFiles(testInitialRepo)) throw new InvalidOperationException("Git clean is not working properly"); }); @@ -826,20 +826,20 @@ Task("Git-Log-Tag") .IsDependentOn("Git-Describe-Annotated") .Does(() => { - var filePath = testInitalRepo.CombineWithFilePath(string.Format("{0}.new", Guid.NewGuid())); + var filePath = testInitialRepo.CombineWithFilePath(string.Format("{0}.new", Guid.NewGuid())); CreateRandomDataFile(Context, filePath); - GitAdd(testInitalRepo, filePath); - GitCommit(testInitalRepo, testUser, testUserEmail, "Third commit"); + GitAdd(testInitialRepo, filePath); + GitCommit(testInitialRepo, testUser, testUserEmail, "Third commit"); CreateRandomDataFile(Context, filePath); - GitAdd(testInitalRepo, filePath); - GitCommit(testInitalRepo, testUser, testUserEmail, "Fourth commit"); + GitAdd(testInitialRepo, filePath); + GitCommit(testInitialRepo, testUser, testUserEmail, "Fourth commit"); CreateRandomDataFile(Context, filePath); - GitAdd(testInitalRepo, filePath); - GitCommit(testInitalRepo, testUser, testUserEmail, "Fifth commit"); + GitAdd(testInitialRepo, filePath); + GitCommit(testInitialRepo, testUser, testUserEmail, "Fifth commit"); - var commitsSinceTag = GitLogTag(testInitalRepo, "test-tag"); + var commitsSinceTag = GitLogTag(testInitialRepo, "test-tag"); - ValidateGitLogTag(commitsSinceTag, "Third commit", "Fourth commit", "Fifth commit"); + ValidateGitLogTag(commitsSinceTag, "Third commit", "Fourth commit", "Fifth commit"); void ValidateGitLogTag(ICollection commits, params string[] commitMessages) { @@ -861,12 +861,12 @@ Task("Git-Log-Tag") Task("Git-Config") .Does(() => { - GitConfigSetLocal(testInitalRepo, "user.email", "bob@example.com"); - - if (GitConfigExists(testInitalRepo, "user.email")) + GitConfigSetLocal(testInitialRepo, "user.email", "bob@example.com"); + + if (GitConfigExists(testInitialRepo, "user.email")) { - string email = GitConfigGet(testInitalRepo, "user.email"); - + string email = GitConfigGet(testInitialRepo, "user.email"); + if (!string.Equals("bob@example.com", email)) { throw new InvalidOperationException("Wrong email in configuration."); @@ -880,25 +880,25 @@ Task("Git-ShortenSha-length") { // Arrange const int min = 20; - var commit = GitLogTip(testInitalRepo); + var commit = GitLogTip(testInitialRepo); // Act - var shortSha = GitShortenSha(testInitalRepo, commit, min); + var shortSha = GitShortenSha(testInitialRepo, commit, min); Information("Sha {0}", commit.Sha); Information("ShortSha {0}", shortSha); - - if(shortSha.Length < min) + + if(shortSha.Length < min) { throw new InvalidOperationException($"Short SHA is expected to have a minimal length of {min}."); } - if(shortSha.Length >= commit.Sha.Length) + if(shortSha.Length >= commit.Sha.Length) { throw new InvalidOperationException("Short SHA is expected to be shorter."); } - if(!commit.Sha.StartsWith(shortSha)) + if(!commit.Sha.StartsWith(shortSha)) { throw new InvalidOperationException("Short SHA is expected to match the start of the full SHA."); } @@ -909,19 +909,19 @@ Task("Git-ShortenSha-no-length") .Does(() => { // Arrange - var commit = GitLogTip(testInitalRepo); + var commit = GitLogTip(testInitialRepo); // Act - var shortSha = GitShortenSha(testInitalRepo, commit); + var shortSha = GitShortenSha(testInitialRepo, commit); Information("Sha {0}", commit.Sha); Information("ShortSha {0}", shortSha); - if(shortSha.Length >= commit.Sha.Length) + if(shortSha.Length >= commit.Sha.Length) { throw new InvalidOperationException("Short SHA is expected to be shorter."); } - if(!commit.Sha.StartsWith(shortSha)) + if(!commit.Sha.StartsWith(shortSha)) { throw new InvalidOperationException("Short SHA is expected to match the start of the full SHA."); } @@ -937,7 +937,7 @@ Task("Git-Fetch-Remote-Base") try { // Arrange: create a repo and a clone, then add a commit in "origin" - GitClone((IsRunningOnWindows() ? "" : "file://") + testInitalRepo.FullPath, originDir); + GitClone((IsRunningOnWindows() ? "" : "file://") + testInitialRepo.FullPath, originDir); GitClone((IsRunningOnWindows() ? "" : "file://") + originDir.FullPath, testDir); // Arrange: Add a commit in origin @@ -952,10 +952,10 @@ Task("Git-Fetch-Remote-Base") // Assert try - { + { var fetched = GitLogLookup(testDir, commit.Sha); Information("Commit found after fetch: {0}", fetched.Sha); - } + } catch(ArgumentNullException) { Error("expected commit not found after fetch."); @@ -984,10 +984,10 @@ Task("Git-Fetch-Remote-Tags") try { // Arrange: create a repo and a clone, then add a commit and a tag in "origin" - GitClone((IsRunningOnWindows() ? "" : "file://")+testInitalRepo.FullPath, originDir); + GitClone((IsRunningOnWindows() ? "" : "file://")+testInitialRepo.FullPath, originDir); GitClone((IsRunningOnWindows() ? "" : "file://")+originDir.FullPath, testDir); - // Arrange: Add a branch, commit and tag in origin and place it "before" our current commit. + // Arrange: Add a branch, commit and tag in origin and place it "before" our current commit. var someOldCommit = GitLog(originDir, 10).Last(); GitCheckout(originDir, someOldCommit.Sha); var newBranch = GitCreateBranch(originDir, Guid.NewGuid().ToString("d"), true); @@ -1184,10 +1184,10 @@ public static void CreateRandomDataFile(ICakeContext context, FilePath filePath) { var file = context.FileSystem.GetFile(filePath); - using (var rngCsp = new RNGCryptoServiceProvider()) + using (var rng = RandomNumberGenerator.Create()) { var data = new byte[128]; - rngCsp.GetBytes(data); + rng.GetBytes(data); var base64Data = Convert.ToBase64String(data, Base64FormattingOptions.InsertLineBreaks); using(var stream = file.OpenWrite()) { diff --git a/testnet50.cake b/test_net5.0.cake similarity index 100% rename from testnet50.cake rename to test_net5.0.cake diff --git a/test_net6.0.cake b/test_net6.0.cake new file mode 100644 index 0000000..ab71d93 --- /dev/null +++ b/test_net6.0.cake @@ -0,0 +1,2 @@ +#r "./tools/Addins/Cake.Git/Cake.Git/lib/net6.0/Cake.Git.dll" +#load test.cake \ No newline at end of file diff --git a/test_netcoreapp3.1.cake b/test_netcoreapp3.1.cake new file mode 100644 index 0000000..e7f4f51 --- /dev/null +++ b/test_netcoreapp3.1.cake @@ -0,0 +1,2 @@ +#r "./tools/Addins/Cake.Git/Cake.Git/lib/netcoreapp3.1/Cake.Git.dll" +#load test.cake \ No newline at end of file diff --git a/testnet461.cake b/testnet461.cake deleted file mode 100644 index 5ccf834..0000000 --- a/testnet461.cake +++ /dev/null @@ -1,2 +0,0 @@ -#r "./tools/Addins/Cake.Git/Cake.Git/lib/net461/Cake.Git.dll" -#load test.cake \ No newline at end of file diff --git a/testnetstandard2.cake b/testnetstandard2.cake deleted file mode 100644 index 3596390..0000000 --- a/testnetstandard2.cake +++ /dev/null @@ -1,2 +0,0 @@ -#r "./tools/Addins/Cake.Git/Cake.Git/lib/netstandard2.0/Cake.Git.dll" -#load test.cake \ No newline at end of file diff --git a/tools/packages.config b/tools/packages.config deleted file mode 100644 index bdb3769..0000000 --- a/tools/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - -