private string GetTagGroupYaml(IEnumerable <ImageDocumentationInfo> infos)
        {
            ImageDocumentationInfo firstInfo = infos.First();

            string dockerfilePath = _gitService.GetDockerfileCommitUrl(firstInfo.Platform, _sourceRepoUrl, _sourceBranch);

            // Generate a list of tags that have this sorting convention:
            // <concrete tags>, <shared tags of platforms that have no concrete tags>, <shared tags of platforms that have concrete tags>
            // This convention should produce a list of tags that are listed from most specificity to least.

            IEnumerable <string> formattedPlatformTags = infos
                                                         .SelectMany(info => info.DocumentedPlatformTags.Select(tag => tag.Name));

            IEnumerable <string> formattedSharedTags = infos
                                                       .Where(info => !info.DocumentedPlatformTags.Any())
                                                       .SelectMany(info => info.DocumentedSharedTags.Select(tag => tag.Name));

            formattedSharedTags = formattedSharedTags.Concat(infos
                                                             .Where(info => info.DocumentedPlatformTags.Any())
                                                             .SelectMany(info => info.DocumentedSharedTags.Select(tag => tag.Name)));

            string formattedTags = string.Join(", ", formattedPlatformTags.Concat(formattedSharedTags));

            StringBuilder yaml = new StringBuilder();

            yaml.AppendLine($"  - tags: [ {formattedTags} ]");
            yaml.AppendLine($"    architecture: {firstInfo.Platform.Model.Architecture.GetDisplayName()}");
            yaml.AppendLine($"    os: {firstInfo.Platform.Model.OS.GetDockerName()}");
            yaml.AppendLine($"    osVersion: {firstInfo.Platform.GetOSDisplayName()}");
            yaml.Append($"    dockerfile: {dockerfilePath}");

            return(yaml.ToString());
        }
        private string GetVariableValue(string variableType, string variableName)
        {
            string variableValue = null;

            if (string.Equals(variableType, VariableHelper.McrTagsYmlRepoTypeId, StringComparison.Ordinal))
            {
                RepoInfo repo = _manifest.GetFilteredRepoById(variableName);
                variableValue = GetRepoYaml(repo);
            }
            else if (string.Equals(variableType, VariableHelper.McrTagsYmlTagGroupTypeId, StringComparison.Ordinal))
            {
                ImageDocumentationInfo info = _imageDocInfos
                                              .FirstOrDefault(idi => idi.DocumentedTags.Any(tag => tag.Name == variableName));
                if (info != null)
                {
                    // Find all other doc infos that match this one. This accounts for scenarios where a platform is
                    // duplicated in another image in order to associate it within a distinct set of shared tags.
                    IEnumerable <ImageDocumentationInfo> matchingDocInfos = _imageDocInfos
                                                                            .Where(docInfo => docInfo.Platform != info.Platform &&
                                                                                   PlatformInfo.AreMatchingPlatforms(docInfo.Image, docInfo.Platform, info.Image, info.Platform))
                                                                            .Prepend(info)
                                                                            .ToArray();

                    foreach (ImageDocumentationInfo docInfo in matchingDocInfos)
                    {
                        _imageDocInfos.Remove(docInfo);
                    }

                    variableValue = GetTagGroupYaml(matchingDocInfos);
                }
            }

            return(variableValue);
        }
Beispiel #3
0
        private string GetTagDocumentation(ImageDocumentationInfo info)
        {
            string tags = info.DocumentedTags
                          .Select(tag => $"`{tag.Name}`")
                          .Aggregate((working, next) => $"{working}, {next}");
            string dockerfile = info.Platform.DockerfilePath.Replace('\\', '/');

            return($"- [{tags} (*Dockerfile*)]({Options.SourceUrl}/{dockerfile})");
        }
        private string GetTagGroupYaml(ImageDocumentationInfo info)
        {
            string dockerfilePath = _gitService.GetDockerfileCommitUrl(info.Platform, _sourceRepoUrl, _sourceBranch);

            StringBuilder yaml = new StringBuilder();

            yaml.AppendLine($"  - tags: [ {info.FormattedDocumentedTags} ]");
            yaml.AppendLine($"    architecture: {info.Platform.Model.Architecture.GetDisplayName()}");
            yaml.AppendLine($"    os: {info.Platform.Model.OS.GetDockerName()}");
            yaml.AppendLine($"    osVersion: {info.Platform.GetOSDisplayName()}");
            yaml.Append($"    dockerfile: {dockerfilePath}");

            return(yaml.ToString());
        }
        private string GetVariableValue(string variableType, string variableName)
        {
            string variableValue = null;

            if (string.Equals(variableType, VariableHelper.TagDocTypeId, StringComparison.Ordinal))
            {
                ImageDocumentationInfo info = ImageDocInfos
                                              .FirstOrDefault(tli => tli.Platform.Tags.Any(tag => tag.Name == variableName));
                if (info != null)
                {
                    variableValue = GetTagDocumentation(info);
                    ImageDocInfos.Remove(info);
                }
            }

            return(variableValue);
        }
Beispiel #6
0
        private string GetVariableValue(string variableType, string variableName)
        {
            string variableValue = null;

            if (string.Equals(variableType, VariableHelper.TagDocTypeId, StringComparison.Ordinal))
            {
                ImageDocumentationInfo info = ImageDocInfos
                                              .FirstOrDefault(idi => idi.DocumentedTags.Any(tag => tag.Name == variableName));
                if (info != null)
                {
                    variableValue = GetTagDocumentation(info);
                    ImageDocInfos.Remove(info);
                }
            }
            else if (string.Equals(variableType, VariableHelper.TagDocListTypeId, StringComparison.Ordinal))
            {
                IEnumerable <string> variableTags = variableName.Split('|');
                if (variableTags.Any())
                {
                    ImageDocumentationInfo info = ImageDocInfos
                                                  .FirstOrDefault(idi => idi.DocumentedTags.Select(tag => tag.Name).Intersect(variableTags).Count() == variableTags.Count());
                    if (info != null)
                    {
                        IEnumerable <TagInfo> variableTagInfos = info.DocumentedTags
                                                                 .Where(tag => variableTags.Any(docTag => docTag == tag.Name));
                        variableValue = GetTagDocumentation(new ImageDocumentationInfo(info.Platform, variableTagInfos));

                        // Remove the tags referenced by the TagDocList.  This will ensure an exception if there are any tags
                        // excluded from the readme.
                        info.DocumentedTags = info.DocumentedTags.Except(variableTagInfos);
                        if (!info.DocumentedTags.Any())
                        {
                            ImageDocInfos.Remove(info);
                        }
                    }
                }
            }
            else if (string.Equals(variableType, VariableHelper.SystemVariableTypeId, StringComparison.Ordinal) &&
                     string.Equals(variableName, VariableHelper.SourceUrlVariableName, StringComparison.Ordinal))
            {
                variableValue = Options.SourceUrl;
            }

            return(variableValue);
        }
        private string GetTagGroupYaml(ImageDocumentationInfo info)
        {
            string branchOrShaPathSegment = _sourceBranch ??
                                            _gitService.GetCommitSha(info.Platform.DockerfilePath, useFullHash: true);

            string dockerfileRelativePath = PathHelper.NormalizePath(info.Platform.DockerfilePathRelativeToManifest);
            string dockerfilePath         = $"{_sourceRepoUrl}/blob/{branchOrShaPathSegment}/{dockerfileRelativePath}";

            StringBuilder yaml = new StringBuilder();

            yaml.AppendLine($"  - tags: [ {info.FormattedDocumentedTags} ]");
            yaml.AppendLine($"    architecture: {info.Platform.Model.Architecture.GetDisplayName()}");
            yaml.AppendLine($"    os: {info.Platform.Model.OS.GetDockerName()}");
            yaml.AppendLine($"    osVersion: {GetOSDisplayName(info.Platform)}");
            yaml.Append($"    dockerfile: {dockerfilePath}");

            return(yaml.ToString());
        }
        private string Execute()
        {
            Logger.WriteHeading("GENERATING MCR TAGS METADATA");

            _imageDocInfos = _repo.FilteredImages
                             .SelectMany(image =>
                                         image.AllPlatforms.SelectMany(platform => ImageDocumentationInfo.Create(image, platform)))
                             .Where(info => info.DocumentedTags.Any())
                             .ToList();

            StringBuilder yaml = new StringBuilder();

            yaml.AppendLine("repos:");

            string templatePath = Path.Combine(_manifest.Directory, _repo.Model.McrTagsMetadataTemplate);

            string template = File.ReadAllText(templatePath);

            yaml.Append(_manifest.VariableHelper.SubstituteValues(template, GetVariableValue));

            if (_imageDocInfos.Any())
            {
                string missingTags = string.Join(
                    Environment.NewLine, _imageDocInfos.Select(info => info.FormattedDocumentedTags));
                throw new InvalidOperationException(
                          $"The following tags are not included in the tags metadata: {Environment.NewLine}{missingTags}");
            }

            string metadata = yaml.ToString();

            Logger.WriteSubheading("Generated Metadata:");
            Logger.WriteMessage(metadata);

            // Validate that the YAML is in a valid format
            new DeserializerBuilder()
            .WithNamingConvention(CamelCaseNamingConvention.Instance)
            .Build()
            .Deserialize <TagsMetadata>(metadata);

            return(metadata);
        }
        private string GetVariableValue(string variableType, string variableName)
        {
            string variableValue = null;

            if (string.Equals(variableType, VariableHelper.McrTagsYmlRepoTypeId, StringComparison.Ordinal))
            {
                RepoInfo repo = _manifest.GetFilteredRepoById(variableName);
                variableValue = GetRepoYaml(repo);
            }
            else if (string.Equals(variableType, VariableHelper.McrTagsYmlTagGroupTypeId, StringComparison.Ordinal))
            {
                ImageDocumentationInfo info = _imageDocInfos
                                              .FirstOrDefault(idi => idi.DocumentedTags.Any(tag => tag.Name == variableName));
                if (info != null)
                {
                    _imageDocInfos.Remove(info);
                    variableValue = GetTagGroupYaml(info);
                }
            }

            return(variableValue);
        }
Beispiel #10
0
        public override Task ExecuteAsync()
        {
            Logger.WriteHeading("GENERATING TAGS README");
            foreach (RepoInfo repo in Manifest.FilteredRepos)
            {
                ImageDocInfos = repo.AllImages
                                .SelectMany(image => image.AllPlatforms.SelectMany(platform => ImageDocumentationInfo.Create(image, platform)))
                                .Where(info => info.DocumentedTags.Any())
                                .ToList();

                string tagsDoc = Options.Template == null?
                                 GetManifestBasedDocumentation() : GetTemplateBasedDocumentation(Options.Template);

                Logger.WriteSubheading($"{repo.Name} Tags Documentation:");
                Logger.WriteMessage();
                Logger.WriteMessage(tagsDoc);

                if (Options.UpdateReadme)
                {
                    UpdateReadme(tagsDoc, repo);
                }
            }

            return(Task.CompletedTask);
        }