private static string PublishPackage(VettingContext context)
        {
            var packagePath = context.ProjectPackageInfo.path;

            if (!context.ProjectPackageInfo.PackageType.NeedsLocalPublishing())
            {
                return(packagePath);
            }

            Profiler.BeginSample("PublishPackage");

            var    tempPath    = System.IO.Path.GetTempPath();
            string packageName = context.ProjectPackageInfo.Id.Replace("@", "-") + ".tgz";

            //Use upm-template-tools package-ci
            var packagesGenerated = PackageCIUtils.Pack(packagePath, tempPath);

            var publishPackagePath = Path.Combine(tempPath, "publish-" + context.ProjectPackageInfo.Id);
            var deleteOutput       = true;

            foreach (var packageTgzName in packagesGenerated)
            {
                Utilities.ExtractPackage(packageTgzName, tempPath, publishPackagePath, context.ProjectPackageInfo.name, deleteOutput);
                deleteOutput = false;
            }

            Profiler.EndSample();

            return(publishPackagePath);
        }
        internal static bool RunAssetStoreValidationSuite(string packageName, string packageVersion, string packagePath, string previousPackagePath = null)
        {
            if (string.IsNullOrEmpty(packageName))
            {
                throw new ArgumentNullException(packageName);
            }

            if (string.IsNullOrEmpty(packageVersion))
            {
                throw new ArgumentNullException(packageVersion);
            }

            if (string.IsNullOrEmpty(packagePath))
            {
                throw new ArgumentNullException(packageName);
            }

            var report = new ValidationSuiteReport(packageName + "@" + packageVersion, packageName, packageVersion, packagePath);

            try
            {
                var context   = VettingContext.CreateAssetStoreContext(packageName, packageVersion, packagePath, previousPackagePath);
                var testSuite = new ValidationSuite(SingleTestCompletedDelegate, AllTestsCompletedDelegate, context, report);
                testSuite.RunSync();
                return(testSuite.testSuiteState == TestState.Succeeded);
            }
            catch (Exception e)
            {
                report.OutputErrorReport(string.Format("\r\nTest Setup Error: \"{0}\"\r\n", e));
                return(false);
            }
        }
Example #3
0
        internal void Initialize(VettingContext context)
        {
            var packageInfo = context.ProjectPackageInfo;

            Write(
                string.Format("Validation Suite Results for package \"{0}\"\n", packageInfo.name) +
                string.Format(" - Path: {0}\n", packageInfo.path) +
                string.Format(" - Version: {0}\n", packageInfo.version) +
                string.Format(" - Type: {0}\n", context.PackageType) +
                string.Format(" - Context: {0}\n", context.ValidationType) +
                string.Format(" - Lifecycle: {0}\n", packageInfo.lifecycle) +
                string.Format(" - Test Time: {0}\n", DateTime.Now) +
                string.Format(" - Tested with {0} version: {1}\n", context.VSuiteInfo.name, context.VSuiteInfo.version)
                );

            if (context.ProjectPackageInfo.dependencies.Any())
            {
                Append("\nPACKAGE DEPENDENCIES:\n");
                Append("--------------------\n");
                foreach (var dependencies in context.ProjectPackageInfo.dependencies)
                {
                    Append(string.Format("    - {0}@{1}\n", dependencies.Key, dependencies.Value));
                }
            }

            Append(exceptionSectionPlaceholder);

            Append("\nVALIDATION RESULTS:\n");
            Append("------------------\n");
        }
        public static bool ValidatePackage(string packageName, string packageVersion, string[] packageIdsForPromotion)
        {
            if (string.IsNullOrEmpty(packageName))
            {
                throw new ArgumentNullException(packageName);
            }

            if (string.IsNullOrEmpty(packageVersion))
            {
                throw new ArgumentNullException(packageVersion);
            }

            var packageId   = Utilities.CreatePackageId(packageName, packageVersion);
            var packagePath = FindPackagePath(packageName);
            var report      = new ValidationSuiteReport(packageId, packageName, packageVersion, packagePath);

            if (string.IsNullOrEmpty(packagePath))
            {
                report.OutputErrorReport(string.Format("Unable to find package \"{0}\" on disk.", packageName));
                return(false);
            }

            // publish locally for embedded and local packages
            var context = VettingContext.CreatePackmanContext(packageId, ValidationType.Promotion);

            context.packageIdsForPromotion = packageIdsForPromotion;
            return(ValidatePackage(context, out report));
        }
        internal ValidationSuite(SingleTestCompletedDelegate singleTestCompletionDelegate,
                                 AllTestsCompletedDelegate allTestsCompletedDelegate,
                                 VettingContext context,
                                 ValidationSuiteReport report)
        {
            this.singleTestCompletionDelegate += singleTestCompletionDelegate;
            this.allTestsCompletedDelegate    += allTestsCompletedDelegate;
            this.context   = context;
            this.report    = report;
            testSuiteState = TestState.NotRun;

            BuildTestSuite();
        }
Example #6
0
        void PrintExceptions(VettingContext context)
        {
            string str = "";

            if (context.ValidationExceptionManager.HasExceptions)
            {
                str  = "\n\n***************************************\n";
                str += "PACKAGE CONTAINS VALIDATION EXCEPTIONS!\n";
                var issuesList = context.ValidationExceptionManager.CheckValidationExceptions(context.PublishPackageInfo.version);
                foreach (var issue in issuesList)
                {
                    str += "\n- Issue: " + issue + "\n";
                }
                str += "***************************************\n";
            }

            Replace(exceptionSectionPlaceholder, str);
        }
Example #7
0
        /// <summary>
        /// Contains project information that is relevant for Template testing. During testing, the used manifest path
        /// and package manager settings path will be defined by the existence of those files within the package's
        /// ProjectData~ folder
        /// </summary>
        /// <param name="context"></param>
        public ProjectInfo(VettingContext context)
        {
            string packedManifestPath =
                Path.Combine(context.PublishPackageInfo.path, "ProjectData~", "Packages", "manifest.json");
            string packmanSettingsPath = Path.Combine(context.PublishPackageInfo.path, "ProjectData~",
                                                      "ProjectSettings", "PackageManagerSettings.asset");

            ManifestPath = File.Exists(packedManifestPath)
                ? packedManifestPath
                : Path.GetFullPath("Packages/manifest.json");

            PackageManagerSettingsPath = File.Exists(packmanSettingsPath)
                ? packmanSettingsPath
                : Path.GetFullPath("ProjectSettings/PackageManagerSettings.asset");

            SetProjectManifestKeys();
            SetPackageManagerSettings();
        }
        public static VettingContext CreateAssetStoreContext(string packageName, string packageVersion, string packagePath, string previousPackagePath)
        {
            VettingContext context = new VettingContext();

            context.ProjectPackageInfo = new ManifestData()
            {
                path = packagePath, name = packageName, version = packageVersion
            };
            context.PublishPackageInfo = new ManifestData()
            {
                path = packagePath, name = packageName, version = packageVersion
            };
            context.PreviousPackageInfo = string.IsNullOrEmpty(previousPackagePath) ? null : new ManifestData()
            {
                path = previousPackagePath, name = packageName, version = "Previous"
            };
            context.ValidationType = ValidationType.AssetStore;
            return(context);
        }
        internal static void ValidateEmbeddedPackages(ValidationType validationType)
        {
            var packageIdList = new List <string>();
            var directories   = Directory.GetDirectories("Packages/", "*", SearchOption.TopDirectoryOnly);

            foreach (var directory in directories)
            {
                ActivityLogger.Log("Starting package validation for " + directory);
                packageIdList.Add(VettingContext.GetManifest(directory).Id);
            }

            if (packageIdList.Any())
            {
                var success = ValidatePackages(packageIdList, validationType);
                ActivityLogger.Log("Package validation done and batchmode is set. Shutting down Editor");
                EditorApplication.Exit(success ? 0 : 1);
            }
            else
            {
                EditorApplication.Exit(1);
            }
        }
        public static bool ValidatePackage(VettingContext context, out ValidationSuiteReport report)
        {
            Profiler.BeginSample("ValidatePackage");

            report = new ValidationSuiteReport(context.ProjectPackageInfo.Id, context.ProjectPackageInfo.name, context.ProjectPackageInfo.version, context.ProjectPackageInfo.path);

            try
            {
                // publish locally for embedded and local packages
                var testSuite = new ValidationSuite(SingleTestCompletedDelegate, AllTestsCompletedDelegate, context, report);

                report.Initialize(testSuite.context);
                testSuite.RunSync();
                Profiler.EndSample();
                return(testSuite.testSuiteState == TestState.Succeeded);
            }
            catch (Exception e)
            {
                report.OutputErrorReport(string.Format("Test Setup Error: \"{0}\"\r\n", e));
                Profiler.EndSample();
                return(false);
            }
        }
        public static VettingContext CreatePackmanContext(string packageId, ValidationType validationType)
        {
            Profiler.BeginSample("CreatePackmanContext");
            ActivityLogger.Log("Starting Packman Context Creation");

            VettingContext context      = new VettingContext();
            var            packageParts = packageId.Split('@');
            var            packageList  = Utilities.UpmListOffline();

            ActivityLogger.Log("Looking for package {0} in project", packageParts[0]);
            var packageInfo = packageList.SingleOrDefault(p => p.name == packageParts[0] && p.version == packageParts[1]);

            if (packageInfo == null)
            {
                throw new ArgumentException("Package Id " + packageId + " is not part of this project.");
            }

#if UNITY_2019_1_OR_NEWER
            context.IsCore = packageInfo.source == PackageSource.BuiltIn && packageInfo.type != "module";
#else
            context.IsCore = false; // there are no core packages before 2019.1
#endif

            context.ValidationType     = validationType;
            context.ProjectPackageInfo = GetManifest(packageInfo.resolvedPath);
            context.PackageType        = context.ProjectPackageInfo.PackageType;

            if (context.ValidationType != ValidationType.VerifiedSet)
            {
                ActivityLogger.Log($"Checking if package {packageInfo.name} has been promoted to production");
                context.PackageExistsOnProduction = Utilities.PackageExistsOnProduction(packageInfo.name);
                ActivityLogger.Log($"Package {packageInfo.name} {(context.PackageExistsOnProduction ? "is" : "is not")} in production");

                ActivityLogger.Log($"Checking if package {packageInfo.packageId} has been promoted to production");
                context.PackageVersionExistsOnProduction = Utilities.PackageExistsOnProduction(packageInfo.packageId);
                ActivityLogger.Log($"Package {packageInfo.packageId} {(context.PackageExistsOnProduction ? "is" : "is not")} in production");
            }

            if (context.ValidationType == ValidationType.LocalDevelopment || context.ValidationType == ValidationType.LocalDevelopmentInternal)
            {
                var publishPackagePath = PublishPackage(context);
                context.PublishPackageInfo = GetManifest(publishPackagePath);
            }
            else
            {
                context.PublishPackageInfo = GetManifest(packageInfo.resolvedPath);
            }

            context.ProjectInfo = new ProjectInfo(context);

            Profiler.BeginSample("RelatedPackages");
            foreach (var relatedPackage in context.PublishPackageInfo.relatedPackages)
            {
                // Check to see if the package is available locally
                // We are only focusing on local packages to avoid validation suite failures in CI
                // when the situation arises where network connection is impaired
                ActivityLogger.Log("Looking for related package {0} in the project", relatedPackage.Key);
                var foundRelatedPackage = Utilities.UpmListOffline().Where(p => p.name.Equals(relatedPackage.Key));
                var relatedPackageInfo  = foundRelatedPackage.ToList();
                if (!relatedPackageInfo.Any())
                {
                    ActivityLogger.Log(String.Format("Cannot find the relatedPackage {0} ", relatedPackage.Key));
                    continue;
                }
                context.relatedPackages.Add(new RelatedPackage(relatedPackage.Key, relatedPackage.Value,
                                                               relatedPackageInfo.First().resolvedPath));
            }
            Profiler.EndSample();

            // No need to compare against the previous version of the package if we're testing out the verified set.
            if (context.ValidationType != ValidationType.VerifiedSet)
            {
                ActivityLogger.Log("Looking for previous package version");

                // List out available versions for a package
                var foundPackages = Utilities.UpmSearch(context.ProjectPackageInfo.name);

                // If it exists, get the last one from that list.
                if (foundPackages != null && foundPackages.Length > 0)
                {
                    // Get the last released version of the package
                    var previousPackagePath = GetPreviousReleasedPackage(context.ProjectPackageInfo, foundPackages[0]);
                    if (!string.IsNullOrEmpty(previousPackagePath))
                    {
                        context.PreviousPackageInfo = GetManifest(previousPackagePath);
                        context.DownloadAssembliesForPreviousVersion();
                    }

                    // Fill the versions for later use
                    context.AllVersions = foundPackages[0].versions.all;
                }
            }
            else
            {
                context.PreviousPackageInfo = null;
            }

            context.VSuiteInfo = GetPackageValidationSuiteInfo(packageList);

            // Get exception Data, if any was added to the package.
            context.ValidationExceptionManager = new ValidationExceptionManager(context.PublishPackageInfo.path);

            Profiler.EndSample();

            return(context);
        }
 internal void Initialize(VettingContext context)
 {
     TextReport?.Initialize(context);
 }
 public static bool ValidatePackage(VettingContext context, ValidationType validationType, out ValidationSuiteReport report) => ValidatePackage(context, out report);