Skip to content

Commit 957c26e

Browse files
committed
Add support for AzurePipelines NuGetAuthenticate and NpmAuthenticate
1 parent e44c3c6 commit 957c26e

6 files changed

+108
-2
lines changed

source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.Test_testName=null_attribute=AzurePipelinesAttribute.verified.txt

+48
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ stages:
6363
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
6464
restoreKeys: $(Agent.OS) | nuget-packages
6565
path: $(HOME)/.nuget/packages
66+
- task: NuGetAuthenticate@1
67+
displayName: 'NuGet Authenticate'
68+
- task: npmAuthenticate@0
69+
displayName: 'npm Authenticate .npmrc'
70+
inputs:
71+
workingFile: '.npmrc'
6672
- task: CmdLine@2
6773
displayName: 'Run: Restore'
6874
inputs:
@@ -96,6 +102,12 @@ stages:
96102
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
97103
restoreKeys: $(Agent.OS) | nuget-packages
98104
path: $(HOME)/.nuget/packages
105+
- task: NuGetAuthenticate@1
106+
displayName: 'NuGet Authenticate'
107+
- task: npmAuthenticate@0
108+
displayName: 'npm Authenticate .npmrc'
109+
inputs:
110+
workingFile: '.npmrc'
99111
- task: CmdLine@2
100112
displayName: 'Run: Compile'
101113
inputs:
@@ -131,6 +143,12 @@ stages:
131143
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
132144
restoreKeys: $(Agent.OS) | nuget-packages
133145
path: $(HOME)/.nuget/packages
146+
- task: NuGetAuthenticate@1
147+
displayName: 'NuGet Authenticate'
148+
- task: npmAuthenticate@0
149+
displayName: 'npm Authenticate .npmrc'
150+
inputs:
151+
workingFile: '.npmrc'
134152
- task: CmdLine@2
135153
displayName: 'Run: Test'
136154
inputs:
@@ -164,6 +182,12 @@ stages:
164182
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
165183
restoreKeys: $(Agent.OS) | nuget-packages
166184
path: $(HOME)/.nuget/packages
185+
- task: NuGetAuthenticate@1
186+
displayName: 'NuGet Authenticate'
187+
- task: npmAuthenticate@0
188+
displayName: 'npm Authenticate .npmrc'
189+
inputs:
190+
workingFile: '.npmrc'
167191
- task: CmdLine@2
168192
displayName: 'Run: Coverage'
169193
inputs:
@@ -203,6 +227,12 @@ stages:
203227
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
204228
restoreKeys: $(Agent.OS) | nuget-packages
205229
path: $(USERPROFILE)/.nuget/packages
230+
- task: NuGetAuthenticate@1
231+
displayName: 'NuGet Authenticate'
232+
- task: npmAuthenticate@0
233+
displayName: 'npm Authenticate .npmrc'
234+
inputs:
235+
workingFile: '.npmrc'
206236
- task: CmdLine@2
207237
displayName: 'Run: Restore'
208238
inputs:
@@ -236,6 +266,12 @@ stages:
236266
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
237267
restoreKeys: $(Agent.OS) | nuget-packages
238268
path: $(USERPROFILE)/.nuget/packages
269+
- task: NuGetAuthenticate@1
270+
displayName: 'NuGet Authenticate'
271+
- task: npmAuthenticate@0
272+
displayName: 'npm Authenticate .npmrc'
273+
inputs:
274+
workingFile: '.npmrc'
239275
- task: CmdLine@2
240276
displayName: 'Run: Compile'
241277
inputs:
@@ -271,6 +307,12 @@ stages:
271307
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
272308
restoreKeys: $(Agent.OS) | nuget-packages
273309
path: $(USERPROFILE)/.nuget/packages
310+
- task: NuGetAuthenticate@1
311+
displayName: 'NuGet Authenticate'
312+
- task: npmAuthenticate@0
313+
displayName: 'npm Authenticate .npmrc'
314+
inputs:
315+
workingFile: '.npmrc'
274316
- task: CmdLine@2
275317
displayName: 'Run: Test'
276318
inputs:
@@ -304,6 +346,12 @@ stages:
304346
key: $(Agent.OS) | nuget-packages | **/global.json, **/*.csproj, **/Directory.Packages.props
305347
restoreKeys: $(Agent.OS) | nuget-packages
306348
path: $(USERPROFILE)/.nuget/packages
349+
- task: NuGetAuthenticate@1
350+
displayName: 'NuGet Authenticate'
351+
- task: npmAuthenticate@0
352+
displayName: 'npm Authenticate .npmrc'
353+
inputs:
354+
workingFile: '.npmrc'
307355
- task: CmdLine@2
308356
displayName: 'Run: Coverage'
309357
inputs:

source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ public class TestBuild : NukeBuild
9696
Submodules = true,
9797
LargeFileStorage = false,
9898
Clean = true,
99-
FetchDepth = 1
99+
FetchDepth = 1,
100+
EnableNuGetAuthenticate = true,
101+
EnableNpmAuthenticate = true,
100102
}
101103
);
102104

source/Nuke.Common/CI/AzurePipelines/AzurePipelinesAttribute.cs

+14
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public bool? PullRequestsAutoCancel
117117
public string[] ImportVariableGroups { get; set; } = new string[0];
118118
public string[] ImportSecrets { get; set; } = new string[0];
119119
public bool EnableAccessToken { get; set; }
120+
121+
public bool EnableNuGetAuthenticate { get; set; }
122+
public bool EnableNpmAuthenticate { get; set; }
123+
public string NpmrcPath { get; set; } = ".npmrc";
120124

121125
public override CustomFileWriter CreateWriter(StreamWriter streamWriter)
122126
{
@@ -251,6 +255,16 @@ protected virtual IEnumerable<AzurePipelinesStep> GetSteps(
251255
}
252256
}
253257

258+
if (EnableNuGetAuthenticate)
259+
{
260+
yield return new AzurePipelinesNuGetAuthenticateStep();
261+
}
262+
263+
if (EnableNpmAuthenticate && !string.IsNullOrEmpty(NpmrcPath))
264+
{
265+
yield return new AzurePipelinesNpmAuthenticateStep{ NpmrcPath = NpmrcPath };
266+
}
267+
254268
string GetArtifactPath(AbsolutePath path)
255269
=> Build.RootDirectory.Contains(path)
256270
? Build.RootDirectory.GetUnixRelativePathTo(path)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2024 Maintainers of NUKE.
2+
// Distributed under the MIT License.
3+
// https://github.com/nuke-build/nuke/blob/master/LICENSE
4+
5+
using Nuke.Common.Utilities;
6+
7+
namespace Nuke.Common.CI.AzurePipelines.Configuration;
8+
9+
public class AzurePipelinesNpmAuthenticateStep : AzurePipelinesStep
10+
{
11+
public string NpmrcPath { get; set; }
12+
13+
public override void Write(CustomFileWriter writer)
14+
{
15+
using (writer.WriteBlock("- task: npmAuthenticate@0"))
16+
{
17+
writer.WriteLine($"displayName: 'npm Authenticate {NpmrcPath}'");
18+
using (writer.WriteBlock("inputs:"))
19+
{
20+
writer.WriteLine($"workingFile: {NpmrcPath.SingleQuote()}");
21+
}
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2024 Maintainers of NUKE.
2+
// Distributed under the MIT License.
3+
// https://github.com/nuke-build/nuke/blob/master/LICENSE
4+
5+
using Nuke.Common.Utilities;
6+
7+
namespace Nuke.Common.CI.AzurePipelines.Configuration;
8+
9+
public class AzurePipelinesNuGetAuthenticateStep : AzurePipelinesStep
10+
{
11+
public override void Write(CustomFileWriter writer)
12+
{
13+
using (writer.WriteBlock("- task: NuGetAuthenticate@1"))
14+
{
15+
writer.WriteLine("displayName: 'NuGet Authenticate'");
16+
}
17+
}
18+
}

source/Nuke.SolutionModel/SolutionSerializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static Dictionary<string, string> GetGlobalSection(this string[] lines,
8888
.SkipWhile(x => !Regex.IsMatch(x, $@"^\s*GlobalSection\({name}\) = \w+$"))
8989
.Skip(count: 1)
9090
.TakeWhile(x => !Regex.IsMatch(x, @"^\s*EndGlobalSection$"))
91-
.Where(x => !x.StartsWith('#'))
91+
.Where(x => !x.StartsWith("#"))
9292
.ToList();
9393

9494
return sectionLines.Count == 0

0 commit comments

Comments
 (0)