Exemplo n.º 1
0
        private static int?CheckAwareness()
        {
            string GetCookieFile(string name, int version)
            => Constants.GlobalNukeDirectory / "telemetry-awareness" / $"v{version}" / name;

            // Check for calls from Nuke.GlobalTool and custom global tools
            if (SuppressErrors(() => NukeBuild.BuildProjectFile, logWarning: false) == null)
            {
                var cookieName = Assembly.GetEntryAssembly().NotNull().GetName().Name;
                var cookieFile = GetCookieFile(cookieName, CurrentVersion);
                if (!File.Exists(cookieFile))
                {
                    PrintDisclosure($"create awareness cookie for {cookieName.SingleQuote()}");
                    FileSystemTasks.Touch(cookieFile);
                }

                return(CurrentVersion);
            }

            var project  = ProjectModelTasks.ParseProject(NukeBuild.BuildProjectFile);
            var property = project.Properties.SingleOrDefault(x => x.Name.EqualsOrdinalIgnoreCase(VersionPropertyName));

            if (property?.EvaluatedValue != CurrentVersion.ToString())
            {
                if (NukeBuild.IsServerBuild)
                {
                    PrintDisclosure(action: null);
                    return(null);
                }

                PrintDisclosure($"set the {VersionPropertyName.SingleQuote()} property");
                project.SetProperty(VersionPropertyName, CurrentVersion.ToString());
                project.Save();
            }

            for (var version = CurrentVersion; version > 0; version--)
            {
                if (File.Exists(GetCookieFile("Nuke.GlobalTool", version)))
                {
                    return(version);
                }
            }

            return(NukeBuild.IsServerBuild ? CurrentVersion : null);
        }