示例#1
0
    /// <summary>
    /// Pre-Processing that must occur for majority of the targets to work.
    /// </summary>
    private void PreProcessing()
    {
        if (Configuration == null)
        {
            if (InvokedTargets.Contains(PublishProd))
            {
                Configuration = Configuration.Release;
            }
            else
            {
                Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
            }
        }


        Utility.ValidateGetVersionEnvVariable();

        // Loads the Solution specific configuration information for building.
        string json = File.ReadAllText(RootDirectory / "NukeSolutionBuild.Conf");

        CustomNukeSolutionConfig = JsonSerializer.Deserialize <CustomNukeSolutionConfig>(json, CustomNukeSolutionConfig.SerializerOptions());
        ControlFlow.Assert(CustomNukeSolutionConfig.CheckRootFolders(),
                           "The DeployProdRoot or DeployTestRoot in the NukeSolutionBuild.Conf do not contain valid entries.  Run SlugNuke --Target Setup to fix.");

        // Setup the GitProcessor
        _gitProcessor = new GitProcessor(RootDirectory);


        if (_gitProcessor.GitVersion == null)
        {
            Logger.Error("GitVersion not Loaded");
        }

        // Get current branch and ensure there are no uncommitted updates.  These methods will throw if anything is out of sorts.
        _gitProcessor.GetCurrentBranch();
        _gitProcessor.IsUncommittedChanges();
        _gitProcessor.IsBranchUpToDate();

        if (_gitProcessor.IsCurrentBranchMainBranch() && InvokedTargets.Contains(Publish))
        {
            string msg =
                @"The current branch is the main branch, yet you are running a Test Publish command.  This is unsupported as it will cause version issues in Git.  " +
                "Either create a branch off master to put the changes into (this is probably what you want) OR change Target command to PublishProd.";
            ControlFlow.Assert(1 == 0, msg);
        }
    }
示例#2
0
        /// <summary>
        /// Ensures there is a valid NukeSolutionBuild.Conf file and updates it if necessary OR creates it.
        /// </summary>
        /// <returns></returns>
        private async Task <bool> ValidateNukeSolutionBuild()
        {
            AbsolutePath nsbFile = RootDirectory / "nukeSolutionBuild.conf";

            CustomNukeSolutionConfig customNukeSolutionConfig;

            if (FileExists(nsbFile))
            {
                using (FileStream fs = File.OpenRead(nsbFile)) { customNukeSolutionConfig = await JsonSerializer.DeserializeAsync <CustomNukeSolutionConfig>(fs, CustomNukeSolutionConfig.SerializerOptions()); }
            }
            else
            {
                customNukeSolutionConfig = new CustomNukeSolutionConfig();
                customNukeSolutionConfig.DeployToVersionedFolder = true;
            }


            bool updateProjectAdd    = false;
            bool hasCopyDeployMethod = false;

            // Now go thru the projects and update the config
            foreach (VisualStudioProject project in Projects)
            {
                NukeConf.Project nukeConfProject = customNukeSolutionConfig.GetProjectByName(project.Name);
                if (nukeConfProject == null)
                {
                    updateProjectAdd = true;
                    nukeConfProject  = new NukeConf.Project()
                    {
                        Name = project.Name
                    };
                    nukeConfProject.Framework     = project.Framework;
                    nukeConfProject.IsTestProject = project.IsTestProject;

                    if (project.IsTestProject)
                    {
                        nukeConfProject.Deploy = CustomNukeDeployMethod.None;

                        // Also add the Required Nuget Coverage package
                        CoverletInstall(project);
                    }
                    else
                    {
                        nukeConfProject.Deploy = CustomNukeDeployMethod.Copy;
                    }

                    customNukeSolutionConfig.Projects.Add(nukeConfProject);
                }
                else
                {
                    // Check for updated values:
                    if (nukeConfProject.Framework != project.Framework)
                    {
                        nukeConfProject.Framework = project.Framework;
                    }

                    if (nukeConfProject.IsTestProject)
                    {
                        // Also add the Required Nuget Coverage package
                        CoverletInstall(project);
                    }

                    if (nukeConfProject.Deploy == CustomNukeDeployMethod.Copy)
                    {
                        hasCopyDeployMethod = true;
                    }
                }
            }


            // Ensure Deploy Roots have values if at least one of the projects has a deploy method of Copy
            if (hasCopyDeployMethod)
            {
                for (int i = 0; i < 2; i++)
                {
                    string        name;
                    Configuration config;

                    if (i == 0)
                    {
                        name   = "Production";
                        config = Configuration.Release;
                    }
                    else
                    {
                        name   = "Test";
                        config = Configuration.Debug;
                    }

                    if (!customNukeSolutionConfig.IsRootFolderSpecified(config))
                    {
                        Console.WriteLine("Enter the root deployment folder for {0} [{1}]", Color.Yellow, name, config);
                        string answer = Console.ReadLine();
                        if (i == 0)
                        {
                            customNukeSolutionConfig.DeployProdRoot = answer;
                        }
                        else
                        {
                            customNukeSolutionConfig.DeployTestRoot = answer;
                        }
                    }
                }
            }


            // We now always write the config file at the end of Setup.  This ensure we get any new properties.
            string json = JsonSerializer.Serialize <CustomNukeSolutionConfig>(customNukeSolutionConfig, CustomNukeSolutionConfig.SerializerOptions());

            File.WriteAllText(nsbFile, json);
            if (updateProjectAdd)
            {
                Logger.Warn("The file: {0} was updated.  One ore more projects were added.  Ensure they have the correct Deploy setting.", nsbFile);
            }

            return(true);
        }