/// <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); }
public async Task <List <GitFile> > GetCommonScriptFilesAsync(string repoUri, string commit) { CheckForValidGitClient(); _logger.LogInformation("Generating commits for script files"); List <GitFile> files = await _gitClient.GetFilesForCommitAsync(repoUri, commit, "eng/common"); _logger.LogInformation("Generating commits for script files succeeded!"); return(files); }