nuke-build / nuke

🏗 The AKEless Build System for C#/.NET
https://nuke.build
MIT License
3.07k stars 369 forks source link

Dependencies are not skipped when the dependent is skipped #1414

Closed dennisdoomen closed 2 months ago

dennisdoomen commented 2 months ago

Usage Information

Nuke 8.0.0 / .NET 8.0.108 / Windows 11

Description

When I mark a target with OnlyWhenDynamic or OnlyWhenStatic and the condition is not met, the target is skipped. But its dependencies are still executed, even if the target is the only one that uses it.

Reproduction Steps

Target Restore => => .Executes(() => { });

Target Compile => => .OnlyWhenStatic(() => IsServerBuild) .DependsOn(Restore) .Executes(() => { });

Expected Behavior

When you run this locally, both the Compile and Restore steps should be skipped.

Actual Behavior

NUKE Execution Engine version 8.0.0 (Windows,.NETCoreApp,Version=v6.0)
​
​
╬════════════
║ Restore
╬═══
​
​
═══════════════════════════════════════
Target             Status      Duration
───────────────────────────────────────
Restore            Succeeded     < 1sec
Compile            Skipped                // OnlyWhen: IsServerBuild
───────────────────────────────────────
Total                            < 1sec
═══════════════════════════════════════
​
Build succeeded on 8-9-2024 09:34:57. \(^ᴗ^)/

Regression?

Yes, but I don't remember exactly in which version. Even in 6.3.0 it doesn't work as expected.

Also, .WhenSkipped(DependencyBehavior.Skip) doesn't make a difference.

Known Workarounds

Apply OnlyWhenDynamic on all targets

Could you help with a pull-request?

Yes

IT-VBFK commented 1 month ago

I am using 8.1.0, but this issue doesn't seem to be fixed?

A target (which is skipped) which depends on exactly one target runs this one target.

image
ITaluone commented 1 month ago

I also seeing this:

With the reproduction steps from this ticket and NUKE 8.1.1 I get following:

Target Restore => _ => _
        .Executes(() =>
        {
            Information($"Should not execute... {nameof(Restore)}");
        });

    Target Compile => _ => _
        .OnlyWhenStatic(() => IsServerBuild)
        .DependsOn(Restore)
        .Executes(() =>
        {
            Information($"Should not execute... {nameof(Compile)}");
        });

image

ITaluone commented 1 month ago

With 8.1.2 this is fixed ~for OnlyWhenStatic. OnlyWhenDynamic still runs the dependencies?~ As the documentation states, this is the desired behavior :)

Thanks @matkoch 🎉