Ejemplo n.º 1
0
        /// <summary>
        /// Validate that the serialized module metadata was updated.
        /// </summary>
        private void ValidateSerialization()
        {
            Version version = _metadataHelper.GetVersionBumpUsingSerialized();

            if (version != Version.PATCH)
            {
                throw new Exception("The JSON containing the serialized module metadata has not been re-serialized.");
            }

            var            outputModuleManifestPath   = _fileHelper.OutputModuleManifestPath;
            var            serializedCmdletsDirectory = _fileHelper.SerializedCmdletsDirectory;
            IList <string> nestedModules = null;

            using (PowerShell powershell = PowerShell.Create())
            {
                powershell.AddScript("Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process;");
                powershell.AddScript("(Test-ModuleManifest -Path " + outputModuleManifestPath + ").NestedModules");
                var cmdletResult = powershell.Invoke();
                nestedModules = cmdletResult.Select(c => c.ToString()).ToList();
            }

            foreach (var nestedModule in nestedModules)
            {
                var serializedCmdletName = nestedModule + ".dll.json";
                var serializedCmdletFile = Directory.GetFiles(serializedCmdletsDirectory, serializedCmdletName).FirstOrDefault();
                var file    = File.ReadAllLines(serializedCmdletFile);
                var pattern = nestedModule + @"(\s*),(\s*)Version(\s*)=(\s*)" + _localVersion;
                if (!file.Where(l => Regex.IsMatch(l, pattern)).Any())
                {
                    throw new Exception("The assembly version has not been updated in the serialized module metadata JSON file.");
                }
            }

            Console.WriteLine("Validated serialization of module metadata.");
        }
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());
        }