Ejemplo n.º 1
0
        public void VersionIsLowerThanValue_Test(string versionStr, string valueStr)
        {
            var version = new NuGetVersion(versionStr);
            var value   = new NuGetVersion(valueStr);

            Assert.True(version.CompareTo(value) == -1);
        }
Ejemplo n.º 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 <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);
        }
        public int Compare(IPackageIdentity x, IPackageIdentity y)
        {
            NuGetVersion xVersion = new NuGetVersion(x.Version);
            NuGetVersion yVersion = new NuGetVersion(y.Version);

            return(xVersion.CompareTo(yVersion));
        }
Ejemplo n.º 4
0
        public void VersionIsEqualToValue_Test(string versionStr, string valueStr)
        {
            var version = new NuGetVersion(versionStr);
            var value   = new NuGetVersion(valueStr);

            Assert.True(version.CompareTo(value) == 0);
        }
Ejemplo n.º 5
0
 public static int Compare(string version)
 {
     if (!NuGetVersion.TryParse(version, out NuGetVersion result))
     {
         return(1);
     }
     return(CurrentVersion.CompareTo(result));
 }
Ejemplo n.º 6
0
        public static async Task <string> GetCurrentVersionOfPackageAsync(string packageId, string currentVersion)
        {
            try
            {
                NuGetVersion maxVersion = NuGetVersion.Parse(currentVersion);
                bool         updated    = false;

                foreach (SourceRepository repo in Repos)
                {
                    FindPackageByIdResource resource = await repo.GetResourceAsync <FindPackageByIdResource>();

                    if (resource == null)
                    {
                        continue;
                    }

                    try
                    {
                        IReadOnlyList <NuGetVersion> versions = (await resource.GetAllVersionsAsync(packageId, CancellationToken.None))?.ToList();

                        if (versions == null || versions.Count == 0)
                        {
                            continue;
                        }

                        NuGetVersion maxVer = versions.Max();
                        if (maxVer.CompareTo(maxVersion) > 0)
                        {
                            updated    = true;
                            maxVersion = maxVer;
                        }
                    }
                    catch (FatalProtocolException)
                    {
                    }
                }

                return(updated ? maxVersion.ToString() : null);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Mark public for testing
        /// </summary>
        public IList <string> GetPostBuildActionScripts()
        {
            List <string> scriptFilesGroupedAndSorted = new List <string>();
            List <string> scriptFolders = new List <string>();

            const string extensionEnvVarSuffix = "_EXTENSION_VERSION";

            // "/site/deployments/tools/PostDeploymentActions" (can override with %SCM_POST_DEPLOYMENT_ACTIONS_PATH%)
            // if %SCM_POST_DEPLOYMENT_ACTIONS_PATH% is set, we will support both absolute path or relative parth from "d:/home/site/repository"
            var customPostDeploymentPath = DeploymentSettings.GetValue(SettingsKeys.PostDeploymentActionsDirectory);
            var postDeploymentPath       = string.IsNullOrEmpty(customPostDeploymentPath) ? Path.Combine(Environment.DeploymentToolsPath, PostDeploymentActions) : Path.Combine(Environment.RepositoryPath, customPostDeploymentPath);

            if (FileSystemHelpers.DirectoryExists(postDeploymentPath))
            {
                scriptFolders.Add(postDeploymentPath);
            }

            // D:\Program Files (x86)\SiteExtensions
            string siteExtensionFolder = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86), "SiteExtensions");

            // Find all enviroment variable with format {package id}_EXTENSION_VERSION,
            // And find scripts from PostDeploymentActions" folder
            foreach (DictionaryEntry entry in System.Environment.GetEnvironmentVariables())
            {
                string       key = entry.Key.ToString();
                string       val = entry.Value.ToString();
                NuGetVersion ver = null;
                if (key.EndsWith(extensionEnvVarSuffix, StringComparison.OrdinalIgnoreCase) &&
                    (string.Equals("latest", val, StringComparison.OrdinalIgnoreCase) || NuGetVersion.TryParse(val, out ver)))      // either latest or a specific version
                {
                    string extensionName = key.Substring(0, key.Length - extensionEnvVarSuffix.Length);
                    if (ver != null)
                    {
                        // "D:\Program Files (x86)\SiteExtensions", "{ExtensionName}", "{version}", "PostDeploymentActions"
                        //  => D:\Program Files (x86)\SiteExtensions\{ExtensionName}\{version}\PostDeploymentActions
                        string scriptFolder = Path.Combine(siteExtensionFolder, extensionName, ver.ToNormalizedString(), PostDeploymentActions);
                        if (FileSystemHelpers.DirectoryExists(scriptFolder))
                        {
                            scriptFolders.Add(scriptFolder);
                        }
                    }
                    else
                    {
                        // Get the latest version
                        // "D:\Program Files (x86)\SiteExtensions", "{PackageName}"
                        //  => D:\Program Files (x86)\SiteExtensions\{PackageName}
                        string packageRoot = Path.Combine(siteExtensionFolder, extensionName);
                        if (FileSystemHelpers.DirectoryExists(packageRoot))
                        {
                            string[] allVersions = FileSystemHelpers.GetDirectories(packageRoot);   // expecting a list of version e.g D:\Program Files (x86)\SiteExtensions\{PackageName}\{version}
                            if (allVersions.Count() > 0)
                            {
                                // latest version comes first
                                Array.Sort(allVersions, (string v1, string v2) =>
                                {
                                    NuGetVersion ver1 = NuGetVersion.Parse(new DirectoryInfo(v1).Name);
                                    NuGetVersion ver2 = NuGetVersion.Parse(new DirectoryInfo(v2).Name);
                                    return(ver2.CompareTo(ver1));
                                });

                                // "D:\Program Files (x86)\SiteExtensions\{PackageName}\{version}", "PostDeploymentActions"
                                // => D:\Program Files (x86)\SiteExtensions\{PackageName}\{version}\PostDeploymentActions
                                string scriptFolder = Path.Combine(allVersions[0], PostDeploymentActions);
                                if (FileSystemHelpers.DirectoryExists(scriptFolder))
                                {
                                    scriptFolders.Add(scriptFolder);
                                }
                            }
                        }
                    }
                }
            }

            // Find all post action scripts and order file alphabetically for each folder
            foreach (var sf in scriptFolders)
            {
                var files = FileSystemHelpers.GetFiles(sf, "*")
                            .Where(f => f.EndsWith(".cmd", StringComparison.OrdinalIgnoreCase) ||
                                   f.EndsWith(".sh", StringComparison.OrdinalIgnoreCase) ||
                                   f.EndsWith(".bat", StringComparison.OrdinalIgnoreCase) ||
                                   f.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase)).ToList();

                files.Sort();
                scriptFilesGroupedAndSorted.AddRange(files);
            }

            return(scriptFilesGroupedAndSorted);
        }
Ejemplo n.º 8
0
 public int CompareTo(PackageVersion other)
 {
     return(NuGetVersion?.CompareTo(other?.NuGetVersion) ?? -1);
 }
 public static bool IsLessThanOrEqualTo(this NuGetVersion thisVersion, NuGetVersion otherVersion)
 {
     return(thisVersion.CompareTo(otherVersion) <= 0);
 }
 public static bool IsGreaterThan(this NuGetVersion thisVersion, NuGetVersion otherVersion)
 {
     return(thisVersion.CompareTo(otherVersion) > 0);
 }