Skip to content

Commit

Permalink
11 upgrade to support grate 180 (#12)
Browse files Browse the repository at this point in the history
* Added the IsUpToDate flag to the addin and unit tests

* Code hygiene changes

* Bump version to 1.8.0 and test

---------

Co-authored-by: Fran Hoey <[email protected]>
  • Loading branch information
franhoey and Fran Hoey authored Oct 25, 2024
1 parent 067bfff commit 14a1194
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 15 deletions.
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"cake.tool": {
"version": "4.2.0",
"commands": [
"dotnet-cake"
],
"rollForward": false
}
}
}
3 changes: 2 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});


Expand Down
19 changes: 17 additions & 2 deletions demo/frosting/build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -48,6 +48,20 @@ public override void Run(FrostingContext context)
}
}

[TaskName("IsUpToDate")]
public sealed class IsUpToDate : FrostingTask<FrostingContext>
{
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<FrostingContext>
{
Expand Down Expand Up @@ -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))]
Expand Down
Binary file modified demo/frosting/grate-admin-functions.bak
Binary file not shown.
14 changes: 13 additions & 1 deletion demo/script/build.cake
Original file line number Diff line number Diff line change
@@ -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"

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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(() =>
{
Expand Down Expand Up @@ -106,6 +117,7 @@ Task("UserTokens")

Task("Default")
.IsDependentOn("Core-Functions")
.IsDependentOn("IsUpToDate")
.IsDependentOn("Admin")
.IsDependentOn("DryRun")
.IsDependentOn("Baseline")
Expand Down
Binary file modified demo/script/grate-admin-functions.bak
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.grate.Tests/GrateRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -168,7 +169,6 @@ public void Should_Execute_Process_With_User_Tokens()
};
fixture.Settings.WithUserToken("b", "banana");


// When
var result = fixture.Run();

Expand Down
3 changes: 2 additions & 1 deletion src/Cake.grate/GrateRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GrateRunner : Tool<GrateSettings>
/// <param name="environment">An <see cref="ICakeEnvironment"/>.</param>
/// <param name="processRunner">An <see cref="IProcessRunner"/>.</param>
/// <param name="tools">An <see cref="IToolLocator"/>.</param>
/// <param name="verbosity">The verbosity or the logging</param>
/// <param name="verbosity">The verbosity or the logging.</param>
public GrateRunner(
IFileSystem fileSystem,
ICakeEnvironment environment,
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion src/Cake.grate/GrateSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public sealed class GrateSettings : ToolSettings
/// </value>
public string Version { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to check if the database is up to date or not.
/// </summary>
/// <value>
/// If true outputs whether the database is up to date or not (whether any non-everytime scripts would be run).
/// </value>
public bool IsUpToDate { get; set; }

/// <summary>
/// Gets or sets the schema name to use instead of [grate].
/// </summary>
Expand Down Expand Up @@ -200,7 +208,7 @@ public sealed class GrateSettings : ToolSettings
public bool DisableTokenReplacement { get; set; }

/// <summary>
/// Gets or sets a dictionary of user tokens
/// Gets or sets a dictionary of user tokens.
/// </summary>
/// <value>
/// Allows grate to perform token replacement on custom tokens.
Expand Down
30 changes: 24 additions & 6 deletions src/Cake.grate/GrateSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// MIT License

Check warning on line 1 in src/Cake.grate/GrateSettingsExtensions.cs

View workflow job for this annotation

GitHub Actions / build

//
// 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
{
Expand All @@ -15,7 +33,7 @@ public static class GrateSettingsExtensions
/// Adds a UserToken to the settings.
/// </summary>
/// <param name="settings">The settings.</param>
/// <param name="name">The name of the user token (-usertokens [key]=[value]).</param>
/// <param name="key">The name of the user token (-usertokens [key]=[value]).</param>
/// <param name="value">The value of the user token (-usertokens [key]=[value]).</param>
/// <returns>The same <see cref="GrateSettings"/> instance so that multiple calls can be chained.</returns>
public static GrateSettings WithUserToken(this GrateSettings settings, string key, string value)
Expand Down

0 comments on commit 14a1194

Please sign in to comment.