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

added extension method to include workload restores #1205

Merged
merged 10 commits into from
May 1, 2024
53 changes: 21 additions & 32 deletions .build/Build.CI.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Rocket.Surgery.Nuke.ContinuousIntegration;
using Rocket.Surgery.Nuke.DotNetCore;
using Rocket.Surgery.Nuke.GithubActions;

#pragma warning disable CA1050
Expand All @@ -10,51 +9,41 @@
"ci-ignore",
GitHubActionsImage.UbuntuLatest,
AutoGenerate = false,
On = new[] { RocketSurgeonGitHubActionsTrigger.Push, },
OnPushTags = new[] { "v*", },
OnPushBranches = new[] { "master", "main", "next", },
OnPullRequestBranches = new[] { "master", "main", "next", },
Enhancements = new[] { nameof(CiIgnoreMiddleware), }
On = [RocketSurgeonGitHubActionsTrigger.Push,],
OnPushTags = ["v*",],
OnPushBranches = ["master", "main", "next",],
OnPullRequestBranches = ["master", "main", "next",],
Enhancements = [nameof(CiIgnoreMiddleware),]
)]
[GitHubActionsSteps(
"ci",
GitHubActionsImage.UbuntuLatest,
AutoGenerate = false,
On = new[]
{
On =
[
RocketSurgeonGitHubActionsTrigger.WorkflowCall,
RocketSurgeonGitHubActionsTrigger.WorkflowDispatch,
},
OnPushTags = new[] { "v*", },
OnPushBranches = new[] { "master", "main", "next", },
OnPullRequestBranches = new[] { "master", "main", "next", },
InvokedTargets = new[] { nameof(Default), },
NonEntryTargets = new[]
{
nameof(ICIEnvironment.CIEnvironment),
nameof(ITriggerCodeCoverageReports.TriggerCodeCoverageReports),
nameof(ITriggerCodeCoverageReports.GenerateCodeCoverageReportCobertura),
nameof(IGenerateCodeCoverageBadges.GenerateCodeCoverageBadges),
nameof(IGenerateCodeCoverageReport.GenerateCodeCoverageReport),
nameof(IGenerateCodeCoverageSummary.GenerateCodeCoverageSummary),
nameof(Default),
},
ExcludedTargets = new[] { nameof(ICanClean.Clean), nameof(ICanRestoreWithDotNetCore.DotnetToolRestore), },
Enhancements = new[] { nameof(CiMiddleware), }
],
OnPushTags = ["v*",],
OnPushBranches = ["master", "main", "next",],
OnPullRequestBranches = ["master", "main", "next",],
InvokedTargets = [nameof(Default),],
NonEntryTargets = [nameof(Default),],
Enhancements = [nameof(CiMiddleware),]
)]
[GitHubActionsLint(
"lint",
GitHubActionsImage.UbuntuLatest,
AutoGenerate = false,
OnPullRequestTargetBranches = new[] { "master", "main", "next", },
Enhancements = new[] { nameof(LintStagedMiddleware), }
OnPullRequestTargetBranches = ["master", "main", "next",],
Enhancements = [nameof(LintStagedMiddleware),]
)]
[GitHubActionsSteps(
"inputs",
GitHubActionsImage.UbuntuLatest,
AutoGenerate = false,
On = new[] { RocketSurgeonGitHubActionsTrigger.WorkflowCall, },
InvokedTargets = new[] { nameof(WithOutputs), }
On = [RocketSurgeonGitHubActionsTrigger.WorkflowCall,],
InvokedTargets = [nameof(WithOutputs),]
)]
[GitHubActionsVariable("THIS_IS_A_VARIABLE", Alias = "ThisIsAOtherVariable")]
[GitHubActionsVariable("THIS_IS_ANOTHER_VARIABLE")]
Expand All @@ -78,13 +67,13 @@ public partial class Pipeline
{
public static RocketSurgeonGitHubActionsConfiguration CiIgnoreMiddleware(RocketSurgeonGitHubActionsConfiguration configuration)
{
( (RocketSurgeonsGithubActionsJob)configuration.Jobs[0] ).Steps = new()
{
( (RocketSurgeonsGithubActionsJob)configuration.Jobs[0] ).Steps =
[
new RunStep("N/A")
{
Run = "echo \"No build required\"",
},
};
];

return configuration.IncludeRepositoryConfigurationFiles();
}
Expand Down
21 changes: 18 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,29 @@ jobs:
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: '8.0.x'
- name: 🎁 dotnet tool restore
- name: 🚒 dotnet workload restore
run: |
dotnet workload restore
- name: ⚒️ dotnet tool restore
run: |
dotnet tool restore
- name: Clean
id: clean
run: |
dotnet nuke Clean --skip --thisisaothervariable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisanothervariable '${{ vars.THIS_IS_ANOTHER_VARIABLE }}' --this_is_a_variable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisaenv '${{ env.THIS_IS_A_ENV || 'test' }}' --thisisasecret '${{ secrets.THIS_IS_A_SECRET }}' --githubtoken '${{ secrets.GITHUB_TOKEN }}'
- name: 🚒 Dotnet Workload Restore
id: dotnetWorkloadRestore
run: |
dotnet nuke DotnetWorkloadRestore --skip --thisisaothervariable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisanothervariable '${{ vars.THIS_IS_ANOTHER_VARIABLE }}' --this_is_a_variable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisaenv '${{ env.THIS_IS_A_ENV || 'test' }}' --thisisasecret '${{ secrets.THIS_IS_A_SECRET }}' --githubtoken '${{ secrets.GITHUB_TOKEN }}'
- name: ⚒️ Dotnet Tool Restore
id: dotnetToolRestore
run: |
dotnet nuke DotnetToolRestore --skip --thisisaothervariable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisanothervariable '${{ vars.THIS_IS_ANOTHER_VARIABLE }}' --this_is_a_variable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisaenv '${{ env.THIS_IS_A_ENV || 'test' }}' --thisisasecret '${{ secrets.THIS_IS_A_SECRET }}' --githubtoken '${{ secrets.GITHUB_TOKEN }}'
- name: 🎁 Restore
id: restore
run: |
dotnet nuke Restore --skip --thisisaothervariable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisanothervariable '${{ vars.THIS_IS_ANOTHER_VARIABLE }}' --this_is_a_variable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisaenv '${{ env.THIS_IS_A_ENV || 'test' }}' --thisisasecret '${{ secrets.THIS_IS_A_SECRET }}' --githubtoken '${{ secrets.GITHUB_TOKEN }}'
- name: ⚙ Build
- name: ⚙ Build
id: build
run: |
dotnet nuke Build --skip --thisisaothervariable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisanothervariable '${{ vars.THIS_IS_ANOTHER_VARIABLE }}' --this_is_a_variable '${{ vars.THIS_IS_A_VARIABLE }}' --thisisaenv '${{ env.THIS_IS_A_ENV || 'test' }}' --thisisasecret '${{ secrets.THIS_IS_A_SECRET }}' --githubtoken '${{ secrets.GITHUB_TOKEN }}'
Expand All @@ -145,7 +160,7 @@ jobs:
with:
name: 'coverage'
path: 'coverage/'
- name: 🐿 Publish Coverage
- name: 📫 Publish Coverage
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || ((github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'dependabot[bot]')
uses: codecov/codecov-action@v4
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/inputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ jobs:
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b
with:
clean: 'false'
- name: 🎁 dotnet tool restore
- name: 🚒 dotnet workload restore
run: |
dotnet workload restore
- name: ⚒️ dotnet tool restore
run: |
dotnet tool restore
- name: With Outputs
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: 🎁 dotnet tool restore
- name: 🚒 dotnet workload restore
run: |
dotnet workload restore
- name: ⚒️ dotnet tool restore
run: |
dotnet tool restore
- name: Regenerate Build Configurations
Expand Down
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"Default",
"DotNetFormat",
"DotnetToolRestore",
"DotnetWorkloadRestore",
"GenerateCodeCoverageBadges",
"GenerateCodeCoverageReport",
"GenerateCodeCoverageReportCobertura",
Expand Down Expand Up @@ -147,6 +148,7 @@
"Default",
"DotNetFormat",
"DotnetToolRestore",
"DotnetWorkloadRestore",
"GenerateCodeCoverageBadges",
"GenerateCodeCoverageReport",
"GenerateCodeCoverageReportCobertura",
Expand Down
53 changes: 28 additions & 25 deletions src/Nuke/AzurePipelinesStepsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ public class AzurePipelinesStepsAttribute : ChainedConfigurationAttributeBase
public override Type HostType => typeof(AzurePipelines);

/// <inheritdoc />
public override IEnumerable<AbsolutePath> GeneratedFiles => new[] { ConfigurationFile };
public override IEnumerable<AbsolutePath> GeneratedFiles => new[] { ConfigurationFile, };

/// <inheritdoc />
public override IEnumerable<string> RelevantTargetNames => InvokeTargets;

/// <summary>
/// The targets to invoke
/// </summary>
public string[] InvokeTargets { get; set; } = Array.Empty<string>();
public string[] InvokeTargets { get; set; } = [];

/// <summary>
/// The parameters to be used
/// </summary>
public string[] Parameters { get; set; } = Array.Empty<string>();
public string[] Parameters { get; set; } = [];

/// <inheritdoc />
public override CustomFileWriter CreateWriter(StreamWriter streamWriter)
{
return new CustomFileWriter(streamWriter, 2, "#");
return new(streamWriter, 2, "#");
}

/// <inheritdoc />
Expand All @@ -61,24 +61,26 @@ IReadOnlyCollection<ExecutableTarget> relevantTargets
{
var paramList = new List<AzurePipelinesParameter>();
var parameters =
Build.GetType()
.GetInterfaces()
.SelectMany(x => x.GetMembers())
.Concat(
Build.GetType()
.GetMembers(
BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.FlattenHierarchy
)
)
.Where(x => x.GetCustomAttribute<ParameterAttribute>() != null);
Build
.GetType()
.GetInterfaces()
.SelectMany(x => x.GetMembers())
.Concat(
Build
.GetType()
.GetMembers(
BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy
)
)
.Where(x => x.GetCustomAttribute<ParameterAttribute>() != null);
foreach (var parameter in parameters)
{
if (Parameters.Any(
z => z.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase) || z.Equals(
parameter.GetCustomAttribute<ParameterAttribute>()?.Name,
StringComparison.OrdinalIgnoreCase
)
z => z.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase)
|| z.Equals(
parameter.GetCustomAttribute<ParameterAttribute>()?.Name,
StringComparison.OrdinalIgnoreCase
)
))
{
var value = parameter.GetValue(Build);
Expand All @@ -88,7 +90,7 @@ IReadOnlyCollection<ExecutableTarget> relevantTargets
}

paramList.Add(
new AzurePipelinesParameter
new()
{
Name = parameter.GetCustomAttribute<ParameterAttribute>()?.Name ?? parameter.Name,
Default = value?.ToString() ?? "",
Expand All @@ -99,14 +101,15 @@ IReadOnlyCollection<ExecutableTarget> relevantTargets

var lookupTable = new LookupTable<ExecutableTarget, AzurePipelinesStep>();
var steps = relevantTargets
.Select(x => (ExecutableTarget: x, Job: GetStep(x, relevantTargets, lookupTable)))
.Select(x => ( ExecutableTarget: x, Job: GetStep(x, relevantTargets, lookupTable) ))
.ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, x.Job))
.Select(x => x.Job).ToArray();
.Select(x => x.Job)
.ToArray();

return new AzurePipelinesSteps
{
Parameters = paramList.ToArray(),
Steps = steps
Steps = steps,
};
}

Expand All @@ -126,7 +129,7 @@ IReadOnlyCollection<ExecutableTarget> relevantTargets
var chainLinkNames = GetInvokedTargets(executableTarget, relevantTargets).Select(z => z.Name).ToArray();
var tool = DotNetTool.IsInstalled("codecov.tool") ? "dotnet nuke" : "nuke";

return new AzurePipelinesStep
return new()
{
Name = executableTarget.Name,
DisplayName = GetStepName(executableTarget.Name),
Expand All @@ -151,4 +154,4 @@ protected virtual string GetStepName(string name)

return $"{symbol} {name}";
}
}
}
21 changes: 15 additions & 6 deletions src/Nuke/DotNetCore/ICanRestoreWithDotNetCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Rocket.Surgery.Nuke.DotNetCore;
/// Adds a task for `dotnet tool restore` and `dotnet restore`
/// </summary>
public interface ICanRestoreWithDotNetCore : IHaveCleanTarget,
IHaveSolution,
IHaveOutputLogs,
IHaveGitVersion,
IHaveRestoreTarget,
ICan
IHaveSolution,
IHaveOutputLogs,
IHaveGitVersion,
IHaveRestoreTarget,
ICan
{
/// <summary>
/// This will ensure that all local dotnet tools are installed
Expand All @@ -23,6 +23,14 @@ public interface ICanRestoreWithDotNetCore : IHaveCleanTarget,
.Unlisted()
.Executes(() => DotNet($"tool restore"));

/// <summary>
/// This will ensure that all local dotnet tools are installed
/// </summary>
public Target DotnetWorkloadRestore => d => d
.After(Clean)
.Unlisted()
.Executes(() => DotNet($"workload restore"));

/// <summary>
/// dotnet restore
/// </summary>
Expand All @@ -31,6 +39,7 @@ public interface ICanRestoreWithDotNetCore : IHaveCleanTarget,
.Unlisted()
.After(Clean)
.DependsOn(DotnetToolRestore)
.DependsOn(DotnetWorkloadRestore)
.Executes(
() => DotNetRestore(
s => s
Expand All @@ -40,4 +49,4 @@ public interface ICanRestoreWithDotNetCore : IHaveCleanTarget,
.SetGitVersionEnvironment(GitVersion)
)
);
}
}
Loading
Loading