Пример #1
0
        /// <summary>
        ///     Updates existing dependencies in the dependency files
        /// </summary>
        /// <param name="dependencies">Dependencies that need updates.</param>
        /// <param name="remote">Remote instance for gathering eng/common script updates.</param>
        /// <returns></returns>
        public async Task UpdateDependenciesAsync(List <DependencyDetail> dependencies, IRemote remote)
        {
            // TODO: This should use known updaters, but today the updaters for global.json can only
            // add, not actually update.  This needs a fix. https://github.com/dotnet/arcade/issues/1095

            /*List<DependencyDetail> defaultUpdates = new List<DependencyDetail>(, IRemote remote);
             * foreach (DependencyDetail dependency in dependencies)
             * {
             *  if (DependencyOperations.TryGetKnownUpdater(dependency.Name, out Delegate function))
             *  {
             *      await (Task)function.DynamicInvoke(_fileManager, _repo, dependency);
             *  }
             *  else
             *  {
             *      defaultUpdates.Add(dependency);
             *  }
             * }*/

            var fileContainer = await _fileManager.UpdateDependencyFiles(dependencies, _repo, null);

            List <GitFile> filesToUpdate = fileContainer.GetFilesToCommit();

            // TODO: This needs to be moved into some consistent handling between local/remote and add/update:
            // https://github.com/dotnet/arcade/issues/1095
            // If we are updating the arcade sdk we need to update the eng/common files as well
            DependencyDetail arcadeItem = dependencies.FirstOrDefault(
                i => string.Equals(i.Name, "Microsoft.DotNet.Arcade.Sdk", StringComparison.OrdinalIgnoreCase));

            if (arcadeItem != null)
            {
                try
                {
                    List <GitFile> engCommonFiles = await remote.GetCommonScriptFilesAsync(arcadeItem.RepoUri, arcadeItem.Commit);

                    filesToUpdate.AddRange(engCommonFiles);

                    List <GitFile> localEngCommonFiles = await _gitClient.GetFilesForCommitAsync(null, null, "eng/common");

                    foreach (GitFile file in localEngCommonFiles)
                    {
                        if (!engCommonFiles.Where(f => f.FilePath == file.FilePath).Any())
                        {
                            file.Operation = GitFileOperation.Delete;
                            filesToUpdate.Add(file);
                        }
                    }
                }
                catch (Exception exc) when
                    (exc.Message == "Not Found")
                {
                    _logger.LogWarning("Could not update 'eng/common'. Most likely this is a scenario " +
                                       "where a packages folder was passed and the commit which generated them is not " +
                                       "yet pushed.");
                }
            }

            // Push on local does not commit.
            await _gitClient.PushFilesAsync(filesToUpdate, _repo, null, null);
        }
Пример #2
0
        /// <summary>
        ///     Updates existing dependencies in the dependency files
        /// </summary>
        /// <param name="dependencies">Dependencies that need updates.</param>
        /// <param name="remote">Remote instance for gathering eng/common script updates.</param>
        /// <returns></returns>
        public async Task UpdateDependenciesAsync(List <DependencyDetail> dependencies, IRemoteFactory remoteFactory)
        {
            // Read the current dependency files and grab their locations so that nuget.config can be updated appropriately.
            // Update the incoming dependencies with locations.
            IEnumerable <DependencyDetail> oldDependencies = await GetDependenciesAsync();

            IRemote barOnlyRemote = await remoteFactory.GetBarOnlyRemoteAsync(_logger);

            await barOnlyRemote.AddAssetLocationToDependenciesAsync(oldDependencies);

            await barOnlyRemote.AddAssetLocationToDependenciesAsync(dependencies);

            var fileContainer = await _fileManager.UpdateDependencyFiles(dependencies, _repo, null, oldDependencies);

            List <GitFile> filesToUpdate = fileContainer.GetFilesToCommit();

            // TODO: This needs to be moved into some consistent handling between local/remote and add/update:
            // https://github.com/dotnet/arcade/issues/1095
            // If we are updating the arcade sdk we need to update the eng/common files as well
            DependencyDetail arcadeItem = dependencies.FirstOrDefault(
                i => string.Equals(i.Name, "Microsoft.DotNet.Arcade.Sdk", StringComparison.OrdinalIgnoreCase));

            if (arcadeItem != null)
            {
                try
                {
                    IRemote remote = await remoteFactory.GetRemoteAsync(arcadeItem.RepoUri, _logger);

                    List <GitFile> engCommonFiles = await remote.GetCommonScriptFilesAsync(arcadeItem.RepoUri, arcadeItem.Commit);

                    filesToUpdate.AddRange(engCommonFiles);

                    List <GitFile> localEngCommonFiles = await _gitClient.GetFilesAtCommitAsync(null, null, "eng/common");

                    foreach (GitFile file in localEngCommonFiles)
                    {
                        if (!engCommonFiles.Where(f => f.FilePath == file.FilePath).Any())
                        {
                            file.Operation = GitFileOperation.Delete;
                            filesToUpdate.Add(file);
                        }
                    }
                }
                catch (Exception exc) when
                    (exc.Message == "Not Found")
                {
                    _logger.LogWarning("Could not update 'eng/common'. Most likely this is a scenario " +
                                       "where a packages folder was passed and the commit which generated them is not " +
                                       "yet pushed.");
                }
            }

            // Push on local does not commit.
            await _gitClient.CommitFilesAsync(filesToUpdate, _repo, null, null);
        }
Пример #3
0
        private async Task CommitFilesForPullRequestAsync(string repoUri, string branch, string assetsProducedInCommit, IEnumerable <DependencyDetail> itemsToUpdate, string pullRequestBaseBranch = null)
        {
            CheckForValidGitClient();
            GitFileContentContainer fileContainer = await _fileManager.UpdateDependencyFiles(itemsToUpdate, repoUri, branch);

            List <GitFile> filesToCommit = fileContainer.GetFilesToCommitMap(pullRequestBaseBranch);

            // If there is an arcade asset that we need to update we try to update the script files as well
            DependencyDetail arcadeItem = itemsToUpdate.Where(i => i.Name.ToLower().Contains("arcade")).FirstOrDefault();

            if (arcadeItem != null &&
                repoUri != arcadeItem.RepoUri)
            {
                List <GitFile> engCommonsFiles = await GetScriptFilesAsync(arcadeItem.RepoUri, assetsProducedInCommit);

                filesToCommit.AddRange(engCommonsFiles);
            }

            await _gitClient.PushFilesAsync(filesToCommit, repoUri, pullRequestBaseBranch, "Updating version files");
        }
Пример #4
0
        public async Task CommitUpdatesAsync(
            string repoUri,
            string branch,
            List <DependencyDetail> itemsToUpdate,
            string message)
        {
            CheckForValidGitClient();
            GitFileContentContainer fileContainer =
                await _fileManager.UpdateDependencyFiles(itemsToUpdate, repoUri, branch);

            List <GitFile> filesToCommit = fileContainer.GetFilesToCommit();

            // If we are updating the arcade sdk we need to update the eng/common files as well
            DependencyDetail arcadeItem = itemsToUpdate.FirstOrDefault(
                i => string.Equals(i.Name, "Microsoft.DotNet.Arcade.Sdk", StringComparison.OrdinalIgnoreCase));

            if (arcadeItem != null && repoUri != arcadeItem.RepoUri)
            {
                // Files in arcade repository
                List <GitFile> engCommonFiles = await GetCommonScriptFilesAsync(arcadeItem.RepoUri, arcadeItem.Commit);

                filesToCommit.AddRange(engCommonFiles);

                // Files in the target repo
                string latestCommit = await _gitClient.GetLastCommitShaAsync(_gitClient.GetOwnerAndRepoFromRepoUri(repoUri), branch);

                List <GitFile> targetEngCommonFiles = await GetCommonScriptFilesAsync(repoUri, latestCommit);

                foreach (GitFile file in targetEngCommonFiles)
                {
                    if (!engCommonFiles.Where(f => f.FilePath == file.FilePath).Any())
                    {
                        file.Operation = GitFileOperation.Delete;
                        filesToCommit.Add(file);
                    }
                }
            }

            await _gitClient.PushFilesAsync(filesToCommit, repoUri, branch, message);
        }
Пример #5
0
        /// <summary>
        ///     Updates existing dependencies in the dependency files
        /// </summary>
        /// <param name="dependencies">Dependencies that need updates.</param>
        /// <param name="remote">Remote instance for gathering eng/common script updates.</param>
        /// <returns></returns>
        public async Task UpdateDependenciesAsync(List <DependencyDetail> dependencies, IRemote remote)
        {
            // TODO: This should use known updaters, but today the updaters for global.json can only
            // add, not actually update.  This needs a fix. https://github.com/dotnet/arcade/issues/1095

            /*List<DependencyDetail> defaultUpdates = new List<DependencyDetail>(, IRemote remote);
             * foreach (DependencyDetail dependency in dependencies)
             * {
             *  if (DependencyOperations.TryGetKnownUpdater(dependency.Name, out Delegate function))
             *  {
             *      await (Task)function.DynamicInvoke(_fileManager, _repo, dependency);
             *  }
             *  else
             *  {
             *      defaultUpdates.Add(dependency);
             *  }
             * }*/

            var fileContainer = await _fileManager.UpdateDependencyFiles(dependencies, _repo, null);

            List <GitFile> filesToUpdate = fileContainer.GetFilesToCommit();

            // TODO: This needs to be moved into some consistent handling between local/remote and add/update:
            // https://github.com/dotnet/arcade/issues/1095
            // If we are updating the arcade sdk we need to update the eng/common files as well
            DependencyDetail arcadeItem = dependencies.FirstOrDefault(
                i => string.Equals(i.Name, "Microsoft.DotNet.Arcade.Sdk", StringComparison.OrdinalIgnoreCase));

            if (arcadeItem != null)
            {
                List <GitFile> engCommonFiles = await remote.GetCommonScriptFilesAsync(arcadeItem.RepoUri, arcadeItem.Commit);

                filesToUpdate.AddRange(engCommonFiles);
            }

            // Push on local does not commit.
            await _gitClient.PushFilesAsync(filesToUpdate, _repo, null, null);
        }
Пример #6
0
        /// <summary>
        ///     Updates existing dependencies in the dependency files
        /// </summary>
        /// <param name="dependencies">Dependencies that need updates.</param>
        /// <param name="remote">Remote instance for gathering eng/common script updates.</param>
        /// <returns></returns>
        public async Task UpdateDependenciesAsync(List <DependencyDetail> dependencies, IRemoteFactory remoteFactory)
        {
            // Read the current dependency files and grab their locations so that nuget.config can be updated appropriately.
            // Update the incoming dependencies with locations.
            IEnumerable <DependencyDetail> oldDependencies = await GetDependenciesAsync();

            IRemote barOnlyRemote = await remoteFactory.GetBarOnlyRemoteAsync(_logger);

            await barOnlyRemote.AddAssetLocationToDependenciesAsync(oldDependencies);

            await barOnlyRemote.AddAssetLocationToDependenciesAsync(dependencies);

            // If we are updating the arcade sdk we need to update the eng/common files as well
            DependencyDetail arcadeItem = dependencies.FirstOrDefault(
                i => string.Equals(i.Name, "Microsoft.DotNet.Arcade.Sdk", StringComparison.OrdinalIgnoreCase));
            SemanticVersion targetDotNetVersion = null;
            IRemote         arcadeRemote        = null;

            if (arcadeItem != null)
            {
                arcadeRemote = await remoteFactory.GetRemoteAsync(arcadeItem.RepoUri, _logger);

                targetDotNetVersion = await arcadeRemote.GetToolsDotnetVersionAsync(arcadeItem.RepoUri, arcadeItem.Commit);
            }

            var fileContainer = await _fileManager.UpdateDependencyFiles(dependencies, _repo, null, oldDependencies, targetDotNetVersion);

            List <GitFile> filesToUpdate = fileContainer.GetFilesToCommit();

            if (arcadeItem != null)
            {
                try
                {
                    List <GitFile> engCommonFiles = await arcadeRemote.GetCommonScriptFilesAsync(arcadeItem.RepoUri, arcadeItem.Commit);

                    filesToUpdate.AddRange(engCommonFiles);

                    List <GitFile> localEngCommonFiles = await _gitClient.GetFilesAtCommitAsync(null, null, "eng/common");

                    foreach (GitFile file in localEngCommonFiles)
                    {
                        if (!engCommonFiles.Where(f => f.FilePath == file.FilePath).Any())
                        {
                            // This is a file in the repo's eng/common folder that isn't present in Arcade at the
                            // requested SHA so delete it during the update.
                            // GitFile instances do not have public setters since we insert/retrieve them from an
                            // In-memory cache during remote updates and we don't want anything to modify the cached,
                            // references, so add a copy with a Delete FileOperation.
                            filesToUpdate.Add(new GitFile(
                                                  file.FilePath,
                                                  file.Content,
                                                  file.ContentEncoding,
                                                  file.Mode,
                                                  GitFileOperation.Delete));
                        }
                    }
                }
                catch (Exception exc) when
                    (exc.Message == "Not Found")
                {
                    _logger.LogWarning("Could not update 'eng/common'. Most likely this is a scenario " +
                                       "where a packages folder was passed and the commit which generated them is not " +
                                       "yet pushed.");
                }
            }

            // Push on local does not commit.
            await _gitClient.CommitFilesAsync(filesToUpdate, _repo, null, null);
        }
Пример #7
0
        public async Task CommitUpdatesAsync(
            string repoUri,
            string branch,
            List <DependencyDetail> itemsToUpdate,
            string message)
        {
            CheckForValidGitClient();
            GitFileContentContainer fileContainer =
                await _fileManager.UpdateDependencyFiles(itemsToUpdate, repoUri, branch);

            List <GitFile> filesToCommit = new List <GitFile>();

            // If we are updating the arcade sdk we need to update the eng/common files and the dotnet versions as well
            DependencyDetail arcadeItem = itemsToUpdate.FirstOrDefault(
                i => string.Equals(i.Name, "Microsoft.DotNet.Arcade.Sdk", StringComparison.OrdinalIgnoreCase));

            if (arcadeItem != null && repoUri != arcadeItem.RepoUri)
            {
                // Files in arcade repository. All Arcade items have a GitHub repo URI by default so we need to change the
                // URI from we are getting the eng/common files. If in an AzDO context we change the URI to that of
                // dotnet-arcade in dnceng

                string arcadeRepoUri = arcadeItem.RepoUri;

                if (Uri.TryCreate(repoUri, UriKind.Absolute, out Uri parsedUri))
                {
                    if (parsedUri.Host == "dev.azure.com" || parsedUri.Host.EndsWith("visualstudio.com"))
                    {
                        arcadeRepoUri = "https://dev.azure.com/dnceng/internal/_git/dotnet-arcade";
                    }
                }

                SemanticVersion arcadeDotnetVersion = await GetToolsDotnetVersionAsync(arcadeRepoUri, arcadeItem.Commit);

                if (arcadeDotnetVersion != null)
                {
                    fileContainer.GlobalJson = UpdateDotnetVersionGlobalJson(arcadeDotnetVersion, fileContainer.GlobalJson);
                }

                List <GitFile> engCommonFiles = await GetCommonScriptFilesAsync(arcadeRepoUri, arcadeItem.Commit);

                filesToCommit.AddRange(engCommonFiles);

                // Files in the target repo
                string latestCommit = await _gitClient.GetLastCommitShaAsync(repoUri, branch);

                List <GitFile> targetEngCommonFiles = await GetCommonScriptFilesAsync(repoUri, latestCommit);

                foreach (GitFile file in targetEngCommonFiles)
                {
                    if (!engCommonFiles.Where(f => f.FilePath == file.FilePath).Any())
                    {
                        file.Operation = GitFileOperation.Delete;
                        filesToCommit.Add(file);
                    }
                }
            }

            filesToCommit.AddRange(fileContainer.GetFilesToCommit());

            await _gitClient.CommitFilesAsync(filesToCommit, repoUri, branch, message);
        }