Skip to content

Commit 6c64161

Browse files
Merge pull request #1579 from RocketSurgeonsGuild/feature/toggle-workload
feature: add toggle for adding github action dotnet workload restore
2 parents e50a8c2 + d35a33a commit 6c64161

6 files changed

Lines changed: 97 additions & 98 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ jobs:
125125
uses: actions/setup-dotnet@v5.0.0
126126
with:
127127
dotnet-version: '10.0.x'
128-
- name: 🚒 dotnet workload restore
129-
continue-on-error: true
130-
run: |
131-
dotnet workload restore
132128
- name: ⚒️ dotnet tool restore
133129
run: |
134130
dotnet tool restore

.github/workflows/inputs.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ jobs:
5454
uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493
5555
with:
5656
clean: 'false'
57-
- name: 🚒 dotnet workload restore
58-
continue-on-error: true
59-
run: |
60-
dotnet workload restore
6157
- name: ⚒️ dotnet tool restore
6258
run: |
6359
dotnet tool restore

.github/workflows/lint.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ jobs:
7171
uses: actions/setup-dotnet@v5
7272
with:
7373
dotnet-version: '10.0.x'
74-
- name: 🚒 dotnet workload restore
75-
continue-on-error: true
76-
run: |
77-
dotnet workload restore
7874
- name: ⚒️ dotnet tool restore
7975
run: |
8076
dotnet tool restore
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Rocket.Surgery.Nuke.DotNetCore;
2+
3+
/// <summary>
4+
/// A customized attribute to disable dotnet workload restore
5+
/// </summary>
6+
[AttributeUsage(AttributeTargets.Class)]
7+
public class DisableDotnetWorkloadRestoreAttribute : Attribute
8+
{
9+
/// <summary>
10+
/// Represents an attribute used to disable the restoration of .NET workloads.
11+
/// </summary>
12+
/// <remarks>
13+
/// This attribute, when applied to a class, sets the flag <c>Extensions.EnableDotNetWorkloadRestore</c>
14+
/// to <c>false</c> to disable the restoration process for workloads during the build.
15+
/// </remarks>
16+
public DisableDotnetWorkloadRestoreAttribute() => Extensions.EnableDotNetWorkloadRestore = false;
17+
}

src/Nuke/Extensions.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,14 @@ public static IEnumerable<AbsolutePath> Match(this IEnumerable<AbsolutePath> abs
227227
/// <param name="target"></param>
228228
/// <returns></returns>
229229
public static ITargetDefinition Net9MsBuildFix(this ITargetDefinition target) => target
230-
.Executes(
231-
() =>
232-
{
233-
if (DisableNet9MsBuildFix) return;
234-
235-
EnvironmentInfo.SetVariable("MSBuildExtensionsPath", "");
236-
EnvironmentInfo.SetVariable("MSBUILD_EXE_PATH", "");
237-
EnvironmentInfo.SetVariable("MSBuildSDKsPath", "");
238-
}
230+
.Executes(() =>
231+
{
232+
if (DisableNet9MsBuildFix) return;
233+
234+
EnvironmentInfo.SetVariable("MSBuildExtensionsPath", "");
235+
EnvironmentInfo.SetVariable("MSBUILD_EXE_PATH", "");
236+
EnvironmentInfo.SetVariable("MSBuildSDKsPath", "");
237+
}
239238
);
240239

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

311+
/// <summary>
312+
/// allow disabling dotnet workload restore.
313+
/// </summary>
314+
public static bool EnableDotNetWorkloadRestore { get; set; }
315+
312316
/// <summary>
313317
/// allow disabling the temporary fix for net9 msbuild issues
314318
/// </summary>

src/Nuke/GithubActions/GitHubActionsStepsAttribute.cs

Lines changed: 67 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,14 @@ public override ConfigurationEntity GetConfiguration(IReadOnlyCollection<Executa
104104
var inputs = attributes
105105
.OfType<GitHubActionsInputAttribute>()
106106
.Select(z => z.ToInput())
107-
.SelectMany(
108-
z =>
109-
{
110-
return new[]
111-
{
112-
new KeyValuePair<string, GitHubActionsInput>(z.Name, z),
113-
new KeyValuePair<string, GitHubActionsInput>(z.Alias ?? z.Name.Pascalize(), z),
114-
};
115-
}
107+
.SelectMany(z =>
108+
{
109+
return new[]
110+
{
111+
new KeyValuePair<string, GitHubActionsInput>(z.Name, z),
112+
new KeyValuePair<string, GitHubActionsInput>(z.Alias ?? z.Name.Pascalize(), z),
113+
};
114+
}
116115
)
117116
.DistinctBy(z => z.Key, StringComparer.OrdinalIgnoreCase)
118117
.ToDictionary(z => z.Key, z => z.Value, StringComparer.OrdinalIgnoreCase);
@@ -152,23 +151,21 @@ .. onePasswordServiceAccountSecrets
152151
steps.AddRange(
153152
onePasswordServiceAccountSecrets
154153
.GroupBy(z => z.Secret)
155-
.Select(
156-
static secrets => new UsingStep($"Load 1Password Secrets ({secrets.Key})")
157-
{
158-
Id = secrets.First().OutputId,
159-
Uses = "1password/load-secrets-action@v1",
160-
Outputs = [.. secrets.Select(secret => new GitHubActionsOutput(secret.Name, secret.Description))],
161-
With = new() { ["export-env"] = "false" },
162-
Environment = Enumerable
154+
.Select(static secrets => new UsingStep($"Load 1Password Secrets ({secrets.Key})")
155+
{
156+
Id = secrets.First().OutputId,
157+
Uses = "1password/load-secrets-action@v1",
158+
Outputs = [.. secrets.Select(secret => new GitHubActionsOutput(secret.Name, secret.Description))],
159+
With = new() { ["export-env"] = "false" },
160+
Environment = Enumerable
163161
.Concat(
164162
secrets
165-
.Select(
166-
z => new KeyValuePair<string, string>(
167-
z.Name,
168-
string.IsNullOrWhiteSpace(z.Variable)
169-
? $"{z.Path}"
170-
: $$$"""${{ vars.{{{z.Variable}}} }}/{{{z.Path.TrimStart('/')}}}"""
171-
)
163+
.Select(z => new KeyValuePair<string, string>(
164+
z.Name,
165+
string.IsNullOrWhiteSpace(z.Variable)
166+
? $"{z.Path}"
167+
: $$$"""${{ vars.{{{z.Variable}}} }}/{{{z.Path.TrimStart('/')}}}"""
168+
)
172169
),
173170
[
174171
new(
@@ -178,7 +175,7 @@ .. onePasswordServiceAccountSecrets
178175
]
179176
)
180177
.ToDictionary(z => z.Key, z => z.Value),
181-
}
178+
}
182179
)
183180
);
184181
}
@@ -211,23 +208,21 @@ .. onePasswordConnectServerSecrets
211208
steps.AddRange(
212209
onePasswordConnectServerSecrets
213210
.GroupBy(z => $"{z.ConnectHost}, {z.ConnectToken}")
214-
.Select(
215-
static secrets => new UsingStep($"Load 1Password Secrets ({secrets.Key})")
216-
{
217-
Id = secrets.First().OutputId,
218-
Uses = "1password/load-secrets-action@v1",
219-
Outputs = [.. secrets.Select(secret => new GitHubActionsOutput(secret.Name, secret.Description))],
220-
With = new() { ["export-env"] = "false" },
221-
Environment = Enumerable
211+
.Select(static secrets => new UsingStep($"Load 1Password Secrets ({secrets.Key})")
212+
{
213+
Id = secrets.First().OutputId,
214+
Uses = "1password/load-secrets-action@v1",
215+
Outputs = [.. secrets.Select(secret => new GitHubActionsOutput(secret.Name, secret.Description))],
216+
With = new() { ["export-env"] = "false" },
217+
Environment = Enumerable
222218
.Concat(
223219
secrets
224-
.Select(
225-
z => new KeyValuePair<string, string>(
226-
z.Name,
227-
string.IsNullOrWhiteSpace(z.Variable)
228-
? $"{z.Path}"
229-
: $$$"""${{ vars.{{{z.Variable}}} }}/{{{z.Path.TrimStart('/')}}}"""
230-
)
220+
.Select(z => new KeyValuePair<string, string>(
221+
z.Name,
222+
string.IsNullOrWhiteSpace(z.Variable)
223+
? $"{z.Path}"
224+
: $$$"""${{ vars.{{{z.Variable}}} }}/{{{z.Path.TrimStart('/')}}}"""
225+
)
231226
),
232227
[
233228
new(
@@ -241,7 +236,7 @@ .. onePasswordConnectServerSecrets
241236
]
242237
)
243238
.ToDictionary(z => z.Key, z => z.Value),
244-
}
239+
}
245240
)
246241
);
247242
}
@@ -252,14 +247,18 @@ .. onePasswordConnectServerSecrets
252247
{
253248
Run = "dotnet tool install -g Nuke.GlobalTool",
254249
};
255-
// TODO: Add configuration to disable this?
256-
steps.Add(
257-
new RunStep("dotnet workload restore")
258-
{
259-
Run = "dotnet workload restore",
260-
ContinueOnError = true,
261-
}
262-
);
250+
251+
if (Extensions.EnableDotNetWorkloadRestore)
252+
{
253+
steps.Add(
254+
new RunStep("dotnet workload restore")
255+
{
256+
Run = "dotnet workload restore",
257+
ContinueOnError = true,
258+
}
259+
);
260+
}
261+
263262
var dotnetTools = Path.Combine(NukeBuild.RootDirectory, ".config/dotnet-tools.json");
264263
if (File.Exists(dotnetTools))
265264
{
@@ -285,15 +284,14 @@ .. onePasswordConnectServerSecrets
285284
environmentAttributes
286285
)
287286
// ReSharper enable CoVariantArrayConversion
288-
.SelectMany(
289-
z =>
290-
{
291-
return new[]
292-
{
293-
new KeyValuePair<string, ITriggerValue>(z.Name, z),
294-
new KeyValuePair<string, ITriggerValue>(z.Alias ?? z.Name.Pascalize(), z),
295-
};
296-
}
287+
.SelectMany(z =>
288+
{
289+
return new[]
290+
{
291+
new KeyValuePair<string, ITriggerValue>(z.Name, z),
292+
new KeyValuePair<string, ITriggerValue>(z.Alias ?? z.Name.Pascalize(), z),
293+
};
294+
}
297295
)
298296
.DistinctBy(z => z.Key, StringComparer.OrdinalIgnoreCase)
299297
.ToDictionary(z => z.Key, z => z.Value, StringComparer.OrdinalIgnoreCase);
@@ -319,9 +317,8 @@ .. onePasswordConnectServerSecrets
319317
var lookupTable = new LookupTable<ExecutableTarget, ExecutableTarget[]>();
320318
var initialArguments = localTool ? new Arguments().Add("dotnet").Add("nuke") : new Arguments().Add("nuke");
321319
foreach ((var execute, var targets) in relevantTargets
322-
.Select(
323-
x => (ExecutableTarget: x,
324-
Targets: GetInvokedTargets(x, relevantTargets).ToArray())
320+
.Select(x => (ExecutableTarget: x,
321+
Targets: GetInvokedTargets(x, relevantTargets).ToArray())
325322
)
326323
.ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, [.. x.Targets]))
327324
)
@@ -425,11 +422,8 @@ .. onePasswordConnectServerSecrets
425422
ApplyEnhancements(config);
426423

427424
if (!buildJob.Name.Equals(Settings.DefaultGithubJobName, StringComparison.OrdinalIgnoreCase))
428-
{
429425
// ReSharper disable once PossibleMultipleEnumeration
430-
config.DetailedTriggers = [.. GetTriggers(requiredInputs, outputs, secrets)
431-
, .. config.DetailedTriggers.Except(triggers)];
432-
}
426+
config.DetailedTriggers = [.. GetTriggers(requiredInputs, outputs, secrets), .. config.DetailedTriggers.Except(triggers)];
433427

434428
// need a better way to do this more generically
435429
if (buildJob.Steps.OfType<UsingStep>().Any(z => z.Uses?.StartsWith("codecov/codecov-action", StringComparison.OrdinalIgnoreCase) == true))
@@ -491,10 +485,9 @@ protected void NormalizeActionVersions(RocketSurgeonGitHubActionsConfiguration c
491485
.Documents
492486
.SelectMany(z => z.AllNodes)
493487
.OfType<YamlMappingNode>()
494-
.Where(
495-
z => z.Children.ContainsKey(key)
496-
&& z.Children[key] is YamlScalarNode sn
497-
&& sn.Value?.Contains('@', StringComparison.OrdinalIgnoreCase) == true
488+
.Where(z => z.Children.ContainsKey(key)
489+
&& z.Children[key] is YamlScalarNode sn
490+
&& sn.Value?.Contains('@', StringComparison.OrdinalIgnoreCase) == true
498491
)
499492
.Select(
500493
// ReSharper disable once NullableWarningSuppressionIsUsed
@@ -518,9 +511,7 @@ protected void NormalizeActionVersions(RocketSurgeonGitHubActionsConfiguration c
518511
foreach (var job in config.Jobs)
519512
{
520513
if (job is RocketSurgeonsGithubWorkflowJob workflowJob)
521-
{
522514
workflowJob.Uses = GetValue(workflowJob.Uses);
523-
}
524515
else if (job is RocketSurgeonsGithubActionsJob actionsJob)
525516
{
526517
foreach (var step in actionsJob.Steps.OfType<UsingStep>())
@@ -547,12 +538,11 @@ protected virtual IEnumerable<GithubActionsNukeParameter> GetParameters(INukeBui
547538
.Where(x => x.GetCustomAttribute<ParameterAttribute>() is { });
548539
foreach (var parameter in parameters)
549540
{
550-
if (Parameters.Any(
551-
z => z.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase)
552-
|| z.Equals(
553-
parameter.GetCustomAttribute<ParameterAttribute>()?.Name,
554-
StringComparison.OrdinalIgnoreCase
555-
)
541+
if (Parameters.Any(z => z.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase)
542+
|| z.Equals(
543+
parameter.GetCustomAttribute<ParameterAttribute>()?.Name,
544+
StringComparison.OrdinalIgnoreCase
545+
)
556546
))
557547
{
558548
var value = parameter.GetValue(build);

0 commit comments

Comments
 (0)