New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithCriteria<DataObject> does not work with 'DryRun' (WhatIf flag) #2208

Closed
jpdavid opened this Issue Jul 2, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@jpdavid

jpdavid commented Jul 2, 2018

What You Are Seeing?

"The context data has not been setup"

What is Expected?

Build script completes without error, respecting any custom data provided in the 'Setup' tasks.

What version of Cake are you using?

0.28.0

Are you running on a 32 or 64 bit system?

64-bit

What environment are you running on? Windows? Linux? Mac?

Windows

Are you running on a CI Server? If so, which one?

No

How Did You Get This To Happen? (Steps to Reproduce)

Using the following in the build.cake file:

public class TestConfig
{
public bool SomeVar { get; set; }
}

Setup((context) =>
{
return new TestConfig() { SomeVar = false };
});

Task("A")
.Does((context, data) =>
{
Information($"SomeVar = {data.SomeVar}");
});

Task("B")
.IsDependentOn("A")
.WithCriteria((context, data) => data.SomeVar)
.Does((context, data) =>
{
Information($"SomeVar = {data.SomeVar}");
});

Task("Default").IsDependentOn("B");

RunTarget("Default");

Run build.ps1 -WhatIf

Output Log

Preparing to run build script...
Running build script...
Performing dry run...
Target is: Default

  1. A
    Error: One or more errors occurred.
    The context data has not been setup.

@jpdavid jpdavid changed the title from Setup<DataObject> does not work with 'DryRun' (WhatIf flag) to WithCriteria<DataObject> does not work with 'DryRun' (WhatIf flag) Jul 2, 2018

@jpdavid

This comment has been minimized.

jpdavid commented Jul 9, 2018

@devlead I have had some thoughts on this.

I understand that with the DryRun execution, you don't want to run any task action code, including setup tasks. This makes perfect sense.

Would it be a good idea to move the Data Object setup code into its own type of Setup task?

e.g.

public class MyBuildData
{
}

DataSetup(dataSetupContext =>
{
return new MyBuildData();
});

Setup(setupContext => {
// Do some stuff
});

DataSetup tasks can always run (regardless of whether it is a dry run) and Setup tasks can remain as they are.

@patriksvensson

This comment has been minimized.

Member

patriksvensson commented Aug 19, 2018

@jpdavid I'm taking a look at this one.

@patriksvensson

This comment has been minimized.

Member

patriksvensson commented Aug 19, 2018

@jpdavid I submitted a pull request. Setup and Teardown should be executed when running a dry run strategy. Setup and Teardown should never contain any code with side effects, and should be idempotent.

pascalberger pushed a commit to pascalberger/cake that referenced this issue Sep 16, 2018

Merge branch 'patriksvensson-bug/cake-buildGH-2208' into develop
* patriksvensson-bug/cake-buildGH-2208:
  Added alias for checking if the current run is a dry run.
  Execute setup and teardown when dry running script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment