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

Add support for AzurePipelines NuGetAuthenticate and NpmAuthenticate #1397

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(HOME)/.nuget/packages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: npmAuthenticate@0
displayName: 'npm Authenticate .npmrc'
inputs:
workingFile: '.npmrc'
- task: CmdLine@2
displayName: 'Run: Restore'
inputs:
Expand Down Expand Up @@ -96,6 +102,12 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(HOME)/.nuget/packages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: npmAuthenticate@0
displayName: 'npm Authenticate .npmrc'
inputs:
workingFile: '.npmrc'
- task: CmdLine@2
displayName: 'Run: Compile'
inputs:
Expand Down Expand Up @@ -131,6 +143,12 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(HOME)/.nuget/packages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: npmAuthenticate@0
displayName: 'npm Authenticate .npmrc'
inputs:
workingFile: '.npmrc'
- task: CmdLine@2
displayName: 'Run: Test'
inputs:
Expand Down Expand Up @@ -164,6 +182,12 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(HOME)/.nuget/packages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: npmAuthenticate@0
displayName: 'npm Authenticate .npmrc'
inputs:
workingFile: '.npmrc'
- task: CmdLine@2
displayName: 'Run: Coverage'
inputs:
Expand Down Expand Up @@ -203,6 +227,12 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(USERPROFILE)/.nuget/packages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: npmAuthenticate@0
displayName: 'npm Authenticate .npmrc'
inputs:
workingFile: '.npmrc'
- task: CmdLine@2
displayName: 'Run: Restore'
inputs:
Expand Down Expand Up @@ -236,6 +266,12 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(USERPROFILE)/.nuget/packages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: npmAuthenticate@0
displayName: 'npm Authenticate .npmrc'
inputs:
workingFile: '.npmrc'
- task: CmdLine@2
displayName: 'Run: Compile'
inputs:
Expand Down Expand Up @@ -271,6 +307,12 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(USERPROFILE)/.nuget/packages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: npmAuthenticate@0
displayName: 'npm Authenticate .npmrc'
inputs:
workingFile: '.npmrc'
- task: CmdLine@2
displayName: 'Run: Test'
inputs:
Expand Down Expand Up @@ -304,6 +346,12 @@ stages:
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
restoreKeys: $(Agent.OS) | nuget-packages
path: $(USERPROFILE)/.nuget/packages
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: npmAuthenticate@0
displayName: 'npm Authenticate .npmrc'
inputs:
workingFile: '.npmrc'
- task: CmdLine@2
displayName: 'Run: Coverage'
inputs:
Expand Down
4 changes: 3 additions & 1 deletion source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public class TestBuild : NukeBuild
Submodules = true,
LargeFileStorage = false,
Clean = true,
FetchDepth = 1
FetchDepth = 1,
EnableNuGetAuthenticate = true,
EnableNpmAuthenticate = true,
}
);

Expand Down
14 changes: 14 additions & 0 deletions source/Nuke.Common/CI/AzurePipelines/AzurePipelinesAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public bool? PullRequestsAutoCancel
public string[] ImportVariableGroups { get; set; } = new string[0];
public string[] ImportSecrets { get; set; } = new string[0];
public bool EnableAccessToken { get; set; }

public bool EnableNuGetAuthenticate { get; set; }
public bool EnableNpmAuthenticate { get; set; }
public string NpmrcPath { get; set; } = ".npmrc";

public override CustomFileWriter CreateWriter(StreamWriter streamWriter)
{
Expand Down Expand Up @@ -251,6 +255,16 @@ protected virtual IEnumerable<AzurePipelinesStep> GetSteps(
}
}

if (EnableNuGetAuthenticate)
{
yield return new AzurePipelinesNuGetAuthenticateStep();
}

if (EnableNpmAuthenticate && !string.IsNullOrEmpty(NpmrcPath))
{
yield return new AzurePipelinesNpmAuthenticateStep{ NpmrcPath = NpmrcPath };
}

string GetArtifactPath(AbsolutePath path)
=> Build.RootDirectory.Contains(path)
? Build.RootDirectory.GetUnixRelativePathTo(path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using Nuke.Common.Utilities;

namespace Nuke.Common.CI.AzurePipelines.Configuration;

public class AzurePipelinesNpmAuthenticateStep : AzurePipelinesStep
{
public string NpmrcPath { get; set; }

public override void Write(CustomFileWriter writer)
{
using (writer.WriteBlock("- task: npmAuthenticate@0"))
{
writer.WriteLine($"displayName: 'npm Authenticate {NpmrcPath}'");
using (writer.WriteBlock("inputs:"))
{
writer.WriteLine($"workingFile: {NpmrcPath.SingleQuote()}");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2024 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using Nuke.Common.Utilities;

namespace Nuke.Common.CI.AzurePipelines.Configuration;

public class AzurePipelinesNuGetAuthenticateStep : AzurePipelinesStep
{
public override void Write(CustomFileWriter writer)
{
using (writer.WriteBlock("- task: NuGetAuthenticate@1"))
{
writer.WriteLine("displayName: 'NuGet Authenticate'");
}
}
}