Skip to content
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
16 changes: 16 additions & 0 deletions source/Nuke.Build/CICD/CustomStepConfigurationEntityAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using System;
using System.Linq;
using Nuke.Common.Utilities;

namespace Nuke.Common.CI;

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public abstract class CustomStepConfigurationEntityAttribute<T> : Attribute
{
public abstract T Get();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using Nuke.Common.CI.AzurePipelines.Configuration;
using Nuke.Common.Utilities;

namespace Nuke.Common.Tests.AzurePipelinesAttributes;

internal sealed class AzureDevOpsDownloadSecureFileStep : AzurePipelinesStep
{
public AzureDevOpsDownloadSecureFileStep(string fileName)
{
FileName = fileName;
}

public string FileName { get; }
public override void Write(CustomFileWriter writer)
{
writer.WriteLine("- task: DownloadSecureFile@1");
using (writer.Indent())
{
writer.WriteLine("inputs:");
using (writer.Indent())
{
writer.WriteLine($"secureFile: '{FileName}'");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using Nuke.Common.CI.AzurePipelines.Configuration;

namespace Nuke.Common.Tests.AzurePipelinesAttributes;

internal sealed class AzureDevOpsDownloadSecureFileStepAttribute : AzurePipelineStepAttribute
{
public AzureDevOpsDownloadSecureFileStepAttribute(string fileName)
{
FileName = fileName;
}

public string FileName { get; }

public override AzurePipelinesStep Get()
{
return new AzureDevOpsDownloadSecureFileStep(FileName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(HOME)/.nuget/packages
- task: DownloadSecureFile@1
inputs:
secureFile: 'securefile.zip'
- task: CmdLine@2
displayName: 'Run: Test'
inputs:
Expand Down Expand Up @@ -271,6 +274,9 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(USERPROFILE)/.nuget/packages
- task: DownloadSecureFile@1
inputs:
secureFile: 'securefile.zip'
- task: CmdLine@2
displayName: 'Run: Test'
inputs:
Expand Down
2 changes: 2 additions & 0 deletions source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Nuke.Common.CI.TeamCity;
using Nuke.Common.Execution;
using Nuke.Common.IO;
using Nuke.Common.Tests.AzurePipelinesAttributes;
using Nuke.Common.Tooling;
using VerifyXunit;
using Xunit;
Expand Down Expand Up @@ -224,6 +225,7 @@ public class TestBuild : NukeBuild

public AbsolutePath TestResultDirectory => OutputDirectory / "test-results";

[AzureDevOpsDownloadSecureFileStep("securefile.zip")]
public Target Test => _ => _
.DependsOn(Compile)
.Produces(TestResultDirectory / "*.trx")
Expand Down
10 changes: 10 additions & 0 deletions source/Nuke.Common/CI/AzurePipelines/AzurePipelinesAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using Nuke.Common.CI.AzurePipelines.Configuration;
using Nuke.Common.Execution;
Expand Down Expand Up @@ -275,6 +276,15 @@ string GetArtifactPath(AbsolutePath path)
// ArtifactRules = rules
// }).ToArray<TeamCityDependency>();

var customSteps = executableTarget.Member
.GetCustomAttributes(typeof(AzurePipelineStepAttribute), true)
.ToList();

foreach (var customStep in customSteps.Cast<AzurePipelineStepAttribute>())
{
yield return customStep.Get();
}

var chainLinkTargets = GetInvokedTargets(executableTarget, relevantTargets).ToArray();
yield return new AzurePipelinesCmdStep
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2024 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using System;
using System.Linq;
using JetBrains.Annotations;

namespace Nuke.Common.CI.AzurePipelines.Configuration;

[PublicAPI]
public abstract class AzurePipelineStepAttribute : CustomStepConfigurationEntityAttribute<AzurePipelinesStep>
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Linq;
using JetBrains.Annotations;
using Nuke.Common.Utilities;

namespace Nuke.Common.CI.AzurePipelines.Configuration;

Expand Down