示例#1
0
    public void PrepareRelease_JsonOutputWhenUpdatingReleaseBranch()
    {
        // create and configure repository
        this.InitializeSourceControl();

        // create version.json
        var versionOptions = new VersionOptions()
        {
            Version = SemanticVersion.Parse("1.0"),
            Release = new ReleaseOptions()
            {
                BranchName       = "v{version}",
                VersionIncrement = ReleaseVersionIncrement.Minor
            }
        };

        this.WriteVersionFile(versionOptions);
        var branchName = "v1.0";

        // switch to release branch
        Commands.Checkout(this.LibGit2Repository, this.LibGit2Repository.CreateBranch(branchName));

        // run release preparation
        var stdout         = new StringWriter();
        var releaseManager = new ReleaseManager(stdout);

        releaseManager.PrepareRelease(this.RepoPath, outputMode: ReleaseManager.ReleaseManagerOutputMode.Json);


        // Expected output:
        // {
        //     "CurrentBranch" : {
        //         "Name" : "<NAME>",
        //         "Commit" : "<COMMIT>",
        //         "Version" : "<VERSION>",
        //     },
        //     "NewBranch" : null
        // }

        var jsonOutput = JObject.Parse(stdout.ToString());

        // check "CurrentBranch"  output
        {
            var expectedCommitId = this.LibGit2Repository.Branches[branchName].Tip.Sha;
            var expectedVersion  = this.GetVersionOptions(committish: this.LibGit2Repository.Branches[branchName].Tip.Sha).Version.ToString();

            var currentBranchOutput = jsonOutput.Property("CurrentBranch")?.Value as JObject;
            Assert.NotNull(currentBranchOutput);

            Assert.Equal(branchName, currentBranchOutput.GetValue("Name")?.ToString());
            Assert.Equal(expectedCommitId, currentBranchOutput.GetValue("Commit")?.ToString());
            Assert.Equal(expectedVersion, currentBranchOutput.GetValue("Version")?.ToString());
        }
        // Check "NewBranch" output
        {
            // no new branch was created, so "NewBranch" should be null
            var newBranchOutput = jsonOutput.Property("NewBranch")?.Value as JObject;
            Assert.Null(newBranchOutput);
        }
    }
示例#2
0
        private Tuple <Mock <IReleasesClient>, IReleaseManager> GetReleaseManager()
        {
            var releasesClient = new Mock <IReleasesClient>();
            var gitHubRepoInfo = new GitHubRepoInfo("CreateMask", "Devoney", "Username", "Password");
            var releaseManager = new ReleaseManager(releasesClient.Object, gitHubRepoInfo);

            return(new Tuple <Mock <IReleasesClient>, IReleaseManager>(releasesClient, releaseManager));
        }
示例#3
0
 public SampleDataFixture()
 {
     Projects     = JsonSerializer.Deserialize <HashSet <Project> >(File.ReadAllText(@"..\..\..\Json\Projects.json")) !;
     Releases     = JsonSerializer.Deserialize <HashSet <Release> >(File.ReadAllText(@"..\..\..\Json\Releases.json")) !;
     Environments = JsonSerializer.Deserialize <HashSet <Environ> >(File.ReadAllText(@"..\..\..\Json\Environments.json")) !;
     Deployments  = JsonSerializer.Deserialize <HashSet <Deployment> >(File.ReadAllText(@"..\..\..\Json\Deployments.json")) !;
     Manager      = new ReleaseManager(Projects, Releases, Environments, Deployments);
 }
    public void PrepareRelease_ReleaseBranch(string initialVersion, string releaseOptionsBranchName, string releaseUnstableTag, string releaseBranchName, string resultingVersion)
    {
        releaseOptionsBranchName = releaseOptionsBranchName ?? new ReleaseOptions().BranchNameOrDefault;

        // create and configure repository
        this.InitializeSourceControl();
        this.Repo.Config.Set("user.name", this.Signer.Name, ConfigurationLevel.Local);
        this.Repo.Config.Set("user.email", this.Signer.Email, ConfigurationLevel.Local);

        var initialVersionOptions = new VersionOptions()
        {
            Version = SemanticVersion.Parse(initialVersion),
            Release = new ReleaseOptions()
            {
                BranchName = releaseOptionsBranchName
            }
        };

        var expectedVersionOptions = new VersionOptions()
        {
            Version = SemanticVersion.Parse(resultingVersion),
            Release = new ReleaseOptions()
            {
                BranchName = releaseOptionsBranchName
            }
        };

        // create version.json
        this.WriteVersionFile(initialVersionOptions);

        // switch to release branch
        var branchName = releaseBranchName;

        Commands.Checkout(this.Repo, this.Repo.CreateBranch(branchName));

        var tipBeforePrepareRelease = this.Repo.Head.Tip;

        // run PrepareRelease
        var releaseManager = new ReleaseManager();

        releaseManager.PrepareRelease(this.RepoPath, releaseUnstableTag);

        // Check if a commit was created
        {
            var updateVersionCommit = this.Repo.Head.Tip;
            Assert.NotEqual(tipBeforePrepareRelease.Id, updateVersionCommit.Id);
            Assert.Single(updateVersionCommit.Parents);
            Assert.Equal(updateVersionCommit.Parents.Single().Id, tipBeforePrepareRelease.Id);
        }

        // check version on release branch
        {
            var actualVersionOptions = VersionFile.GetVersion(this.Repo.Branches[branchName].Tip);
            Assert.Equal(expectedVersionOptions, actualVersionOptions);
        }
    }
示例#5
0
        private static void GetEnvironnements(ReleaseManager releaseManager)
        {
            IEnumerable <(string Name, int Id)> environments = releaseManager.GetReleaseDefinitionEnvironements(project, release);

            foreach (var(Name, Id) in environments)
            {
                Console.WriteLine($"Name: {Name}");
                Console.WriteLine($"\tId: {Id}");
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            LoadConfiguration();

            ReleaseManager releaseManager = new ReleaseManager(organizationUri, pat);

            var app = new CommandLineApplication();

            // template commands
            app.Command("template", templateCmd =>
            {
                templateCmd.Command("list", listCmd =>
                {
                    // list template
                    listCmd.OnExecute(() =>
                    {
                        Console.WriteLine(JsonConvert.SerializeObject(releaseManager.GetEnvironmentTemplates(project), Formatting.Indented));
                    });
                });

                templateCmd.Command("show", showCmd =>
                {
                    CommandOption id = showCmd.Option("--id", "id of the template", CommandOptionType.SingleValue).IsRequired();
                    showCmd.OnExecute(() =>
                    {
                        Console.WriteLine(JsonConvert.SerializeObject(releaseManager.GetEnvironmentTemplate(project, Guid.Parse(id.Value())), Formatting.Indented));
                    });
                });
            });

            // environment commands
            app.Command("environment", environmentCmd =>
            {
                // list environments
                environmentCmd.OnExecute(() =>
                {
                    GetEnvironnements(releaseManager);
                });

                environmentCmd.Command("create", createCmd =>
                {
                    CommandOption variables    = createCmd.Option("--variables", "set values for template variables in json format ie {'variablename':'variablevalue'}", CommandOptionType.SingleValue);
                    CommandArgument templateId = createCmd.Argument("templateId", "Id of the template").IsRequired();
                    createCmd.OnExecute(() =>
                    {
                        JObject jsonVariables = null;
                        jsonVariables         = variables.HasValue() ? JsonConvert.DeserializeObject(variables.Value()) as JObject : null;
                        releaseManager.CreateEnvironment(project, release, Guid.Parse(templateId.Value), jsonVariables);
                    });
                });
            });

            app.Execute(args);
        }
    public async void List_releases_that_needs_updates()
    {
        var gitHubClient = ClientBuilder.Build();

        var releaseNotesBuilder = new ReleaseManager(gitHubClient, "Particular");
        var result = await releaseNotesBuilder.GetReleasesInNeedOfUpdates();

        Debug.WriteLine("{0} releases found that needs updating", result.Count());
        foreach (var releaseName in result)
        {
            Debug.WriteLine(releaseName);
        }
    }
示例#8
0
    public void PrepareRelease_TextOutput()
    {
        // create and configure repository
        this.InitializeSourceControl();

        // create version.json
        var versionOptions = new VersionOptions()
        {
            Version = SemanticVersion.Parse("1.0")
        };

        this.WriteVersionFile(versionOptions);

        var stdout         = new StringWriter();
        var releaseManager = new ReleaseManager(stdout);

        releaseManager.PrepareRelease(this.RepoPath);

        // by default, text output mode should be used => trying to parse it as JSON should fail
        Assert.ThrowsAny <JsonException>(() => JsonConvert.DeserializeObject(stdout.ToString()));
    }
示例#9
0
    public void PrepareRelease_ResetsVersionHeightOffset()
    {
        // create and configure repository
        this.InitializeSourceControl();

        var initialVersionOptions = new VersionOptions()
        {
            Version             = SemanticVersion.Parse("1.0-beta"),
            VersionHeightOffset = 5,
        };

        var expectedReleaseVersionOptions = new VersionOptions()
        {
            Version             = SemanticVersion.Parse("1.0"),
            VersionHeightOffset = 5,
        };

        var expectedMainVersionOptions = new VersionOptions()
        {
            Version = SemanticVersion.Parse("1.1-alpha"),
        };

        // create version.json
        this.WriteVersionFile(initialVersionOptions);

        var tipBeforePrepareRelease = this.LibGit2Repository.Head.Tip;

        var releaseManager = new ReleaseManager();

        releaseManager.PrepareRelease(this.RepoPath);

        this.SetContextToHead();
        var newVersion = this.Context.VersionFile.GetVersion();

        Assert.Equal(expectedMainVersionOptions, newVersion);

        VersionOptions releaseVersion = this.GetVersionOptions(committish: this.LibGit2Repository.Branches["v1.0"].Tip.Sha);

        Assert.Equal(expectedReleaseVersionOptions, releaseVersion);
    }
    public void PrepareRelease_Master(
        // data for initial setup (version and release options configured in version.json)
        string initialVersion,
        string releaseOptionsBranchName,
        ReleaseVersionIncrement?releaseOptionsVersionIncrement,
        string releaseOptionsFirstUnstableTag,
        // arguments passed to PrepareRelease()
        string releaseUnstableTag,
        string nextVersion,
        ReleaseVersionIncrement?parameterVersionIncrement,
        // expected versions and branch name after running PrepareRelease()
        string expectedBranchName,
        string resultingReleaseVersion,
        string resultingMainVersion)
    {
        // create and configure repository
        this.InitializeSourceControl();
        this.Repo.Config.Set("user.name", this.Signer.Name, ConfigurationLevel.Local);
        this.Repo.Config.Set("user.email", this.Signer.Email, ConfigurationLevel.Local);

        // create version.json
        var initialVersionOptions = new VersionOptions()
        {
            Version = SemanticVersion.Parse(initialVersion),
            Release = new ReleaseOptions()
            {
                VersionIncrement = releaseOptionsVersionIncrement,
                BranchName       = releaseOptionsBranchName,
                FirstUnstableTag = releaseOptionsFirstUnstableTag
            }
        };

        this.WriteVersionFile(initialVersionOptions);

        var expectedVersionOptionsReleaseBranch = new VersionOptions()
        {
            Version = SemanticVersion.Parse(resultingReleaseVersion),
            Release = new ReleaseOptions()
            {
                VersionIncrement = releaseOptionsVersionIncrement,
                BranchName       = releaseOptionsBranchName,
                FirstUnstableTag = releaseOptionsFirstUnstableTag
            }
        };

        var expectedVersionOptionsCurrentBrach = new VersionOptions()
        {
            Version = SemanticVersion.Parse(resultingMainVersion),
            Release = new ReleaseOptions()
            {
                VersionIncrement = releaseOptionsVersionIncrement,
                BranchName       = releaseOptionsBranchName,
                FirstUnstableTag = releaseOptionsFirstUnstableTag
            }
        };

        var initialBranchName       = this.Repo.Head.FriendlyName;
        var tipBeforePrepareRelease = this.Repo.Head.Tip;

        // prepare release
        var releaseManager = new ReleaseManager();

        releaseManager.PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion == null ? null : Version.Parse(nextVersion)), parameterVersionIncrement);

        // check if a branch was created
        Assert.Contains(this.Repo.Branches, branch => branch.FriendlyName == expectedBranchName);

        // PrepareRelease should switch back to the initial branch
        Assert.Equal(initialBranchName, this.Repo.Head.FriendlyName);

        // check if release branch contains a new commit
        // parent of new commit must be the commit before preparing the release
        var releaseBranch = this.Repo.Branches[expectedBranchName];

        {
            // If the original branch had no -prerelease tag, the release branch has no commit to author.
            if (string.IsNullOrEmpty(initialVersionOptions.Version.Prerelease))
            {
                Assert.Equal(releaseBranch.Tip.Id, tipBeforePrepareRelease.Id);
            }
            else
            {
                Assert.NotEqual(releaseBranch.Tip.Id, tipBeforePrepareRelease.Id);
                Assert.Equal(releaseBranch.Tip.Parents.Single().Id, tipBeforePrepareRelease.Id);
            }
        }

        if (string.IsNullOrEmpty(initialVersionOptions.Version.Prerelease))
        {
            // Verify that one commit was authored.
            var incrementCommit = this.Repo.Head.Tip;
            Assert.Single(incrementCommit.Parents);
            Assert.Equal(tipBeforePrepareRelease.Id, incrementCommit.Parents.Single().Id);
        }
        else
        {
            // check if current branch contains new commits
            // - one commit that updates the version (parent must be the commit before preparing the release)
            // - one commit merging the release branch back to master and resolving the conflict
            var mergeCommit = this.Repo.Head.Tip;
            Assert.Equal(2, mergeCommit.Parents.Count());
            Assert.Equal(releaseBranch.Tip.Id, mergeCommit.Parents.Skip(1).First().Id);

            var updateVersionCommit = mergeCommit.Parents.First();
            Assert.Single(updateVersionCommit.Parents);
            Assert.Equal(tipBeforePrepareRelease.Id, updateVersionCommit.Parents.First().Id);
        }

        // check version on release branch
        {
            var releaseBranchVersion = VersionFile.GetVersion(releaseBranch.Tip);
            Assert.Equal(expectedVersionOptionsReleaseBranch, releaseBranchVersion);
        }

        // check version on master branch
        {
            var currentBranchVersion = VersionFile.GetVersion(this.Repo.Head.Tip);
            Assert.Equal(expectedVersionOptionsCurrentBrach, currentBranchVersion);
        }
    }
 public ServiceInsightInstaller(ProcessRunner processRunner, ReleaseManager releaseManager, IEventAggregator eventAggregator)
 {
     this.eventAggregator = eventAggregator;
     this.processRunner   = processRunner;
     this.releaseManager  = releaseManager;
 }
示例#12
0
        private static ExitCodes OnPrepareReleaseCommand(string projectPath, string prereleaseTag, string nextVersion, string versionIncrement, string format)
        {
            // validate project path property
            string searchPath = GetSpecifiedOrCurrentDirectoryPath(projectPath);

            if (!Directory.Exists(searchPath))
            {
                Console.Error.WriteLine($"\"{searchPath}\" is not an existing directory.");
                return(ExitCodes.NoGitRepo);
            }

            // nextVersion and versionIncrement parameters cannot be combined
            if (!string.IsNullOrEmpty(nextVersion) && !string.IsNullOrEmpty(versionIncrement))
            {
                Console.Error.WriteLine("Options 'nextVersion' and 'versionIncrement' cannot be used at the same time.");
                return(ExitCodes.InvalidParameters);
            }

            // parse versionIncrement if parameter was specified
            VersionOptions.ReleaseVersionIncrement?versionIncrementParsed = default;
            if (!string.IsNullOrEmpty(versionIncrement))
            {
                if (!Enum.TryParse <VersionOptions.ReleaseVersionIncrement>(versionIncrement, true, out var parsed))
                {
                    Console.Error.WriteLine($"\"{versionIncrement}\" is not a valid version increment");
                    return(ExitCodes.InvalidVersionIncrement);
                }
                versionIncrementParsed = parsed;
            }

            // parse nextVersion if parameter was specified
            Version nextVersionParsed = default;

            if (!string.IsNullOrEmpty(nextVersion))
            {
                if (!Version.TryParse(nextVersion, out nextVersionParsed))
                {
                    Console.Error.WriteLine($"\"{nextVersion}\" is not a valid version spec.");
                    return(ExitCodes.InvalidVersionSpec);
                }
            }

            // parse format
            if (string.IsNullOrEmpty(format))
            {
                format = DefaultOutputFormat;
            }
            if (!Enum.TryParse(format, true, out ReleaseManager.ReleaseManagerOutputMode outputMode))
            {
                Console.Error.WriteLine($"Unsupported format: {format}");
                return(ExitCodes.UnsupportedFormat);
            }

            // run prepare-release
            try
            {
                var releaseManager = new ReleaseManager(Console.Out, Console.Error);
                releaseManager.PrepareRelease(searchPath, prereleaseTag, nextVersionParsed, versionIncrementParsed, outputMode);
                return(ExitCodes.OK);
            }
            catch (ReleaseManager.ReleasePreparationException ex)
            {
                // map error codes
                switch (ex.Error)
                {
                case ReleaseManager.ReleasePreparationError.NoGitRepo:
                    return(ExitCodes.NoGitRepo);

                case ReleaseManager.ReleasePreparationError.UncommittedChanges:
                    return(ExitCodes.UncommittedChanges);

                case ReleaseManager.ReleasePreparationError.InvalidBranchNameSetting:
                    return(ExitCodes.InvalidBranchNameSetting);

                case ReleaseManager.ReleasePreparationError.NoVersionFile:
                    return(ExitCodes.NoVersionJsonFound);

                case ReleaseManager.ReleasePreparationError.VersionDecrement:
                    return(ExitCodes.InvalidVersionSpec);

                case ReleaseManager.ReleasePreparationError.BranchAlreadyExists:
                    return(ExitCodes.BranchAlreadyExists);

                case ReleaseManager.ReleasePreparationError.UserNotConfigured:
                    return(ExitCodes.UserNotConfigured);

                case ReleaseManager.ReleasePreparationError.DetachedHead:
                    return(ExitCodes.DetachedHead);

                case ReleaseManager.ReleasePreparationError.InvalidVersionIncrementSetting:
                    return(ExitCodes.InvalidVersionIncrementSetting);

                default:
                    Report.Fail($"{nameof(ReleaseManager.ReleasePreparationError)}: {ex.Error}");
                    return((ExitCodes)(-1));
                }
            }
        }
示例#13
0
    public void PrepareRelease_JsonOutput()
    {
        // create and configure repository
        this.InitializeSourceControl();

        // create version.json
        var versionOptions = new VersionOptions()
        {
            Version = SemanticVersion.Parse("1.0"),
            Release = new ReleaseOptions()
            {
                BranchName       = "v{version}",
                VersionIncrement = ReleaseVersionIncrement.Minor
            }
        };

        this.WriteVersionFile(versionOptions);

        var currentBranchName = this.LibGit2Repository.Head.FriendlyName;
        var releaseBranchName = "v1.0";

        // run release preparation
        var stdout         = new StringWriter();
        var releaseManager = new ReleaseManager(stdout);

        releaseManager.PrepareRelease(this.RepoPath, outputMode: ReleaseManager.ReleaseManagerOutputMode.Json);


        // Expected output:
        // {
        //     "CurrentBranch" : {
        //         "Name" : "<NAME-OF-CURRENT-BRANCH>",
        //         "Commit" : "<HEAD-COMMIT-OF-CURRENT-BRANCH>",
        //         "Version" : "<UPDATED-VERSION-ON-CURRENT-BRANCH>",
        //     },
        //     "NewBranch" : {
        //         "Name" : "<NAME-OF-CREATED-BRANCH>",
        //         "Commit" : "<HEAD-COMMIT-OF-CREATED-BRANCH>",
        //         "Version" : "<VERSION-ON-CREATED-BRANCH>",
        //     }
        // }

        var jsonOutput = JObject.Parse(stdout.ToString());

        // check "CurrentBranch" output
        {
            var expectedCommitId = this.LibGit2Repository.Branches[currentBranchName].Tip.Sha;
            var expectedVersion  = this.GetVersionOptions(committish: this.LibGit2Repository.Branches[currentBranchName].Tip.Sha).Version.ToString();

            var currentBranchOutput = jsonOutput.Property("CurrentBranch")?.Value as JObject;
            Assert.NotNull(currentBranchOutput);

            Assert.Equal(currentBranchName, currentBranchOutput.GetValue("Name")?.ToString());
            Assert.Equal(expectedCommitId, currentBranchOutput.GetValue("Commit")?.ToString());
            Assert.Equal(expectedVersion, currentBranchOutput.GetValue("Version")?.ToString());
        }

        // Check "NewBranch" output
        {
            var expectedCommitId = this.LibGit2Repository.Branches[releaseBranchName].Tip.Sha;
            var expectedVersion  = this.GetVersionOptions(committish: this.LibGit2Repository.Branches[releaseBranchName].Tip.Sha).Version.ToString();

            var newBranchOutput = jsonOutput.Property("NewBranch")?.Value as JObject;
            Assert.NotNull(newBranchOutput);

            Assert.Equal(releaseBranchName, newBranchOutput.GetValue("Name")?.ToString());
            Assert.Equal(expectedCommitId, newBranchOutput.GetValue("Commit")?.ToString());
            Assert.Equal(expectedVersion, newBranchOutput.GetValue("Version")?.ToString());
        }
    }
示例#14
0
        private static ExitCodes OnPrepareReleaseCommand(string projectPath, string prereleaseTag, string nextVersion)
        {
            // validate project path property
            string searchPath = GetSpecifiedOrCurrentDirectoryPath(projectPath);

            if (!Directory.Exists(searchPath))
            {
                Console.Error.WriteLine($"\"{searchPath}\" is not an existing directory.");
                return(ExitCodes.NoGitRepo);
            }

            // parse nextVersion if parameter was specified
            SemanticVersion nextVersionParsed = default;

            if (!string.IsNullOrEmpty(nextVersion))
            {
                if (!SemanticVersion.TryParse(nextVersion, out nextVersionParsed))
                {
                    Console.Error.WriteLine($"\"{nextVersion}\" is not a semver-compliant version spec.");
                    return(ExitCodes.InvalidVersionSpec);
                }
            }

            // run prepare-release
            try
            {
                var releaseManager = new ReleaseManager(Console.Out, Console.Error);
                releaseManager.PrepareRelease(searchPath, prereleaseTag, nextVersionParsed);
                return(ExitCodes.OK);
            }
            catch (ReleaseManager.ReleasePreparationException ex)
            {
                // map error codes
                switch (ex.Error)
                {
                case ReleaseManager.ReleasePreparationError.NoGitRepo:
                    return(ExitCodes.NoGitRepo);

                case ReleaseManager.ReleasePreparationError.UncommittedChanges:
                    return(ExitCodes.UncommittedChanges);

                case ReleaseManager.ReleasePreparationError.InvalidBranchNameSetting:
                    return(ExitCodes.InvalidBranchNameSetting);

                case ReleaseManager.ReleasePreparationError.NoVersionFile:
                    return(ExitCodes.NoVersionJsonFound);

                case ReleaseManager.ReleasePreparationError.VersionDecrement:
                    return(ExitCodes.InvalidVersionSpec);

                case ReleaseManager.ReleasePreparationError.BranchAlreadyExists:
                    return(ExitCodes.BranchAlreadyExists);

                case ReleaseManager.ReleasePreparationError.UserNotConfigured:
                    return(ExitCodes.UserNotConfigured);

                case ReleaseManager.ReleasePreparationError.DetachedHead:
                    return(ExitCodes.DetachedHead);

                default:
                    Report.Fail($"{nameof(ReleaseManager.ReleasePreparationError)}: {ex.Error}");
                    return((ExitCodes)(-1));
                }
            }
        }