Skip to content
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

fix(tools): kill child process on timeout #1306

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: mcr.microsoft.com/dotnet/sdk:5.0
image: mcr.microsoft.com/dotnet/sdk:8.0

variables:
GIT_DEPTH: 0
Expand Down
2 changes: 1 addition & 1 deletion .space.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ job("continuous") {
}
}

container("mcr.microsoft.com/dotnet/sdk:6.0") {
container("mcr.microsoft.com/dotnet/sdk:8.0") {
shellScript {
content = "./build.sh Test"
}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# docker build --no-cache --progress=plain -t my-image .
ARG registryUrl

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS builder
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS builder

WORKDIR /
COPY ./ /code
Expand Down
4 changes: 2 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ $DotNetGlobalFile = "$PSScriptRoot\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$DotNetChannel = "STS"

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_MULTILEVEL_LOOKUP = 0
$env:DOTNET_NOLOGO = 1
$env:DOTNET_ROLL_FORWARD = "Major"
$env:NUKE_TELEMETRY_OPTOUT = 1

Expand Down Expand Up @@ -72,6 +71,7 @@ else {
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
}
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
$env:PATH = "$DotNetDirectory;$env:PATH"
}

Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)"
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
DOTNET_CHANNEL="STS"

export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_MULTILEVEL_LOOKUP=0
export DOTNET_NOLOGO=1
export DOTNET_ROLL_FORWARD="Major"
export NUKE_TELEMETRY_OPTOUT=1

Expand Down Expand Up @@ -65,6 +64,7 @@ else
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
fi
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
export PATH="$DOTNET_DIRECTORY:$PATH"
fi

echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"
Expand Down
2 changes: 1 addition & 1 deletion build/Build.CI.SpaceAutomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[SpaceAutomation(
name: "continuous",
image: "mcr.microsoft.com/dotnet/sdk:6.0",
image: "mcr.microsoft.com/dotnet/sdk:8.0",
OnPush = true,
InvokedTargets = new[] { nameof(ITest.Test) })]
partial class Build
Expand Down
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
Expand Down
3 changes: 2 additions & 1 deletion docs/03-common/03-paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ var extensionWithDot = IndexFile.Extension;

// Get the parent directory
var parent1 = IndexFile.Parent;
var parent2 = IndexFile / ".."; // gets normalized
var parent2 = IndexFile / ..; // gets normalized
var parent3 = IndexFile / ".."; // gets normalized

// Check if one path contains another
var containsFile = SourceDirectory.Contains(IndexFile);
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.201",
"version": "8.0.100",
"rollForward": "latestMinor"
}
}
3 changes: 2 additions & 1 deletion source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<PropertyGroup>
<LangVersion>preview</LangVersion>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<NoWarn>CS1591;NU5129;NU5118</NoWarn>
<NoWarn>CS1591;NU5129;NU5118;SYSLIB0050;SYSLIB0051</NoWarn>
<DefineConstants>$(DefineConstants);JETBRAINS_ANNOTATIONS</DefineConstants>
<DebugType>embedded</DebugType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

<PropertyGroup>
Expand Down
98 changes: 98 additions & 0 deletions source/Nuke.Build.Shared/Notifications.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2023 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using System;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Utilities;

namespace Nuke.Build.Shared;

[PublicAPI]
internal record Notification(string Title, string Text, Link[] Links)
{
public string Title { get; } = Title;
public string Text { get; } = Text;
public Link[] Links { get; } = Links;
}

[PublicAPI]
internal record Link(string Text, string Url)
{
public string Text { get; } = Text;
public string Url { get; } = Url;
}

[PublicAPI]
internal class NotificationFetcher
{
private const string NotificationEndpoint = "https://nuke.build/notifications.json";
private const string UtmMedium = "development";

private readonly AbsolutePath _notificationDirectory = Constants.GlobalNukeDirectory / "received-notifications";
private readonly string _utmSource;

public NotificationFetcher(string utmSource)
{
_utmSource = utmSource;
}

public async Task<Notification> GetNotificationAsync()
{
try
{
return await GetNotificationInternal();
}
catch (Exception)
{
return null;
}
}

private async Task<Notification> GetNotificationInternal()
{
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(NotificationEndpoint);
if (!response.IsSuccessStatusCode)
return null;

var content = await response.Content.ReadAsStringAsync();
var json = JsonDocument.Parse(content).RootElement;

var notification = json.EnumerateArray()
.Where(IsApplicable)
.Select(x => (Json: x, File: _notificationDirectory / x.ToString().GetMD5Hash()))
.FirstOrDefault(x => !x.File.Exists());
if (notification.File == null)
return null;

notification.File.TouchFile();

return new Notification(
Title: notification.Json.GetProperty("title").GetString(),
Text: notification.Json.GetProperty("text").GetString(),
Links: notification.Json.GetProperty("links").EnumerateArray().Select(GetLink).ToArray());

bool IsApplicable(JsonElement element)
=> !element.TryGetProperty("exclude", out var exclusions) ||
!exclusions.EnumerateArray().Select(x => x.GetString()).Contains(_utmSource);

Link GetLink(JsonElement obj)
{
var originalUrl = new Uri(obj.GetProperty("url").GetString().NotNullOrEmpty())
.WithUtmValues(
medium: UtmMedium,
source: _utmSource,
campaign: obj.GetProperty("campaign").GetString());
return new Link(
Text: obj.GetProperty("title").GetString(),
Url: originalUrl.AbsoluteUri);
}
}
}
25 changes: 23 additions & 2 deletions source/Nuke.Build.Tests/BuildExecutorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void TestParameterSkipped_AllWithInvoked()
{
C.Invoked = true;
ExecuteBuild(skippedTargets: new ExecutableTarget[0]);
AssertSucceeded(C);
AssertSkipped(A, B);
AssertSucceeded();
AssertSkipped(A, B, C);
}

[Fact]
Expand Down Expand Up @@ -108,6 +108,27 @@ public void TestStaticCondition_DependencyBehavior_Skip()
B.OnlyWhen.Should().Be("false");
}

[Fact]
public void TestStaticCondition_Invoked_DependencyBehavior_Skip()
{
C.StaticConditions.Add(("() => false", () => false));
C.DependencyBehavior = DependencyBehavior.Skip;
C.Invoked = true;
ExecuteBuild();
AssertSkipped(A, B, C);
}

[Fact]
public void TestStaticCondition_Invoked_DependencyBehavior_Execute()
{
C.StaticConditions.Add(("() => false", () => false));
C.DependencyBehavior = DependencyBehavior.Execute;
C.Invoked = true;
ExecuteBuild();
AssertSkipped(C);
AssertSucceeded(A, B);
}

[Fact]
public void TestStaticCondition_Multiple()
{
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Build/Execution/BuildExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ string Format(string condition)

private static void MarkTargetSkipped(INukeBuild build, ExecutableTarget target, string reason = null)
{
if (target.Invoked || target.Status != ExecutionStatus.Scheduled)
if (target.Status != ExecutionStatus.Scheduled)
return;

target.Status = ExecutionStatus.Skipped;
Expand Down
14 changes: 8 additions & 6 deletions source/Nuke.Build/Execution/DelegateRequirementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ public static void ValidateRequirements(INukeBuild build, IReadOnlyCollection<Ex
if (requirement is Expression<Func<bool>> boolExpression)
// TODO: same as HasSkippingCondition.GetSkipReason
Assert.True(boolExpression.Compile().Invoke(), $"Target '{target.Name}' requires '{requirement.Body}'");
else if (IsMemberNull(requirement.GetMemberInfo(), build, target))
Assert.Fail($"Target '{target.Name}' requires member '{GetMemberName(requirement.GetMemberInfo())}' to be not null");
else if (IsMemberNullOrEmpty(requirement.GetMemberInfo(), build, target))
Assert.Fail($"Target '{target.Name}' requires member '{GetMemberName(requirement.GetMemberInfo())}' to be not null or empty");
}

var requiredMembers = ValueInjectionUtility.GetInjectionMembers(build.GetType())
.Select(x => x.Member)
.Where(x => x.HasCustomAttribute<RequiredAttribute>());
foreach (var member in requiredMembers)
{
if (IsMemberNull(member, build))
Assert.Fail($"Member '{GetMemberName(member)}' is required to be not null");
if (IsMemberNullOrEmpty(member, build))
Assert.Fail($"Member '{GetMemberName(member)}' is required to be not null or empty");
}
}

private static bool IsMemberNull(MemberInfo member, INukeBuild build, ExecutableTarget target = null)
private static bool IsMemberNullOrEmpty(MemberInfo member, INukeBuild build, ExecutableTarget target = null)
{
member = member.DeclaringType != build.GetType()
? build.GetType().GetMember(member.Name).SingleOrDefault() ?? member
Expand All @@ -52,7 +52,9 @@ private static bool IsMemberNull(MemberInfo member, INukeBuild build, Executable
if (build.Host is Terminal)
TryInjectValueInteractive(member, build);

return member.GetValue(build) == null;
return member.GetMemberType() != typeof(string)
? member.GetValue(build) == null
: member.GetValue<string>(build).IsNullOrWhiteSpace();
}

private static void TryInjectValueInteractive(MemberInfo member, INukeBuild build)
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Build/Execution/ToolRequirementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void InstallNuGetPackages(IReadOnlyCollection<NuGetPackageRequire
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions source/Nuke.Common/Nuke.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<PropertyGroup>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<MSBuildWarningsAsErrors>$(MSBuildWarningsAsErrors);CS8785</MSBuildWarningsAsErrors>
<NoWarn>$(NoWarn);SYSLIB0050;SYSLIB0051</NoWarn>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions source/Nuke.Common/Tools/SonarScanner/SonarScanner.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"name": "Verbose",
"type": "bool",
"format": "/d:sonar.verbose={value}",
"customValue": true,
"help": "Sets the logging verbosity to detailed. Add this argument before sending logs for troubleshooting."
},
{
Expand Down
6 changes: 5 additions & 1 deletion source/Nuke.GlobalTool.Tests/cake-scripts/paths.verified.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -40,9 +40,13 @@
class Build : NukeBuild
{
AbsolutePath LocalPackagesDir => RootDirectory / ".." / "LocalPackages";

AbsolutePath SourceFolder => RootDirectory / "source";

AbsolutePath PublishDir => RootDirectory / "publish";

AbsolutePath SignToolPath => RootDirectory / "certificates" / "signtool.exe";

private string Convert(AbsolutePath file)
{
file = (AbsolutePath)file;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -46,6 +46,7 @@ class Build : NukeBuild
System.Console.WriteLine();
});


Target B => _ => _
.DependsOn(A)
.DependentFor(A)
Expand All @@ -54,6 +55,7 @@ class Build : NukeBuild
System.Console.WriteLine();
});


Target C_1 => _ => _
.DependsOn(B)
.OnlyWhenStatic(() => staticCondition)
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.GlobalTool/Program.Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ partial class Program
{
// ReSharper disable InconsistentNaming

private const string TARGET_FRAMEWORK = "net6.0";
private const string TARGET_FRAMEWORK = "net8.0";
private const string PROJECT_KIND = "9A19103F-16F7-4668-BE54-9A1E7A4F7556";

// ReSharper disable once CognitiveComplexity
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.GlobalTool/ProjectUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Update(string projectFile)

private static void UpdateTargetFramework(Microsoft.Build.Evaluation.Project buildProject)
{
buildProject.SetProperty("TargetFramework", "net6.0");
buildProject.SetProperty("TargetFramework", "net8.0");
}

private static void UpdateNukeCommonPackage(Microsoft.Build.Evaluation.Project buildProject, out FloatRange previousPackageVersion)
Expand Down
Loading
Loading