Skip to content

Commit

Permalink
Add support for AzurePipelines NuGetAuthenticate and NpmAuthenticate
Browse files Browse the repository at this point in the history
  • Loading branch information
pasoma2015 committed Jul 17, 2024
1 parent 6ed9e4d commit d099d0b
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
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'");
}
}
}

0 comments on commit d099d0b

Please sign in to comment.