diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..f079c76 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "4.2.0", + "commands": [ + "dotnet-cake" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/build.cake b/build.cake index 2326a9c..4fb351a 100644 --- a/build.cake +++ b/build.cake @@ -92,7 +92,8 @@ Task("Default") { Information(@"The following tasks are available: -Build-And-Test: Builds the Addin and runs the Unit Tests"); +Build-And-Test: Builds the Addin and runs the Unit Tests +Deploy: Runs Build-And-Test and then packs and deploys the Nuget package"); }); diff --git a/demo/frosting/build/Program.cs b/demo/frosting/build/Program.cs index c317d42..a646360 100644 --- a/demo/frosting/build/Program.cs +++ b/demo/frosting/build/Program.cs @@ -10,7 +10,7 @@ public static class Program public static int Main(string[] args) { return new CakeHost() - .InstallTool(new Uri("dotnet:?package=grate&version=1.7.4")) + .InstallTool(new Uri("dotnet:?package=grate&version=1.8.0")) .Run(args); } } @@ -48,6 +48,20 @@ public override void Run(FrostingContext context) } } +[TaskName("IsUpToDate")] +public sealed class IsUpToDate : FrostingTask +{ + public override void Run(FrostingContext context) + { + context.Grate(new GrateSettings() + { + ConnectionString = "Server=(local);Database=grate-dry-run;Trusted_Connection=True;TrustServerCertificate=true;", + IsUpToDate = true, + Silent = true + }); + } +} + [TaskName("Admin")] public sealed class Admin : FrostingTask { @@ -125,7 +139,8 @@ public override void Run(FrostingContext context) [TaskName("Default")] [IsDependentOn(typeof(CoreFunctions))] -//[IsDependentOn(typeof(Admin))] +[IsDependentOn(typeof(IsUpToDate))] +[IsDependentOn(typeof(Admin))] [IsDependentOn(typeof(DryRun))] [IsDependentOn(typeof(Baseline))] [IsDependentOn(typeof(UserTokens))] diff --git a/demo/frosting/grate-admin-functions.bak b/demo/frosting/grate-admin-functions.bak index 00187c9..58f6614 100644 Binary files a/demo/frosting/grate-admin-functions.bak and b/demo/frosting/grate-admin-functions.bak differ diff --git a/demo/script/build.cake b/demo/script/build.cake index d8ad6d5..4c10533 100644 --- a/demo/script/build.cake +++ b/demo/script/build.cake @@ -1,5 +1,5 @@ -#tool "dotnet:?package=grate&version=1.7.4" +#tool "dotnet:?package=grate&version=1.8.0" #r "..\..\src\Cake.grate\bin\Debug\net8.0\Cake.grate.dll" /////////////////////////////////////////////////////////////////////////////// @@ -41,6 +41,17 @@ Task("Core-Functions") }); }); +Task("IsUpToDate") +.Does(() => +{ + Grate(new GrateSettings() + { + ConnectionString = "Server=(local);Database=grate-dry-run;Trusted_Connection=True;TrustServerCertificate=true;", + IsUpToDate = true, + Silent = true + }); +}); + Task("Admin") .Does(() => { @@ -106,6 +117,7 @@ Task("UserTokens") Task("Default") .IsDependentOn("Core-Functions") + .IsDependentOn("IsUpToDate") .IsDependentOn("Admin") .IsDependentOn("DryRun") .IsDependentOn("Baseline") diff --git a/demo/script/grate-admin-functions.bak b/demo/script/grate-admin-functions.bak index 00187c9..58f6614 100644 Binary files a/demo/script/grate-admin-functions.bak and b/demo/script/grate-admin-functions.bak differ diff --git a/readme.md b/readme.md index e57712b..c04d002 100644 --- a/readme.md +++ b/readme.md @@ -25,7 +25,7 @@ From the grate documentation: ## Usage ```cs -#tool "dotnet:?package=grate&version=1.7.4" +#tool "dotnet:?package=grate&version=1.8.0" #addin nuget:?package=Cake.grate Task("MyTask").Does(() => { diff --git a/src/Cake.grate.Tests/GrateRunnerTests.cs b/src/Cake.grate.Tests/GrateRunnerTests.cs index a7ed1e0..72bfe53 100644 --- a/src/Cake.grate.Tests/GrateRunnerTests.cs +++ b/src/Cake.grate.Tests/GrateRunnerTests.cs @@ -83,12 +83,13 @@ public void Should_Execute_Process_With_Flags() fixture.Settings.RunAllAnyTimeScripts = true; fixture.Settings.DisableTokenReplacement = true; fixture.Settings.DoNotStoreScriptsRunText = true; + fixture.Settings.IsUpToDate = true; // When var result = fixture.Run(); // Then - result.Args.Should().StartWith("--drop --dryrun --silent --baseline --disabletokens --runallanytimescripts --warnononetimescriptchanges --warnandignoreononetimescriptchanges --transaction --donotstorescriptsruntext"); + result.Args.Should().StartWith("--drop --dryrun --silent --baseline --disabletokens --runallanytimescripts --warnononetimescriptchanges --warnandignoreononetimescriptchanges --transaction --donotstorescriptsruntext --isuptodate"); } [Fact] @@ -168,7 +169,6 @@ public void Should_Execute_Process_With_User_Tokens() }; fixture.Settings.WithUserToken("b", "banana"); - // When var result = fixture.Run(); diff --git a/src/Cake.grate/GrateRunner.cs b/src/Cake.grate/GrateRunner.cs index eb18c99..8ecbb19 100644 --- a/src/Cake.grate/GrateRunner.cs +++ b/src/Cake.grate/GrateRunner.cs @@ -45,7 +45,7 @@ public class GrateRunner : Tool /// An . /// An . /// An . - /// The verbosity or the logging + /// The verbosity or the logging. public GrateRunner( IFileSystem fileSystem, ICakeEnvironment environment, @@ -127,6 +127,7 @@ private static void AddFlagArguments(ProcessArgumentBuilder builder, GrateSettin AppendFlag(builder, "warnandignoreononetimescriptchanges", settings.WarnAndIgnoreOnOneTimeScriptChanges); AppendFlag(builder, "transaction", settings.WithTransaction); AppendFlag(builder, "donotstorescriptsruntext", settings.DoNotStoreScriptsRunText); + AppendFlag(builder, "isuptodate", settings.IsUpToDate); } private static void AddDatabaseArguments(ProcessArgumentBuilder builder, GrateSettings settings) diff --git a/src/Cake.grate/GrateSettings.cs b/src/Cake.grate/GrateSettings.cs index 8bd1e8d..fe4841b 100644 --- a/src/Cake.grate/GrateSettings.cs +++ b/src/Cake.grate/GrateSettings.cs @@ -87,6 +87,14 @@ public sealed class GrateSettings : ToolSettings /// public string Version { get; set; } + /// + /// Gets or sets a value indicating whether to check if the database is up to date or not. + /// + /// + /// If true outputs whether the database is up to date or not (whether any non-everytime scripts would be run). + /// + public bool IsUpToDate { get; set; } + /// /// Gets or sets the schema name to use instead of [grate]. /// @@ -200,7 +208,7 @@ public sealed class GrateSettings : ToolSettings public bool DisableTokenReplacement { get; set; } /// - /// Gets or sets a dictionary of user tokens + /// Gets or sets a dictionary of user tokens. /// /// /// Allows grate to perform token replacement on custom tokens. diff --git a/src/Cake.grate/GrateSettingsExtensions.cs b/src/Cake.grate/GrateSettingsExtensions.cs index 0b85e38..f830f82 100644 --- a/src/Cake.grate/GrateSettingsExtensions.cs +++ b/src/Cake.grate/GrateSettingsExtensions.cs @@ -1,8 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// MIT License +// +// Copyright (c) 2023 Fran Hoey +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace Cake.Grate { @@ -15,7 +33,7 @@ public static class GrateSettingsExtensions /// Adds a UserToken to the settings. /// /// The settings. - /// The name of the user token (-usertokens [key]=[value]). + /// The name of the user token (-usertokens [key]=[value]). /// The value of the user token (-usertokens [key]=[value]). /// The same instance so that multiple calls can be chained. public static GrateSettings WithUserToken(this GrateSettings settings, string key, string value)