Skip to content
Merged
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
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ jobs:
uses: actions/setup-dotnet@v5.0.0
with:
dotnet-version: '10.0.x'
- name: 🚒 dotnet workload restore
continue-on-error: true
run: |
dotnet workload restore
- name: ⚒️ dotnet tool restore
run: |
dotnet tool restore
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/inputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ jobs:
uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493
with:
clean: 'false'
- name: 🚒 dotnet workload restore
continue-on-error: true
run: |
dotnet workload restore
- name: ⚒️ dotnet tool restore
run: |
dotnet tool restore
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ jobs:
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: 🚒 dotnet workload restore
continue-on-error: true
run: |
dotnet workload restore
- name: ⚒️ dotnet tool restore
run: |
dotnet tool restore
Expand Down
17 changes: 17 additions & 0 deletions src/Nuke/DotNetCore/DisableWorkloadRestoreAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Rocket.Surgery.Nuke.DotNetCore;

/// <summary>
/// A customized attribute to disable dotnet workload restore
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class DisableDotnetWorkloadRestoreAttribute : Attribute
{
/// <summary>
/// Represents an attribute used to disable the restoration of .NET workloads.
/// </summary>
/// <remarks>
/// This attribute, when applied to a class, sets the flag <c>Extensions.EnableDotNetWorkloadRestore</c>
/// to <c>false</c> to disable the restoration process for workloads during the build.
/// </remarks>
public DisableDotnetWorkloadRestoreAttribute() => Extensions.EnableDotNetWorkloadRestore = false;
}
22 changes: 13 additions & 9 deletions src/Nuke/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,14 @@ public static IEnumerable<AbsolutePath> Match(this IEnumerable<AbsolutePath> abs
/// <param name="target"></param>
/// <returns></returns>
public static ITargetDefinition Net9MsBuildFix(this ITargetDefinition target) => target
.Executes(
() =>
{
if (DisableNet9MsBuildFix) return;

EnvironmentInfo.SetVariable("MSBuildExtensionsPath", "");
EnvironmentInfo.SetVariable("MSBUILD_EXE_PATH", "");
EnvironmentInfo.SetVariable("MSBuildSDKsPath", "");
}
.Executes(() =>
{
if (DisableNet9MsBuildFix) return;

EnvironmentInfo.SetVariable("MSBuildExtensionsPath", "");
EnvironmentInfo.SetVariable("MSBUILD_EXE_PATH", "");
EnvironmentInfo.SetVariable("MSBuildSDKsPath", "");
}
);

/// <summary>
Expand Down Expand Up @@ -309,6 +308,11 @@ public static bool ShouldUpdate(this AbsolutePath path, TimeSpan? waitTime = nul
/// </summary>
public static bool DisableNet9MsBuildFix { get; set; }

/// <summary>
/// allow disabling dotnet workload restore.
/// </summary>
public static bool EnableDotNetWorkloadRestore { get; set; }

/// <summary>
/// allow disabling the temporary fix for net9 msbuild issues
/// </summary>
Expand Down
144 changes: 67 additions & 77 deletions src/Nuke/GithubActions/GitHubActionsStepsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ public override ConfigurationEntity GetConfiguration(IReadOnlyCollection<Executa
var inputs = attributes
.OfType<GitHubActionsInputAttribute>()
.Select(z => z.ToInput())
.SelectMany(
z =>
{
return new[]
{
new KeyValuePair<string, GitHubActionsInput>(z.Name, z),
new KeyValuePair<string, GitHubActionsInput>(z.Alias ?? z.Name.Pascalize(), z),
};
}
.SelectMany(z =>
{
return new[]
{
new KeyValuePair<string, GitHubActionsInput>(z.Name, z),
new KeyValuePair<string, GitHubActionsInput>(z.Alias ?? z.Name.Pascalize(), z),
};
}
)
.DistinctBy(z => z.Key, StringComparer.OrdinalIgnoreCase)
.ToDictionary(z => z.Key, z => z.Value, StringComparer.OrdinalIgnoreCase);
Expand Down Expand Up @@ -152,23 +151,21 @@ .. onePasswordServiceAccountSecrets
steps.AddRange(
onePasswordServiceAccountSecrets
.GroupBy(z => z.Secret)
.Select(
static secrets => new UsingStep($"Load 1Password Secrets ({secrets.Key})")
{
Id = secrets.First().OutputId,
Uses = "1password/load-secrets-action@v1",
Outputs = [.. secrets.Select(secret => new GitHubActionsOutput(secret.Name, secret.Description))],
With = new() { ["export-env"] = "false" },
Environment = Enumerable
.Select(static secrets => new UsingStep($"Load 1Password Secrets ({secrets.Key})")
{
Id = secrets.First().OutputId,
Uses = "1password/load-secrets-action@v1",
Outputs = [.. secrets.Select(secret => new GitHubActionsOutput(secret.Name, secret.Description))],
With = new() { ["export-env"] = "false" },
Environment = Enumerable
.Concat(
secrets
.Select(
z => new KeyValuePair<string, string>(
z.Name,
string.IsNullOrWhiteSpace(z.Variable)
? $"{z.Path}"
: $$$"""${{ vars.{{{z.Variable}}} }}/{{{z.Path.TrimStart('/')}}}"""
)
.Select(z => new KeyValuePair<string, string>(
z.Name,
string.IsNullOrWhiteSpace(z.Variable)
? $"{z.Path}"
: $$$"""${{ vars.{{{z.Variable}}} }}/{{{z.Path.TrimStart('/')}}}"""
)
),
[
new(
Expand All @@ -178,7 +175,7 @@ .. onePasswordServiceAccountSecrets
]
)
.ToDictionary(z => z.Key, z => z.Value),
}
}
)
);
}
Expand Down Expand Up @@ -211,23 +208,21 @@ .. onePasswordConnectServerSecrets
steps.AddRange(
onePasswordConnectServerSecrets
.GroupBy(z => $"{z.ConnectHost}, {z.ConnectToken}")
.Select(
static secrets => new UsingStep($"Load 1Password Secrets ({secrets.Key})")
{
Id = secrets.First().OutputId,
Uses = "1password/load-secrets-action@v1",
Outputs = [.. secrets.Select(secret => new GitHubActionsOutput(secret.Name, secret.Description))],
With = new() { ["export-env"] = "false" },
Environment = Enumerable
.Select(static secrets => new UsingStep($"Load 1Password Secrets ({secrets.Key})")
{
Id = secrets.First().OutputId,
Uses = "1password/load-secrets-action@v1",
Outputs = [.. secrets.Select(secret => new GitHubActionsOutput(secret.Name, secret.Description))],
With = new() { ["export-env"] = "false" },
Environment = Enumerable
.Concat(
secrets
.Select(
z => new KeyValuePair<string, string>(
z.Name,
string.IsNullOrWhiteSpace(z.Variable)
? $"{z.Path}"
: $$$"""${{ vars.{{{z.Variable}}} }}/{{{z.Path.TrimStart('/')}}}"""
)
.Select(z => new KeyValuePair<string, string>(
z.Name,
string.IsNullOrWhiteSpace(z.Variable)
? $"{z.Path}"
: $$$"""${{ vars.{{{z.Variable}}} }}/{{{z.Path.TrimStart('/')}}}"""
)
),
[
new(
Expand All @@ -241,7 +236,7 @@ .. onePasswordConnectServerSecrets
]
)
.ToDictionary(z => z.Key, z => z.Value),
}
}
)
);
}
Expand All @@ -252,14 +247,18 @@ .. onePasswordConnectServerSecrets
{
Run = "dotnet tool install -g Nuke.GlobalTool",
};
// TODO: Add configuration to disable this?
steps.Add(
new RunStep("dotnet workload restore")
{
Run = "dotnet workload restore",
ContinueOnError = true,
}
);

if (Extensions.EnableDotNetWorkloadRestore)
{
steps.Add(
new RunStep("dotnet workload restore")
{
Run = "dotnet workload restore",
ContinueOnError = true,
}
);
}

var dotnetTools = Path.Combine(NukeBuild.RootDirectory, ".config/dotnet-tools.json");
if (File.Exists(dotnetTools))
{
Expand All @@ -285,15 +284,14 @@ .. onePasswordConnectServerSecrets
environmentAttributes
)
// ReSharper enable CoVariantArrayConversion
.SelectMany(
z =>
{
return new[]
{
new KeyValuePair<string, ITriggerValue>(z.Name, z),
new KeyValuePair<string, ITriggerValue>(z.Alias ?? z.Name.Pascalize(), z),
};
}
.SelectMany(z =>
{
return new[]
{
new KeyValuePair<string, ITriggerValue>(z.Name, z),
new KeyValuePair<string, ITriggerValue>(z.Alias ?? z.Name.Pascalize(), z),
};
}
)
.DistinctBy(z => z.Key, StringComparer.OrdinalIgnoreCase)
.ToDictionary(z => z.Key, z => z.Value, StringComparer.OrdinalIgnoreCase);
Expand All @@ -319,9 +317,8 @@ .. onePasswordConnectServerSecrets
var lookupTable = new LookupTable<ExecutableTarget, ExecutableTarget[]>();
var initialArguments = localTool ? new Arguments().Add("dotnet").Add("nuke") : new Arguments().Add("nuke");
foreach ((var execute, var targets) in relevantTargets
.Select(
x => (ExecutableTarget: x,
Targets: GetInvokedTargets(x, relevantTargets).ToArray())
.Select(x => (ExecutableTarget: x,
Targets: GetInvokedTargets(x, relevantTargets).ToArray())
)
.ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, [.. x.Targets]))
)
Expand Down Expand Up @@ -425,11 +422,8 @@ .. onePasswordConnectServerSecrets
ApplyEnhancements(config);

if (!buildJob.Name.Equals(Settings.DefaultGithubJobName, StringComparison.OrdinalIgnoreCase))
{
// ReSharper disable once PossibleMultipleEnumeration
config.DetailedTriggers = [.. GetTriggers(requiredInputs, outputs, secrets)
, .. config.DetailedTriggers.Except(triggers)];
}
config.DetailedTriggers = [.. GetTriggers(requiredInputs, outputs, secrets), .. config.DetailedTriggers.Except(triggers)];

// need a better way to do this more generically
if (buildJob.Steps.OfType<UsingStep>().Any(z => z.Uses?.StartsWith("codecov/codecov-action", StringComparison.OrdinalIgnoreCase) == true))
Expand Down Expand Up @@ -491,10 +485,9 @@ protected void NormalizeActionVersions(RocketSurgeonGitHubActionsConfiguration c
.Documents
.SelectMany(z => z.AllNodes)
.OfType<YamlMappingNode>()
.Where(
z => z.Children.ContainsKey(key)
&& z.Children[key] is YamlScalarNode sn
&& sn.Value?.Contains('@', StringComparison.OrdinalIgnoreCase) == true
.Where(z => z.Children.ContainsKey(key)
&& z.Children[key] is YamlScalarNode sn
&& sn.Value?.Contains('@', StringComparison.OrdinalIgnoreCase) == true
)
.Select(
// ReSharper disable once NullableWarningSuppressionIsUsed
Expand All @@ -518,9 +511,7 @@ protected void NormalizeActionVersions(RocketSurgeonGitHubActionsConfiguration c
foreach (var job in config.Jobs)
{
if (job is RocketSurgeonsGithubWorkflowJob workflowJob)
{
workflowJob.Uses = GetValue(workflowJob.Uses);
}
else if (job is RocketSurgeonsGithubActionsJob actionsJob)
{
foreach (var step in actionsJob.Steps.OfType<UsingStep>())
Expand All @@ -547,12 +538,11 @@ protected virtual IEnumerable<GithubActionsNukeParameter> GetParameters(INukeBui
.Where(x => x.GetCustomAttribute<ParameterAttribute>() is { });
foreach (var parameter in parameters)
{
if (Parameters.Any(
z => z.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase)
|| z.Equals(
parameter.GetCustomAttribute<ParameterAttribute>()?.Name,
StringComparison.OrdinalIgnoreCase
)
if (Parameters.Any(z => z.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase)
|| z.Equals(
parameter.GetCustomAttribute<ParameterAttribute>()?.Name,
StringComparison.OrdinalIgnoreCase
)
))
{
var value = parameter.GetValue(build);
Expand Down
Loading