示例#1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public GitBranchInfo(RecordBranchLatestCommit branchRecord, GitProcessor gitProcessor)
        {
            Name = branchRecord.branch;

            // Retrieve info about the latest commit on the branch
            if (branchRecord.commitHash != "->")
            {
                LatestCommitOnBranch = gitProcessor.GetCommitInfo(branchRecord.commitHash);
            }
            LatestSemVersionOnBranch = gitProcessor.FindLatestSemVersionOnBranch(Name);
        }
示例#2
0
        /// <summary>
        /// Initializes the GitProcessor and ensures Repo is in the proper state
        /// </summary>
        private void GitProcessorStartup()
        {
            // Setup the GitProcessor
            _gitProcessor = CISession.GitProcessor;

            if (_gitProcessor.IsCurrentBranchMainBranch() && CISession.PublishTarget != PublishTargetEnum.Production)
            {
                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);
            }
        }
示例#3
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);
        }
    }
        public void GetGitDescribeTag_Success(string output, bool throwsError, string tag, int commits, string hash)
        {
            RecordGitDescribeTag record = new RecordGitDescribeTag("", 0, "");

            // Test
            if (!throwsError)
            {
                Assert.DoesNotThrow(() => record = GitProcessor.GetGitDescribeTag(output), "A10:");
            }
            else
            {
                Assert.Throws <Exception>(() => GitProcessor.GetGitDescribeTag(output), "A20:");
                return;
            }

            // Validate
            Assert.AreEqual(tag, record.tag, "A30:");
            Assert.AreEqual(commits, record.commitsSince, "A40:");
            Assert.AreEqual(hash, record.commitHash, "A50:");
        }
        public void Test_ConvertVersionToSemVer(string version, bool shouldError, int major, int minor, int patch, string alpha)
        {
            if (!shouldError)
            {
                Assert.DoesNotThrow(() => GitProcessor.ConvertVersionToSemVersion(version), "A10:");
            }
            else
            {
                Assert.Throws <Exception>(() => GitProcessor.ConvertVersionToSemVersion(version), "A20:");
                return;
            }


            // Now check the versioning
            SemVersion semVersion = GitProcessor.ConvertVersionToSemVersion(version);

            Assert.AreEqual(major, semVersion.Major, "A100");
            Assert.AreEqual(minor, semVersion.Minor, "A120");
            Assert.AreEqual(patch, semVersion.Patch, "A130");
            Assert.AreEqual(alpha, semVersion.Prerelease, "A140");
        }
示例#6
0
 public SettingsViewModel(IConfiguration configuration, ILogger logger)
 {
     _gitProcessor = new GitProcessor(configuration, logger);
 }
        private void processTaskScript(String scriptProcessingLocation, Task task, TaskScript taskScript)
        {
            _log.Debug("Determining task type");

            IProcessor processor = null;

            switch (taskScript.Type)
            {
            case ScriptType.Git:
                processor = new GitProcessor(scriptProcessingLocation, taskScript);
                break;

            case ScriptType.CommandLine:
                processor = new CommandLineProcessor(scriptProcessingLocation, _nodeLocation, taskScript);
                break;

            case ScriptType.Node:
                processor = new NodeProcessor(scriptProcessingLocation, _nodeLocation, taskScript);
                break;

            case ScriptType.Grunt:
                processor = new GruntProcessor(scriptProcessingLocation, _nodeLocation, taskScript);
                break;

            case ScriptType.PhantomJS:
                processor = new PhantomJSProcessor(scriptProcessingLocation, _phantomJSLocation, taskScript);
                break;
            }

            String processResults = String.Empty;

            if (processor != null)
            {
                _log.Debug("Starting to process task");

                if (!Directory.Exists(scriptProcessingLocation))
                {
                    Directory.CreateDirectory(scriptProcessingLocation);
                }

                _log.Debug("Checking for any required node packages");

                foreach (String requiredPackage in processor.GetRequiredPackages())
                {
                    PackageCache packageCache = _packageCacheDataAccess.Get(task.Project.ID, requiredPackage);

                    _log.Debug("Package required: " + requiredPackage);

                    String packageCacheLocation  = _packageCacheLocation.TrimEnd(new char[] { '\\' }) + "\\" + task.Project.ID + "\\" + requiredPackage;
                    String targetPackageLocation = scriptProcessingLocation.TrimEnd(new char[] { '\\' }) + "\\node_modules\\" + requiredPackage;

                    _log.Debug("Package cache location: " + packageCacheLocation);
                    _log.Debug("target package location: " + targetPackageLocation);

                    if ((packageCache == null) ||
                        ((packageCache != null) && (!packageCache.Store)) ||
                        ((packageCache != null) && (packageCache.Store) && (!Directory.Exists(packageCacheLocation))))
                    {
                        _log.Debug("Cached package does not exist so importing");

                        processResults += CommandWindowHelper.ProcessCommand(scriptProcessingLocation, _nodeLocation, 5, "npm install " + requiredPackage) + Environment.NewLine;
                    }
                    else
                    {
                        _log.Debug("Cached package exists so attempting to pull into place");

                        Boolean packageImportSuccessful = IOHelper.CopyDirectory(packageCacheLocation, targetPackageLocation);

                        _log.Debug("Check if the cach package copy was successfull");

                        if (!packageImportSuccessful)
                        {
                            _log.Debug("Cache package copy failed so pulling " + requiredPackage + " from npm");

                            processResults += CommandWindowHelper.ProcessCommand(scriptProcessingLocation, _nodeLocation, 5, "npm install " + requiredPackage) + Environment.NewLine;
                        }
                    }

                    _log.Debug("Checking that we now have the target package");

                    if (Directory.Exists(targetPackageLocation))
                    {
                        _log.Debug("We do have the package so copy it into cache");

                        Boolean copySuccessful = true;

                        if ((packageCache == null) ||
                            ((packageCache != null) && (packageCache.Store) && (!Directory.Exists(packageCacheLocation))))
                        {
                            copySuccessful = IOHelper.CopyDirectory(targetPackageLocation, packageCacheLocation);
                        }

                        if ((packageCache == null) && (copySuccessful))
                        {
                            packageCache            = new PackageCache();
                            packageCache.ExternalId = System.Guid.NewGuid().ToString();
                            packageCache.Name       = requiredPackage;
                            packageCache.Version    = IOHelper.GetPackageVersion(targetPackageLocation);
                            packageCache.Store      = true;
                            packageCache.Project    = task.Project;

                            packageCache = _packageCacheDataAccess.Insert(packageCache);
                        }
                    }
                }

                processResults += processor.Process();
            }

            _taskScriptDataAccess.UpdateTaskScriptLog(taskScript.ID, processResults);
        }