Ejemplo n.º 1
0
        /// <summary>
        /// Validate that the correct version bump was applied from the
        /// previous (gallery) module version to the module version found locally.
        /// </summary>
        private void ValidateVersionBump()
        {
            var moduleName = _fileHelper.ModuleName;

            // Don't validate a version bump for new module
            if (_isNewModule)
            {
                Console.WriteLine("Skipping version bump validation for " + moduleName + " since it is a new module.");
                return;
            }

            Version version = _metadataHelper.GetVersionBumpUsingGallery();

            if (string.Equals(moduleName, "Az.Accounts"))
            {
                var commonCodeVersion = _metadataHelper.GetVersionBumpForCommonCode();
                if (commonCodeVersion == Version.MAJOR)
                {
                    version = Version.MAJOR;
                }
                else if (commonCodeVersion == Version.MINOR && version == Version.PATCH)
                {
                    version = Version.MINOR;
                }
            }

            var splitVersion = _galleryVersion.Split('.').Select(v => int.Parse(v)).ToArray();

            // PATCH update for preview modules (0.x.x or x.x.x-preview)
            if (splitVersion[0] == 0 || _isPreview)
            {
                version = Version.PATCH;
            }

            if (version == Version.MAJOR)
            {
                splitVersion[0]++;
                splitVersion[1] = 0;
                splitVersion[2] = 0;
            }
            else if (version == Version.MINOR)
            {
                splitVersion[1]++;
                splitVersion[2] = 0;
            }
            else
            {
                splitVersion[2]++;
            }

            var tempVersion = string.Join(".", splitVersion);

            if (!string.Equals(_localVersion, tempVersion))
            {
                throw new Exception("Incorrect version bump. The local version is " + _localVersion + ", but should have been " + tempVersion);
            }

            Console.WriteLine("Validated correct version bump to version " + _localVersion);
        }
Ejemplo n.º 2
0
        /// <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, "AzureRM.Profile"))
            {
                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;
                }
            }

            // PATCH update for preview modules (0.x.x or x.x.x-preview)
            if (splitVersion[0] == 0 || _isPreview)
            {
                versionBump = Version.PATCH;
            }

            if (versionBump == Version.MAJOR)
            {
                splitVersion[0]++;
                splitVersion[1] = 0;
                splitVersion[2] = 0;
            }
            else if (versionBump == Version.MINOR)
            {
                splitVersion[1]++;
                splitVersion[2] = 0;
            }
            else
            {
                splitVersion[2]++;
            }

            return(string.Join(".", splitVersion));
        }
Ejemplo n.º 3
0
        /// <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());
        }