Skip to content

OnlyWhenStatic is not working on dependencies with default interface and TryDependsOn<> #1322

Closed
@m21-cerutti

Description

@m21-cerutti

Usage Information

Nuke version 8.0.0, .NET SDK version 8.0.101, .NET 8, Windows

Description

Trying to make a pipeline library for Nuke Build, with default pipeline and target dependency, when I fall inside a specific edge case with Build Components. Seems like TryDependsOn<> not assure to skip the target if the dependency is skipped when using interfaces.
Thinks it's linked to #1296 and available on Discord for more information.

Reproduction Steps

For easy reproduction :
https://gitlab.com/neitherlands/ouroboros/-/tree/test/dependency-nuke?ref_type=heads

Otherwise :

  1. Make two interface, one depending on the other
  2. Implement explicitly the interface in the Build
    Should look like that
using Nuke.Common;
using Nuke.Common.Execution;
using Serilog;

public interface ISkipped : INukeBuild
{
    public Target Skipped => _ => _
        .Executes(() => { Log.Information("Skipped"); });
}

public interface ITest : INukeBuild
{
    public Target Test => _ => _
        .TryDependsOn<ISkipped>()
        .Executes(() => { Log.Information("Test"); });
}

[UnsetVisualStudioEnvironmentVariables]
public class Build : NukeBuild, ISkipped, ITest
{
    public static int Main() => Execute<Build>(x => x.All);

    public Target All => _ => _
        .Triggers<ITest>();

    Target ISkipped.Skipped => _ => _
            .OnlyWhenStatic(() => !IsLocalBuild)
            .WhenSkipped(DependencyBehavior.Skip)
            .Inherit<ISkipped>();
}
  1. Then run in local

Expected Behavior

All targets would be skipped.

Actual Behavior

Test is not skipped.
image

Regression?

No response

Known Workarounds

Using a interface dependency with a function that checks SkippedTargets collection and see a particular step is skipped, than using it with OnlyWhenStatic on others targets.

Could you help with a pull-request?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions