private void AddVersionedOsLegs(BuildMatrixInfo matrix, IGrouping <PlatformId, PlatformInfo> platformGrouping)
        {
            var versionGroups = platformGrouping
                                .GroupBy(platform => new
            {
                // Assumption:  Dockerfile path format <ProductVersion>/<ImageVariant>/<OsVariant>/...
                DotNetVersion = GetDotNetVersionFromPath(platform.DockerfilePathRelativeToManifest),
                OsVariant     = platform.Model.OsVersion
            });

            foreach (var versionGrouping in versionGroups)
            {
                IEnumerable <PlatformInfo> subgraphs = versionGrouping
                                                       .GetCompleteSubgraphs(platform => GetPlatformDependencies(platform, platformGrouping))
                                                       .SelectMany(subgraph => subgraph);

                BuildLegInfo leg = new BuildLegInfo()
                {
                    Name = $"{versionGrouping.Key.DotNetVersion}-{versionGrouping.Key.OsVariant}"
                };
                matrix.Legs.Add(leg);

                AddCommonVariables(platformGrouping, leg);
                leg.Variables.Add(("dotnetVersion", versionGrouping.Key.DotNetVersion));
                leg.Variables.Add(("osVariant", versionGrouping.Key.OsVariant));

                IEnumerable <string> dockerfilePaths = GetDockerfilePaths(subgraphs)
                                                       .Union(GetCustomLegGroupingDockerfilePaths(subgraphs));

                AddImageBuilderPathsVariable(dockerfilePaths.ToArray(), leg);
            }
        }
        private static void AddImageBuilderPathsVariable(string[] dockerfilePaths, BuildLegInfo leg)
        {
            string pathArgs = dockerfilePaths
                              .Select(path => $"{ManifestFilterOptions.FormattedPathOption} {path}")
                              .Aggregate((working, next) => $"{working} {next}");

            leg.Variables.Add(("imageBuilderPaths", pathArgs));
        }
        private void AddDockerfilePathLegs(
            BuildMatrixInfo matrix, IEnumerable <string> matrixNameParts, IGrouping <PlatformId, PlatformInfo> platformGrouping)
        {
            IEnumerable <IEnumerable <PlatformInfo> > subgraphs = platformGrouping.GetCompleteSubgraphs(
                platform => GetPlatformDependencies(platform, platformGrouping));

            foreach (IEnumerable <PlatformInfo> subgraph in subgraphs)
            {
                string[] dockerfilePaths = GetDockerfilePaths(subgraph)
                                           .Union(GetCustomLegGroupingDockerfilePaths(subgraph))
                                           .ToArray();

                BuildLegInfo leg = new BuildLegInfo()
                {
                    Name = GetDockerfilePathLegName(dockerfilePaths, matrixNameParts)
                };
                matrix.Legs.Add(leg);

                AddImageBuilderPathsVariable(dockerfilePaths, leg);
                AddCommonVariables(platformGrouping, leg);
            }
        }
        private static void AddCommonVariables(IGrouping <PlatformId, PlatformInfo> platformGrouping, BuildLegInfo leg)
        {
            string fullyQualifiedLegName =
                (platformGrouping.Key.OsVersion ?? platformGrouping.Key.OS.GetDockerName()) +
                platformGrouping.Key.Architecture.GetDisplayName(platformGrouping.Key.Variant) +
                leg.Name;

            leg.Variables.Add(("legName", fullyQualifiedLegName));
            leg.Variables.Add(("osType", platformGrouping.Key.OS.GetDockerName()));
            leg.Variables.Add(("architecture", platformGrouping.Key.Architecture.GetDockerName()));
            leg.Variables.Add(("osVersion", platformGrouping.Key.OsVersion ?? "*"));
        }