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