Skip to content

Commit

Permalink
wip: ArgumentsFromParametersFileAttribute via JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Jul 3, 2024
1 parent c81d92c commit a258115
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 97 deletions.
33 changes: 25 additions & 8 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,8 @@
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"SignPathOrganizationId": {
"type": "string"
},
"SignPathPolicySlug": {
"type": "string"
},
"SignPathProjectSlug": {
"type": "string"
"SignPathSettings": {
"$ref": "#/definitions/SignPathSettings"
},
"SlackWebhook": {
"type": "string",
Expand Down Expand Up @@ -108,6 +102,29 @@
"VSCode"
]
},
"SignPathSettings": {
"type": "object",
"properties": {
"OrganizationId": {
"type": [
"null",
"string"
]
},
"ProjectSlug": {
"type": [
"null",
"string"
]
},
"PolicySlug": {
"type": [
"null",
"string"
]
}
}
},
"ExecutableTarget": {
"type": "string",
"enum": [
Expand Down
22 changes: 5 additions & 17 deletions .nuke/parameters.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
{
"$schema": "./build.schema.json",
"Solution": "nuke-common.sln",
"SignPathOrganizationId": "0fdaf334-6910-41f4-83d2-e58e4cccb087",
"SignPathProjectSlug": "nuke",
"SignPathPolicySlug": "release-signing",
"Data2": [
{
"FirstName": "foo",
"Nested": {
"FirstName": "bar"
}
},
{
"FirstName": "foo2",
"Nested": {
"FirstName": "bar2"
}
}
]
"SignPathSettings": {
"OrganizationId": "0fdaf334-6910-41f4-83d2-e58e4cccb087",
"ProjectSlug": "nuke",
"PolicySlug": "release-signing"
}
}
24 changes: 3 additions & 21 deletions .teamcity/settings.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ project {
value = "Release",
options = listOf("Debug" to "Debug", "Release" to "Release"),
display = ParameterDisplay.NORMAL)
text (
"env.Data2",
label = "Data2",
value = "Build+Data Build+Data",
allowEmpty = true,
display = ParameterDisplay.NORMAL)
checkbox (
"env.IgnoreFailedSources",
label = "IgnoreFailedSources",
Expand All @@ -69,21 +63,9 @@ project {
unchecked = "False",
display = ParameterDisplay.NORMAL)
text (
"env.SignPathOrganizationId",
label = "SignPathOrganizationId",
value = "0fdaf334-6910-41f4-83d2-e58e4cccb087",
allowEmpty = true,
display = ParameterDisplay.NORMAL)
text (
"env.SignPathPolicySlug",
label = "SignPathPolicySlug",
value = "release-signing",
allowEmpty = true,
display = ParameterDisplay.NORMAL)
text (
"env.SignPathProjectSlug",
label = "SignPathProjectSlug",
value = "nuke",
"env.SignPathSettings",
label = "SignPathSettings",
value = "",
allowEmpty = true,
display = ParameterDisplay.NORMAL)
text (
Expand Down
14 changes: 0 additions & 14 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,6 @@ partial class Build
/// - Microsoft VSCode https://nuke.build/vscode
public static int Main() => Execute<Build>(x => ((IPack)x).Pack);

public class Data
{
public string FirstName;
public Data Nested;
}

[Parameter] readonly Data[] Data2;

Target Foo => _ => _
.Executes(() =>
{
Console.WriteLine(Data2);
});

[CI] readonly TeamCity TeamCity;
[CI] readonly AzurePipelines AzurePipelines;
[CI] readonly AppVeyor AppVeyor;
Expand Down
3 changes: 2 additions & 1 deletion nuke-common.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">Copyright $CURRENT_YEAR$ Maintainers of NUKE.&#xD;
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">Copyright ${CurrentDate.Year} Maintainers of NUKE.&#xD;
Distributed under the MIT License.&#xD;
https://github.com/nuke-build/nuke/blob/master/LICENSE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;</s:String>
Expand All @@ -17,4 +17,5 @@ https://github.com/nuke-build/nuke/blob/master/LICENSE</s:String>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileA321B7F1C678C84CAFFD23C2D9D03A36/RelativePriority/@EntryValue">3</s:Double>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileA68CFA51EFE4364DA61BFD270E021A11/@KeyIndexDefined">True</s:Boolean>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileA68CFA51EFE4364DA61BFD270E021A11/RelativePriority/@EntryValue">1</s:Double>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
38 changes: 18 additions & 20 deletions source/Nuke.Build.Tests/ParameterServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ public void TestNotSupplied(Type destinationType, object expectedValue)
public void TestEnvironmentVariables(string parameter, Type destinationType, object expectedValue)
{
var service = GetService(
new[]
{
[
"-arg1",
"value1",
"-switch1"
},
],
new Dictionary<string, string>
{
{ "arg1", "value2" },
Expand All @@ -68,15 +67,14 @@ public void TestEnvironmentVariables(string parameter, Type destinationType, obj
public void TestExpression()
{
var service = GetService(
new[]
{
[
"--string",
"--set",
"1",
"2",
"3",
"--interface-param"
});
]);

var build = new TestBuild();

Expand All @@ -98,12 +96,12 @@ public void TestValueSet()
{
var build = new TestBuild();
var verbosities = new[]
{
(nameof(Verbosity.Minimal), Verbosity.Minimal),
(nameof(Verbosity.Normal), Verbosity.Normal),
(nameof(Verbosity.Quiet), Verbosity.Quiet),
(nameof(Verbosity.Verbose), Verbosity.Verbose),
};
{
(nameof(Verbosity.Minimal), Verbosity.Minimal),
(nameof(Verbosity.Normal), Verbosity.Normal),
(nameof(Verbosity.Quiet), Verbosity.Quiet),
(nameof(Verbosity.Verbose), Verbosity.Verbose),
};
ParameterService.GetParameterValueSet(GetMemberInfo(() => NukeBuild.Verbosity), instance: null)
.Should().BeEquivalentTo(verbosities);
ParameterService.GetParameterValueSet(GetMemberInfo(() => build.Verbosities), instance: null)
Expand All @@ -118,13 +116,13 @@ public void TestPrecedence()

var environmentVariables = new Dictionary<string, string> { ["string"] = "environmentVariables" };
var commandLineArguments = new ArgumentParser("--string commandLine");
var parameterFileArguments = new ArgumentParser("--string parameterFile");
var parameterFileArguments = new Func<string, Type, object>((_, _) => "parameterFile");
var commitMessageArguments = new ArgumentParser("--string commitMessage");

var service = new ParameterService(() => emptyArguments, () => emptyEnvironmentVariables)
{
ArgumentsFromFilesService = parameterFileArguments
};
{
ArgumentsFromFilesService = parameterFileArguments
};
service.GetParameter("string", typeof(string), separator: null).Should().Be("parameterFile");

service = new ParameterService(() => emptyArguments, () => environmentVariables) { ArgumentsFromFilesService = parameterFileArguments };
Expand All @@ -134,10 +132,10 @@ public void TestPrecedence()
service.GetParameter("string", typeof(string), separator: null).Should().Be("commandLine");

service = new ParameterService(() => emptyArguments, () => emptyEnvironmentVariables)
{
ArgumentsFromFilesService = parameterFileArguments,
ArgumentsFromCommitMessageService = commitMessageArguments
};
{
ArgumentsFromFilesService = parameterFileArguments,
ArgumentsFromCommitMessageService = commitMessageArguments
};
service.GetParameter("string", typeof(string), separator: null).Should().Be("commitMessage");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Newtonsoft.Json.Linq;
using Nuke.Common.CI;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using Nuke.Common.ValueInjection;
Expand Down Expand Up @@ -76,10 +75,8 @@ string DecryptValue(string profile, string name, string value)
var member = parameterMembers.SingleOrDefault(x => ParameterService.GetParameterMemberName(x).EqualsOrdinalIgnoreCase(parameter));
var scalarType = member?.GetMemberType().GetScalarType();
if (scalarType == typeof(AbsolutePath) ||
typeof(Solution).IsAssignableFrom(scalarType) ||
scalarType == typeof(Project))
return NukeBuild.RootDirectory / property.Value.ToObject<string>();
if (typeof(IAbsolutePathHolder).IsAssignableFrom(scalarType))
return property.Value.ToObject<string>().Apply(x => !PathConstruction.HasPathRoot(x) ? NukeBuild.RootDirectory / x : (AbsolutePath)x);
if ((member?.HasCustomAttribute<SecretAttribute>() ?? false) &&
!BuildServerConfigurationGeneration.IsActive)
Expand Down
23 changes: 12 additions & 11 deletions source/Nuke.Components/ISignPackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ public interface ISignPackages : INukeBuild
{
public const string SignPath = nameof(SignPath);

public record SignPathSettings(
string OrganizationId,
string ProjectSlug,
string PolicySlug);

[Parameter] SignPathSettings Settings => TryGetValue(() => Settings);
[Parameter] [Secret] string ApiToken => TryGetValue(() => ApiToken);
[Parameter] string OrganizationId => TryGetValue(() => OrganizationId);
[Parameter] string ProjectSlug => TryGetValue(() => ProjectSlug);
[Parameter] string PolicySlug => TryGetValue(() => PolicySlug);

AbsolutePath SignPathTemporaryDirectory => TemporaryDirectory / "signpath";
AbsolutePath SignPathRequestDirectory => SignPathTemporaryDirectory / "signing-request";
AbsolutePath SignPathResponseDirectory => SignPathTemporaryDirectory / "signing-response";
AbsolutePath SignPathRequestArchive => Path.ChangeExtension(SignPathRequestDirectory, ".zip");
AbsolutePath SignPathResponseArchive => Path.ChangeExtension(SignPathResponseDirectory, ".zip");
AbsolutePath SignPathRequestArchive => SignPathRequestDirectory.WithExtension(".zip");
AbsolutePath SignPathResponseArchive => SignPathResponseDirectory.WithExtension(".zip");

IEnumerable<AbsolutePath> SignPathPackages { get; }
bool SignPathReplacePackages => true;
Expand All @@ -72,10 +75,8 @@ public interface ISignPackages : INukeBuild
.TryDependsOn<IPack>()
.TryDependentFor<IPublish>()
.OnlyWhenStatic(() => AppVeyor != null)
.Requires(() => Settings)
.Requires(() => ApiToken)
.Requires(() => OrganizationId)
.Requires(() => ProjectSlug)
.Requires(() => PolicySlug)
.Executes(async () =>
{
SignPathRequestDirectory.CreateOrCleanDirectory();
Expand All @@ -86,9 +87,9 @@ public interface ISignPackages : INukeBuild
var signingRequestUrl = await GetSigningRequestUrlViaAppVeyor(
ApiToken,
OrganizationId,
ProjectSlug,
PolicySlug);
Settings.OrganizationId,
Settings.ProjectSlug,
Settings.PolicySlug);
ReportSummary(_ => _
.AddPair("Approve/Deny Request", signingRequestUrl.Replace("api/v1", "Web")));
Expand Down

0 comments on commit a258115

Please sign in to comment.