public void TestConstructor() { var v1 = new AzurePSVersion("11.0.20"); Assert.Equal(11, v1.Major); Assert.Equal(0, v1.Minor); Assert.Equal(20, v1.Patch); Assert.False(v1.IsPreview); Assert.Null(v1.Label); }
/// <summary> /// Under the same Major version, check if there exist preview version in gallery that has greater version. /// </summary> /// <returns>True if exist a version, false otherwise.</returns> private bool HasGreaterPreviewVersion(AzurePSVersion version, List <AzurePSVersion> galleryVersion) { foreach (var gaVersion in galleryVersion) { if (gaVersion.Major == version.Major && gaVersion >= version) { return(true); } } return(false); }
/// <summary> /// Get bumped version by type. /// </summary> /// <param name="version">The version before bump.</param> /// <param name="type">The bump type.</param> /// <returns>The version after bump.</returns> private AzurePSVersion GetBumpedVersionByType(AzurePSVersion version, Version type) { AzurePSVersion bumpedVersion; if (type == Version.MAJOR) { bumpedVersion = new AzurePSVersion(version.Major + 1, 0, 0, version.Label); } else if (type == Version.MINOR) { bumpedVersion = new AzurePSVersion(version.Major, version.Minor + 1, 0, version.Label); } else { bumpedVersion = new AzurePSVersion(version.Major, version.Minor, version.Patch + 1, version.Label); } return(bumpedVersion); }
/// <summary> /// Apply a version bump to a given version. /// </summary> /// <returns>The updated version after the bump has been applied.</returns> private string GetBumpedVersion() { var moduleName = _fileHelper.ModuleName; var splitVersion = _oldVersion.Split('.').Select(v => int.Parse(v)).ToArray(); var versionBump = _metadataHelper.GetVersionBumpUsingSerialized(); if (string.Equals(moduleName, "Az.Accounts")) { var commonCodeVersionBump = _metadataHelper.GetVersionBumpForCommonCode(); if (commonCodeVersionBump == Version.MAJOR) { throw new Exception("Breaking change detected in common code."); } else if (commonCodeVersionBump == Version.MINOR && versionBump == Version.PATCH) { versionBump = Version.MINOR; } // for https://github.com/Azure/azure-powershell/pull/12356 // Because of the wrong compare script in the link above, we need to avoid the minor bump when the version of Az.Accounts is 1.9.x // So we add a special judge for it when the version is 1.9.x and the expect bump type is minor, // we will change the type to patch so that it can work until 1.9.9.Once the version is greater or equal than 2.0.0 // this special judge will not works anymore. if (splitVersion[0] == 1 && splitVersion[1] == 9 && versionBump == Version.MINOR) { versionBump = Version.PATCH; } } // PATCH update for preview modules (x.x.x-preview) if (_isPreview) { versionBump = Version.PATCH; } // Breaking change is allowed when module version is less than 1.0.0. Downgrade bumped version to minor for this case. if (splitVersion[0] == 0 && versionBump == Version.MAJOR) { versionBump = Version.MINOR; } var bumpedVersion = GetBumpedVersionByType(new AzurePSVersion(_oldVersion), versionBump); List <AzurePSVersion> galleryVersion = GetGalleryVersion(); AzurePSVersion maxGalleryGAVersion = new AzurePSVersion("0.0.0"); foreach (var version in galleryVersion) { if (version.Major == bumpedVersion.Major && !version.IsPreview && version > maxGalleryGAVersion) { maxGalleryGAVersion = version; } } if (galleryVersion.Count == 0) { bumpedVersion = new AzurePSVersion(0, 1, 0); } else if (maxGalleryGAVersion >= bumpedVersion) { string errorMsg = $"The GA version of {moduleName} in gallery ({maxGalleryGAVersion}) is greater or equal to the bumped version({bumpedVersion})."; _logger.LogError(errorMsg); throw new Exception(errorMsg); } else if (HasGreaterPreviewVersion(bumpedVersion, galleryVersion)) { while (HasGreaterPreviewVersion(bumpedVersion, galleryVersion)) { bumpedVersion = GetBumpedVersionByType(bumpedVersion, Version.MINOR); } _logger.LogWarning("There existed greater preview version in the gallery."); } return(bumpedVersion.ToString()); }