Example #1
0
        /// <summary>
        /// Finalizes the changelog by moving all entries from `[vNext]` to the version specified by release.
        /// <p>If <paramref name="repository"/> is specified a summary with all versions and links to list the changes directly on GitHub is appended to the end of the changelog.</p>
        /// </summary>
        /// <param name="changelogFile">The path to the changelog file.</param>
        /// <param name="tag">The <see cref="NuGetVersion"/> to finalize the changelog.</param>
        /// <param name="repository">The repository to create the version overview for.</param>
        /// <seealso cref="FinalizeChangelog(ChangeLog,NuGetVersion,GitRepository)"/>
        public static void FinalizeChangelog(ChangeLog changelogFile, NuGetVersion tag, [CanBeNull] GitRepository repository = null)
        {
            Logger.Info($"Finalizing {PathConstruction.GetRelativePath(NukeBuild.RootDirectory, changelogFile.Path)} for '{tag}'...");

            var unreleasedNotes = changelogFile.Unreleased;
            var releaseNotes    = changelogFile.ReleaseNotes;
            var lastReleased    = changelogFile.LatestVersion;

            ControlFlow.Assert(unreleasedNotes != null, "Changelog should have draft section.");
            ControlFlow.Assert(releaseNotes.Any(x => x.Version != null && x.Version.Equals(tag)), $"Tag '{tag}' already exists.");
            ControlFlow.Assert(lastReleased != null && tag.CompareTo(lastReleased.Version) > 0,
                               $"Tag '{tag}' is not greater compared to last tag '{lastReleased.NotNull().Version}'.");

            var path = changelogFile.Path;

            var content = TextTasks.ReadAllLines(path).ToList();

            content.Insert(unreleasedNotes.StartIndex + 1, string.Empty);
            content.Insert(unreleasedNotes.EndIndex + 2, $"## [{tag}] / {DateTime.Now:yyyy-MM-dd}");

            UpdateVersionSummary(tag.ToString(), content, repository);

            content.Add(string.Empty);

            TextTasks.WriteAllLines(path, content);
        }
Example #2
0
        /// <summary>
        /// Finalizes the changelog by moving all entries from `[vNext]` to the version specified by release.
        /// <p>If <paramref name="repository"/> is specified a summary with all versions and links to list the changes directly on GitHub is appended to the end of the changelog.</p>
        /// </summary>
        /// <param name="changelogFile">The path to the changelog file.</param>
        /// <param name="tag">The version to finalize the changelog.</param>
        /// <param name="repository">The repository to create the version overview for.</param>
        /// <seealso cref="FinalizeChangelog(ChangeLog,NuGetVersion,GitRepository)"/>
        public static void FinalizeChangelog(string changelogFile, string tag, [CanBeNull] GitRepository repository = null)
        {
            Logger.Info($"Finalizing {PathConstruction.GetRelativePath(NukeBuild.RootDirectory, changelogFile)} for '{tag}'...");

            var content       = TextTasks.ReadAllLines(changelogFile).ToList();
            var sections      = GetReleaseSections(content).ToList();
            var firstSection  = sections.First();
            var secondSection = sections.Skip(1).FirstOrDefault();

            ControlFlow.Assert(firstSection.Caption.All(char.IsLetter), "Cannot find a draft section.");
            ControlFlow.Assert(sections.All(x => !x.Caption.EqualsOrdinalIgnoreCase(tag)), $"Tag '{tag}' already exists.");
            ControlFlow.Assert(firstSection.EndIndex > firstSection.StartIndex,
                               $"Draft section '{firstSection.Caption}' does not contain any information.");
            ControlFlow.Assert(secondSection == null || NuGetVersion.Parse(tag).CompareTo(NuGetVersion.Parse(secondSection.Caption)) > 0,
                               $"Tag '{tag}' is not greater compared to last tag '{secondSection?.Caption}'.");

            content.Insert(firstSection.StartIndex + 1, string.Empty);
            content.Insert(firstSection.StartIndex + 2, $"## [{tag}] / {DateTime.Now:yyyy-MM-dd}");

            UpdateVersionSummary(tag, content, repository);

            content.Add(string.Empty);

            TextTasks.WriteAllLines(changelogFile, content);
        }
        private static string GetRepositoryRelativePath([CanBeNull] string path, GitRepository repository)
        {
            if (path == null)
                return null;

            if (!Path.IsPathRooted(path))
                return path;

            ControlFlow.Assert(PathConstruction.IsDescendantPath(repository.LocalDirectory.NotNull("repository.LocalDirectory != null"), path),
                $"PathConstruction.IsDescendantPath({repository.LocalDirectory}, {path})");
            return PathConstruction.GetRelativePath(repository.LocalDirectory, path).Replace(oldChar: '\\', newChar: '/');
        }
Example #4
0
        private static string GetRepositoryRelativePath([CanBeNull] string path, GitRepository repository)
        {
            if (path == null)
            {
                return(null);
            }

            if (!Path.IsPathRooted(path))
            {
                return(path);
            }

            ControlFlow.Assert(PathConstruction.IsDescendantPath(repository.LocalDirectory.NotNull("repository.LocalDirectory != null"), path),
                               $"PathConstruction.IsDescendantPath({repository.LocalDirectory}, {path})");
            return(PathConstruction.GetRelativePath(repository.LocalDirectory, path));
        }
Example #5
0
        public static void CompressZip(string directory, string archiveFile, Predicate <FileInfo> filter, CompressionLevel compressionLevel)
        {
            FileSystemTasks.EnsureExistingParentDirectory(archiveFile);

            var files = GetFiles(directory, filter);

            using (var fileStream = File.Open(archiveFile, FileMode.CreateNew, FileAccess.ReadWrite))
                using (var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Create))
                {
                    // zipStream.SetLevel(1);

                    foreach (var file in files)
                    {
                        var relativePath = PathConstruction.GetRelativePath(directory, file);
                        var entryName    = ZipEntry.CleanName(relativePath);
                        zipArchive.CreateEntryFromFile(file, entryName, compressionLevel);
                    }
                }

            Logger.Log($"Compressed content of '{directory}' to '{Path.GetFileName(archiveFile)}'.");
        }
Example #6
0
        private static void CompressTar(string directory, string archiveFile, Predicate <FileInfo> filter, Func <Stream, Stream> outputStreamFactory)
        {
            FileSystemTasks.EnsureExistingParentDirectory(archiveFile);

            var files = GetFiles(directory, filter);

            using (var fileStream = File.Open(archiveFile, FileMode.CreateNew, FileAccess.ReadWrite))
                using (var outputStream = outputStreamFactory(fileStream))
                    using (var tarArchive = TarArchive.CreateOutputTarArchive(outputStream))
                    {
                        foreach (var file in files)
                        {
                            var entry        = TarEntry.CreateEntryFromFile(file);
                            var relativePath = PathConstruction.GetRelativePath(directory, file);
                            entry.Name = PathConstruction.NormalizePath(relativePath, separator: '/');

                            tarArchive.WriteEntry(entry, recurse: false);
                        }
                    }
            Logger.Log($"Compressed content of '{directory}' to '{Path.GetFileName(archiveFile)}'.");
        }
        private IEnumerable <ITaskItem> GetFiles(string packageId, string packageVersion)
        {
            var packageToolsPath = Path.Combine(NuGetPackageRoot, packageId, packageVersion, "tools");

            if (!Directory.Exists(packageToolsPath))
            {
                yield break;
            }

            foreach (var file in Directory.GetFiles(packageToolsPath, "*", SearchOption.AllDirectories))
            {
                var taskItem = new TaskItem(file);
                taskItem.SetMetadata("BuildAction", "None");
                taskItem.SetMetadata("PackagePath",
                                     Path.Combine("tools",
                                                  TargetFramework,
                                                  "any",
                                                  packageId,
                                                  PathConstruction.GetRelativePath(packageToolsPath, file)));
                yield return(taskItem);
            }
        }