Exemplo n.º 1
0
        public override async Task ExecuteAsync()
        {
            _loggerService.WriteHeading("PUBLISHING MCR DOCS");

            // Hookup a TraceListener in order to capture details from Microsoft.DotNet.VersionTools
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            IEnumerable <GitObject> gitObjects =
                GetUpdatedReadmes()
                .Concat(GetUpdatedTagsMetadata());

            foreach (GitObject gitObject in gitObjects)
            {
                _loggerService.WriteMessage(
                    $"Updated file '{gitObject.Path}' with contents:{Environment.NewLine}{gitObject.Content}{Environment.NewLine}");
            }

            if (!Options.IsDryRun)
            {
                using IGitHubClient gitHubClient = _gitHubClientFactory.GetClient(Options.GitOptions.ToGitHubAuth(), Options.IsDryRun);

                await RetryHelper.GetWaitAndRetryPolicy <HttpRequestException>(_loggerService).ExecuteAsync(async() =>
                {
                    GitReference gitRef = await GitHelper.PushChangesAsync(gitHubClient, Options, $"Mirroring readmes", branch =>
                    {
                        return(FilterUpdatedGitObjectsAsync(gitObjects, gitHubClient, branch));
                    });

                    if (gitRef != null)
                    {
                        _loggerService.WriteMessage(PipelineHelper.FormatOutputVariable("readmeCommitDigest", gitRef.Object.Sha));
                    }
                });
            }
        }
Exemplo n.º 2
0
        public override Task ExecuteAsync()
        {
            IEnumerable <(string Tag, string Platform)> platformTags;

            if (string.IsNullOrEmpty(Options.ImageInfoPath))
            {
                platformTags = Manifest.GetFilteredPlatforms()
                               .Where(platform => platform.Tags.Any())
                               .Select(platform => (platform.Tags.First().FullyQualifiedName, platform.PlatformLabel));
            }
            else
            {
                // We want to apply manifest filtering to the loading of the image info file. This allows, for example,
                // only images of a specific architecture to be pulled.
                ImageArtifactDetails imageArtifactDetails = ImageInfoHelper.LoadFromFile(
                    Options.ImageInfoPath, Manifest, skipManifestValidation: true, useFilteredManifest: true);
                platformTags = imageArtifactDetails.Repos
                               .SelectMany(repo => repo.Images)
                               .SelectMany(image => image.Platforms)
                               // If the platform doesn't have an associated manifest instance, it means the manifest filter
                               // options had filtered out the platform. In that case, it doesn't apply and shouldn't be pulled.
                               .Where(platform => platform.PlatformInfo is not null && platform.SimpleTags.Any())
                               .Select(platform => (
                                           TagInfo.GetFullyQualifiedName(platform.PlatformInfo !.FullRepoModelName, platform.SimpleTags.First()),
                                           platform.PlatformInfo !.PlatformLabel));
            }

            platformTags = platformTags
                           .Distinct()
                           .ToList();

            _loggerService.WriteHeading("PULLING IMAGES");
            foreach ((string tag, string platform) in platformTags)
            {
                _dockerService.PullImage(tag, platform, Options.IsDryRun);
            }

            if (Options.OutputVariableName is not null)
            {
                _loggerService.WriteMessage(
                    PipelineHelper.FormatOutputVariable(
                        Options.OutputVariableName,
                        string.Join(',', platformTags.Select(platformTag => platformTag.Tag))));
            }

            return(Task.CompletedTask);
        }
 private static void EmitVstsVariables(IEnumerable <BuildMatrixInfo> matrices)
 {
     // Emit the special syntax to set a VSTS build definition matrix variable
     // ##vso[task.setvariable variable=x;isoutput=true]{ \"a\": { \"v1\": \"1\" }, \"b\": { \"v1\": \"2\" } }
     foreach (BuildMatrixInfo matrix in matrices)
     {
         string legs = matrix.OrderedLegs
                       .Select(leg =>
         {
             string variables = leg.Variables
                                .Select(var => $" \"{var.Name}\": \"{var.Value}\"")
                                .Aggregate((working, next) => $"{working},{next}");
             return($" \"{leg.Name}\": {{{variables} }}");
         })
                       .Aggregate((working, next) => $"{working},{next}");
         Logger.WriteMessage(PipelineHelper.FormatOutputVariable(matrix.Name, $"{{{legs}}}"));
     }
 }
Exemplo n.º 4
0
        public override async Task ExecuteAsync()
        {
            string subscriptionsJson = File.ReadAllText(Options.SubscriptionsPath);

            Subscription[] subscriptions = JsonConvert.DeserializeObject <Subscription[]>(subscriptionsJson);

            try
            {
                SubscriptionImagePaths[] results = await Task.WhenAll(
                    subscriptions.Select(async s => new SubscriptionImagePaths
                {
                    SubscriptionId = s.Id,
                    ImagePaths     = (await GetPathsToRebuildAsync(s)).ToArray()
                }));

                // Filter out any results that don't have any images to rebuild
                results = results
                          .Where(result => result.ImagePaths.Any())
                          .ToArray();

                string outputString = JsonConvert.SerializeObject(results);

                _loggerService.WriteMessage(
                    PipelineHelper.FormatOutputVariable(Options.VariableName, outputString)
                    .Replace("\"", "\\\""));     // Escape all quotes

                string formattedResults = JsonConvert.SerializeObject(results, Formatting.Indented);
                _loggerService.WriteMessage(
                    $"Image Paths to be Rebuilt:{Environment.NewLine}{formattedResults}");
            }
            finally
            {
                foreach (string repoPath in _gitRepoIdToPathMapping.Values)
                {
                    // The path to the repo is stored inside a zip extraction folder so be sure to delete that
                    // zip extraction folder, not just the inner repo folder.
                    Directory.Delete(new DirectoryInfo(repoPath).Parent.FullName, true);
                }
            }
        }