Skip to content

Commit

Permalink
refactor(pipelines)!: deprecate pipelines scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoopereira committed Apr 11, 2023
1 parent 0b497eb commit 05976a3
Show file tree
Hide file tree
Showing 77 changed files with 379 additions and 6,607 deletions.
183 changes: 13 additions & 170 deletions cmf-cli/Commands/init/InitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Cmf.CLI.Constants;
using Cmf.CLI.Core.Attributes;
using Cmf.CLI.Core.Commands;
using Cmf.CLI.Core.Constants;
using Cmf.CLI.Core.Enums;
using Cmf.CLI.Core.Objects;
using Cmf.CLI.Utilities;
Expand All @@ -27,7 +28,6 @@ internal class InitArguments
public string version { get; set; }
public IFileInfo config { get; set; }
public IDirectoryInfo deploymentDir { get; set; }
public Uri repositoryUrl { get; set; }
public string BaseVersion { get; set; }
public string DevTasksVersion { get; set; }
public string HTMLStarterVersion { get; set; }
Expand All @@ -38,20 +38,10 @@ internal class InitArguments
public IFileInfo infrastructure { get; set; }
public Uri nugetRegistry { get; set; }
public Uri npmRegistry { get; set; }
public Uri azureDevOpsCollectionUrl { get; set; }
public string agentPool { get; set; }
public AgentType? agentType { get; set; }
public IFileInfo ISOLocation { get; set; }
public string nugetRegistryUsername { get; set; }
public string nugetRegistryPassword { get; set; }
public string cmfPipelineRepository { get; set; }
public string cmfCliRepository { get; set; }
public string pipelinesFolder { get; set; }
public string releaseCustomerEnvironment { get; set; }
public string releaseSite { get; set; }
public string releaseDeploymentPackage { get; set; }
public string releaseLicense { get; set; }
public string releaseDeploymentTarget { get; set; }
public RepositoryType repositoryType { get; set; }
// ReSharper restore UnusedAutoPropertyAccessor.Global
// ReSharper restore InconsistentNaming
Expand Down Expand Up @@ -117,10 +107,6 @@ public override void Configure(Command cmd)
{ IsRequired = true });

// template-time options. These are all mandatory
cmd.AddOption(new Option<Uri>(
aliases: new[] { "--repositoryUrl" },
description: "Git repository URL"
) { IsRequired = true });
cmd.AddOption(new Option<IDirectoryInfo>(
aliases: new[] { "--deploymentDir" },
parseArgument: argResult => Parse<IDirectoryInfo>(argResult),
Expand Down Expand Up @@ -171,18 +157,7 @@ public override void Configure(Command cmd)
aliases: new[] { "--npmRegistry" },
description: "NPM registry that contains the MES packages"
));
cmd.AddOption(new Option<Uri>(
aliases: new[] { "--azureDevOpsCollectionUrl" },
description: "The Azure DevOps collection address"
));
cmd.AddOption(new Option<string>(
aliases: new[] { "--agentPool" },
description: "Azure DevOps agent pool"
));
cmd.AddOption(new Option<AgentType>(
aliases: new[] { "--agentType" },
description: "Type of Azure DevOps agents: Cloud or Hosted"
));

cmd.AddOption(new Option<IFileInfo>(
aliases: new[] { "--ISOLocation" },
parseArgument: argResult => Parse<IFileInfo>(argResult),
Expand All @@ -202,63 +177,13 @@ public override void Configure(Command cmd)
description: "NPM registry that contains the CLI",
getDefaultValue: () => new Uri(CliConstants.NpmJsUrl, UriKind.Absolute)
));
cmd.AddOption(new Option<Uri>(
aliases: new[] { "--cmfPipelineRepository" },
description: "NPM registry that contains the CLI Pipeline Plugin"
));
cmd.AddOption(new Option<string>(
aliases: new[] { "--pipelinesFolder" },
getDefaultValue: () => "",
description: "Folder where we should put the pipelines in. Empty means the root folder"
));

// container-specific switches
cmd.AddOption(new Option<string>(
aliases: new[] { "--releaseCustomerEnvironment" },
description: "Customer Environment Name defined in DevOpsCenter"
));
cmd.AddOption(new Option<string>(
aliases: new[] { "--releaseSite" },
description: "Site defined in DevOpsCenter"
));
cmd.AddOption(new Option<string>(
aliases: new[] { "--releaseDeploymentPackage" },
description: "DeploymentPackage defined in DevOpsCenter"
));
cmd.AddOption(new Option<string>(
aliases: new[] { "--releaseLicense" },
description: "License defined in DevOpsCenter"
));
cmd.AddOption(new Option<string>(
aliases: new[] { "--releaseDeploymentTarget" },
description: "DeploymentTarget defined in DevOpsCenter"
));


// Add the handler
cmd.Handler = CommandHandler
.Create((InitArguments args) =>
{
this.Execute(args);
});
// no overload accepts these many arguments...
// .Create<
// IDirectoryInfo, // workingDir
// string, // rootPackageName,
// IFileInfo, // config
// IDirectoryInfo, // deploymentDir
// string, // MESVersion
// string, // DevTasksVersion
// string, // HTMLStarterVersion
// string, // yoGeneratorVersion
// string, // nugetVersion
// string, // testScenariosNugetVersion
// IFileInfo, // infrastructure
// Uri, // nugetRegistry
// Uri, // npmRegistry
// Uri, // universalRegistry
// string, // agentPool
// AgentType? // agentType
// >(this.Execute);
}

/// <summary>
Expand Down Expand Up @@ -287,29 +212,9 @@ internal void Execute(InitArguments x)
if (x.deploymentDir != null)
{
args.AddRange(new [] {"--deploymentDir", x.deploymentDir.FullName});
// repositories are sub-folders of deploymentDir
args.AddRange(new [] {"--CIRepo", $"{x.deploymentDir.FullName}\\CIPackages"});
args.AddRange(new [] {"--ADArtifactsRepo", $"{x.deploymentDir.FullName}\\ADArtifacts"});
args.AddRange(new [] {"--RCRepo", $"{x.deploymentDir.FullName}\\ReleaseCandidates"});
args.AddRange(new [] {"--DeliveredRepo", $"{x.deploymentDir.FullName}\\Delivered"});
args.AddRange(new[] { "--CIRepo", $"{x.deploymentDir.FullName}\\CIPackages" });
}

var repoName = x.projectName;
if (x.repositoryUrl != null)
{
args.AddRange(new [] {"--repositoryUrl", x.repositoryUrl.AbsoluteUri});
var match = CliConstants.RepoRegex.Match(x.repositoryUrl.AbsoluteUri);
if ((match?.Success ?? false) && match.Groups.ContainsKey("repo"))
{
repoName = match.Groups["repo"].Value;
}
}

if (repoName != null)
{
args.AddRange(new [] {"--repositoryName", repoName});
}

if (x.BaseVersion != null)
{
args.AddRange(new [] {"--MESVersion", x.BaseVersion});
Expand All @@ -329,16 +234,6 @@ internal void Execute(InitArguments x)
args.AddRange(new [] {"--testScenariosNugetVersion", x.testScenariosNugetVersion});
}

if (!string.IsNullOrWhiteSpace(x.pipelinesFolder))
{
var folder = x.pipelinesFolder.Replace("/", "\\");
if (!folder.StartsWith("\\"))
{
folder = "\\" + folder;
}
args.AddRange(new []{"--pipelinesFolder", folder});
}

#region infrastructure

if (x.infrastructure != null)
Expand All @@ -349,12 +244,6 @@ internal void Execute(InitArguments x)
{
x.nugetRegistry ??= GenericUtilities.JsonObjectToUri(infraJson["NuGetRegistry"]);
x.npmRegistry ??= GenericUtilities.JsonObjectToUri(infraJson["NPMRegistry"]);
x.azureDevOpsCollectionUrl ??= GenericUtilities.JsonObjectToUri(infraJson["AzureDevopsCollectionURL"]);
x.agentPool ??= infraJson["AgentPool"]?.Value;
if (Enum.TryParse<AgentType>(infraJson["AgentType"]?.Value, out AgentType agentTypeParsed))
{
x.agentType ??= agentTypeParsed;
}
if (!string.IsNullOrEmpty(infraJson["NuGetRegistryUsername"]?.Value))
{
x.nugetRegistryUsername ??= infraJson["NuGetRegistryUsername"]?.Value;
Expand All @@ -367,18 +256,16 @@ internal void Execute(InitArguments x)
{
x.cmfCliRepository ??= infraJson["CmfCliRepository"]?.Value;
}
if (!string.IsNullOrEmpty(infraJson["CmfPipelineRepository"]?.Value))
{
x.cmfPipelineRepository ??= infraJson["CmfPipelineRepository"]?.Value;
}
}
}
}

if (x.nugetRegistry == null ||
x.npmRegistry == null ||
x.azureDevOpsCollectionUrl == null ||
x.ISOLocation == null ||
x.agentPool == null)
//x.azureDevOpsCollectionUrl == null ||
x.ISOLocation == null
//||
//x.agentPool == null
)
{
throw new CliException("Missing infrastructure options. Either specify an infrastructure file with [--infrastructure] or specify each infrastructure option separately.");
}
Expand All @@ -391,10 +278,6 @@ internal void Execute(InitArguments x)
{
args.AddRange(new [] {"--npmRegistry", x.npmRegistry.AbsoluteUri});
}
if (x.azureDevOpsCollectionUrl != null)
{
args.AddRange(new [] {"--azureDevOpsCollectionUrl", x.azureDevOpsCollectionUrl.AbsoluteUri});
}
if (x.ISOLocation != null)
{
args.AddRange(new [] {"--ISOLocation", x.ISOLocation.FullName});
Expand All @@ -410,52 +293,12 @@ internal void Execute(InitArguments x)

args.AddRange(x.cmfCliRepository != null
? new[] { "--cmfCliRepository", x.cmfCliRepository }
: new[] { "--cmfCliRepository", CliConstants.NpmJsUrl });
args.AddRange(x.cmfPipelineRepository != null
? new[] { "--cmfPipelineRepository", x.cmfPipelineRepository }
: new[] { "--cmfPipelineRepository", CliConstants.NpmJsUrl });
: new[] { "--cmfCliRepository", CoreConstants.NpmJsUrl });

if (!string.IsNullOrEmpty(x.agentPool))
{
args.AddRange(new [] {"--agentPool", x.agentPool});
}
args.AddRange(new [] {"--agentType", (x.agentType ??= AgentType.Hosted).ToString()});


#endregion

#region container-specific switches
if (!string.IsNullOrEmpty(x.releaseCustomerEnvironment))
{
args.AddRange(new[] { "--releaseCustomerEnvironment", x.releaseCustomerEnvironment });
}

if (!string.IsNullOrEmpty(x.releaseSite))
{
args.AddRange(new[] { "--releaseSite", x.releaseSite });
}

if (!string.IsNullOrEmpty(x.releaseDeploymentPackage))
{
// we need to escape the @ symbol to avoid that commandline lib parses it as a file
// https://github.com/dotnet/command-line-api/issues/816
x.releaseDeploymentPackage = x.releaseDeploymentPackage.Length > 1 && x.releaseDeploymentPackage[0] == '\\'
? x.releaseDeploymentPackage[1..]
: x.releaseDeploymentPackage;

args.AddRange(new[] { "--releaseDeploymentPackage", $"{x.releaseDeploymentPackage}" });
}

if (!string.IsNullOrEmpty(x.releaseLicense))
{
args.AddRange(new[] { "--releaseLicense", x.releaseLicense });
}

if (!string.IsNullOrEmpty(x.releaseDeploymentTarget))
{
args.AddRange(new[] { "--releaseDeploymentTarget", x.releaseDeploymentTarget });
}
#endregion

#endregion

#region version-specific bits

Expand Down
5 changes: 0 additions & 5 deletions cmf-cli/Constants/CliConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ public static class CliConstants
/// </summary>
public const string DefaultStrategyPath = "$.tenants.config.$(tenant).strategies";

/// <summary>
/// regex to determine repository name from the url
/// </summary>
public static readonly Regex RepoRegex = new Regex(@"^(?<proto>\w+):\/\/(?<host>[^\/]+)\/(?<collection>[^/]+)\/(?<project>[^\/]+\/)?_git\/(?<repo>.+)\/?$", RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);

/// <summary>
/// Default repository type
/// </summary>
Expand Down
9 changes: 4 additions & 5 deletions cmf-cli/resources/template_feed/init/.project-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"BaseLayer": "<%= $CLI_PARAM_BaseLayer %>",
"NPMRegistry": "<%= $CLI_PARAM_NPMRegistry %>",
"NuGetRegistry": "<%= $CLI_PARAM_NuGetRegistry %>",
"AzureDevopsCollectionURL": "<%= $CLI_PARAM_AzureDevopsCollectionURL %>",
"AgentPool": "<%= $CLI_PARAM_AgentPool %>",
"AgentType": "<%= $CLI_PARAM_AgentType %>",
"RepositoryURL": "<%= $CLI_PARAM_RepositoryURL %>",
"EnvironmentName": "<%= $CLI_PARAM_EnvironmentName %>",
"DefaultDomain": "<%= $CLI_PARAM_DefaultDomain %>",
"RESTPort": "<%= $CLI_PARAM_RESTPort %>",
Expand All @@ -34,5 +30,8 @@
"HTMLPort": "<%= $CLI_PARAM_HTMLPort %>",
"GatewayPort": "<%= $CLI_PARAM_GatewayPort %>",
"ReleaseEnvironmentConfig": "<%= $CLI_PARAM_ReleaseEnvironmentConfig %>",
"ISOLocation": "<%= $CLI_PARAM_ISOLocation_JSON %>"
"ISOLocation": "<%= $CLI_PARAM_ISOLocation_JSON %>",
"CmfCliRepository": "<%= $CLI_PARAM_CmfCliRepository %>",
"DeploymentDir": "<%= $CLI_PARAM_DeploymentDir %>",
"DeliveredRepo": "<%= $CLI_PARAM_DeliveredRepo %>"
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 05976a3

Please sign in to comment.